
    	                         S r SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS jr\R                  SS	 j5       rSS
 jrg)z;Utilities for operating on endpoints for different regions.    N)apis)	constants)log)
properties)parsec                     [         R                  " U 5      u  p4pVpxUR                  S5      (       a*  U(       a  SR                  X5      nOSR                  X5      n[         R                  " X4XVXx45      $ )z(Adds region as a prefix of the base url.
aiplatformz{}-prediction-{}z{}-{})r   urlparse
startswithformat
urlunparse)	endpointregionis_predictionschemenetlocpathparamsqueryfragments	            2lib/googlecloudsdk/command_lib/ai/endpoint_util.py DeriveAiplatformRegionalEndpointr      sa    27..2J/&$|$$!((8f~~f-f			64I	JJ    c              #      #    [        XUS9n[        R                  R                  SR	                  U5      5        [
        R                  R                  R                  R                  U5        Sv   g7f)a-  Context manager to override the AI Platform endpoints for a while.

Raises an error if
region is not set.

Args:
  version: str, implies the version that the endpoint will use.
  region: str, region of the AI Platform stack.
  is_prediction: bool, it's for prediction endpoint or not.

Yields:
  None
)versionr   r   zUsing endpoint [{}]N)
GetEffectiveEndpointr   statusPrintr   r   VALUESapi_endpoint_overridesr	   Set)r   r   r   used_endpoints       r   AiplatformEndpointOverridesr#   &   sX      'w5BD-**(//>?**5599-Hs   A1A3c                     [         R                  " [        R                  [        R                  U    5      n[        X1US9$ )zOReturns regional AI Platform endpoint, or raise an error if the region not set.)r   )r   GetEffectiveApiEndpointr   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSIONr   )r   r   r   r   s       r   r   r   <   s=    ))$$''02( 
*m
5 5r   )F)__doc__
contextlibgooglecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.air   googlecloudsdk.corer   r   six.moves.urllibr   r   contextmanagerr#   r    r   r   <module>r0      sD    B  , 3 # * "K  *5r   