
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ d	Zd
ZdZdZddddZej"                  d        Zd Zd Zy)z%Utilities for handling location flag.    )absolute_import)division)unicode_literalsN)apis)
properties)parsecloudresourcemanagerv3z<https://staging-cloudresourcemanager.sandbox.googleapis.com/z5stagqual-cloudresourcemanager.sandbox.googleapis.com/nane2staginganane2stagingbnane2stagingc)z northamerica-northeast2-stagingaz northamerica-northeast2-stagingbz northamerica-northeast2-stagingcc           	   #   
  K   t        t        j                  j                  t              }|j                         }|xr t        |v xs	 t        |k(  }	 | rk| dk7  rf|rIt        j                  | |       } |j                  t        dt        z   | j                  dd                   n2|j                  t        |              n|r|j                  t               d |j                  |       y# |j                  |       w xY ww)a!  Context manager to override the current CRM endpoint.

  The new endpoint will temporarily be the one corresponding to the given
  location.

  Args:
    location: str, location of the CRM backend (e.g. a cloud region or zone).
      Can be None to indicate global.

  Yields:
    None.
  globalzhttps://- N)getattrr   VALUESapi_endpoint_overridesCRM_API_NAMEGetCRM_STAGING_REGIONAL_SUFFIXCRM_STAGING_GLOBAL_APILOCATION_MAPPINGgetSet_DeriveCrmRegionalEndpointreplace_GetEffectiveCrmEndpoint)locationendpoint_propertyold_endpointis_staging_envs       Alib/googlecloudsdk/command_lib/resource_manager/endpoint_utils.pyCrmEndpointOverridesr$   +   s      j//FF*,"&&(, P%@L%P &O(>,(N (H(	 $''(;&z4O'O'/'7'7R'@B	C 	6x@A	 23	,','s   ADBC- D-D  Dc                 V    t        j                  t        t              }t	        ||       S )zFReturns regional Tag Bindings Endpoint based on the regional location.)r   GetEffectiveApiEndpointr   CRM_API_VERSIONr   )r   endpoints     r#   r   r   R   s!    )),H(	#Hh	77    c                     t        j                  |       \  }}}}}}dj                  ||      }t        j                  ||||||f      S )Nz{}-{})r   urlparseformat
urlunparse)r(   r   schemenetlocpathparamsqueryfragments           r#   r   r   X   sK    27..2J/&&$x>>(F+&			664I	JJr)   )__doc__
__future__r   r   r   
contextlibgooglecloudsdk.api_lib.utilr   googlecloudsdk.corer   six.moves.urllibr   r   r'   r   r   r   contextmanagerr$   r   r    r)   r#   <module>r<      st    , &  '  , * "%B  <  )8(7(7  #( #(L8Kr)   