
    
                         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d	l
mZ dd
lmZ ddZej                   dd       ZddZy)z;Utilities for operating on endpoints for different regions.    )absolute_import)division)unicode_literalsN)apis)	constants)log)
properties)parsec                     t        j                  |       \  }}}}}}|j                  d      r'|rdj                  ||      }ndj                  ||      }t        j                  ||||||f      S )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      sn    27..2J/&&$x|$!((8f~~ff-f			664I	JJ    c              #      K   t        | ||      }t        j                  j                  dj	                  |             t
        j                  j                  j                  j                  |       d yw)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&   )   s[      'wv5BD-**(//>?**5599-Hs   A5A7c                     t        j                  t        j                  t        j                  |          }t        |||      S )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__
__future__r   r   r   
contextlibgooglecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.air   googlecloudsdk.corer   r	   six.moves.urllibr
   r   contextmanagerr&   r    r   r   <module>r4      sK    B &  '  , 3 # * "K  *5r   