
                             S 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K	J
r
  SSK	Jr  SS	KJr  S
 rS r\R                   4S jr\R                   4S jrS rS r\4S jrg)z#Utilities for handling region flag.    )absolute_import)division)unicode_literals)
exceptions)	constants)log)
properties)
console_ioc                      [         R                  R                  R                  R	                  5       [         R                  R                  R                  R
                  :H  $ N)r	   VALUEScoreuniverse_domainGetdefault     0lib/googlecloudsdk/command_lib/ai/region_util.py_IsDefaultUniverser      sE    ,,002						/	/	7	78r   c                      [         R                  n U (       d  g[        U 5      S:X  a  U S   $ [        R                  " 5       (       a%  [        U 5      n[        R                  " USSS9nX   $ g)z3Handles region selection for non-default universes.N   r   Please specify a region:
Tmessagecancel_option)r   NON_DEFAULT_UNIVERSE_REGIONSlenr
   	CanPromptlistPromptChoice)non_default_universe_regionsall_regionsidxs      r   _HandleNonDefaultUniverseRegionr$   #   sp    !*!G!G	%	%&!+'** 34K

!
!9OC 
r   c                    ^  U 4S j$ )z]Returns a no argument function that prompts available regions and catches the user selection.c                     > [        T 5      $ r   )PromptForRegionavailable_regionss   r   <lambda>(GetPromptForRegionFunc.<locals>.<lambda>:   s    !23r   r   r(   s   `r   GetPromptForRegionFuncr,   8   s	    	33r   c                    [        5       (       d
  [        5       $ [        R                  " 5       (       aU  [	        U 5      n[        R
                  " USSS9nX   n[        R                  R                  SR                  U5      5        U$ g)a<  Prompt for region from list of available regions.

This method is referenced by the declaritive iam commands as a fallthrough
for getting the region.

Args:
  available_regions: list of the available regions to choose from

Returns:
  The region specified by the user, str, or None if not in GDU or cannot
  prompt.
r   Tr   GTo make this the default region, run `gcloud config set ai/region {}`.
N)
r   r$   r
   r   r   r    r   statusPrintformat)r)   r"   r#   regions       r   r'   r'   =   s|     
		*,,()K

!
!9OCFJJ ;;A6&>KM r   c                  0   [        5       (       d
  [        5       $ [        R                  " 5       (       ac  [	        [
        R                  5      n [        R                  " U SSS9nX   n[        R                  R                  SR                  U5      5        U$ g)a  Prompt for region from list of online prediction available regions.

This method is referenced by the declaritive iam commands as a fallthrough
for getting the region.

Returns:
  The region specified by the user, str, or None if not in GDU or cannot
  prompt.
r   Tr   r.   N)r   r$   r
   r   r   r   SUPPORTED_OP_REGIONSr    r   r/   r0   r1   r"   r#   r2   s      r   PromptForOpRegionr6   W   s     
		*,,y556K

!
!9OCFJJ ;;A6&>KM r   c                  0   [        5       (       d
  [        5       $ [        R                  " 5       (       ac  [	        [
        R                  5      n [        R                  " U SSS9nX   n[        R                  R                  SR                  U5      5        U$ g)a  Prompt for region from list of deployment resource pool available regions.

This method is referenced by the declaritive iam commands as a fallthrough
for getting the region.

Returns:
  The region specified by the user, str, or None if not in GDU or cannot
  prompt.
r   Tr   r.   N)r   r$   r
   r   r   r   *SUPPORTED_DEPLOYMENT_RESOURCE_POOL_REGIONSr    r   r/   r0   r1   r5   s      r   .PromptForDeploymentResourcePoolSupportedRegionr9   n   s     
		*,,yKKLK

!
!9OCFJJ ;;A6&>KM r   c                 ^   [        U SS5      (       a  U R                  $ [        R                  R                  R                  R                  5       (       a2  [        R                  R                  R                  R                  5       $ U" 5       nU(       a  U$ [        R                  " SS5      e)aX  Gets the region and prompt for region if not provided.

  Region is decided in the following order:
- region argument;
- ai/region gcloud config;
- prompt user input (only in GDU).

Args:
  args: Namespace, The args namespace.
  prompt_func: Function, To prompt for region from list of available regions.

Returns:
  A str representing region.
r2   Nz--regionzRegion is required)	getattrr2   r	   r   aiIsExplicitlySetr   r   RequiredArgumentException)argsprompt_funcr2   s      r   	GetRegionrA      s     T8T"";;  0022&&**,,=&M 	,,Z9MNNr   N)__doc__
__future__r   r   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   googlecloudsdk.corer   r	   googlecloudsdk.core.consoler
   r   r$   SUPPORTED_REGIONr,   r'   r6   r9   rA   r   r   r   <module>rI      sa    * &  ' . 3 # * 2* .7-G-G 4
 '0&@&@ 4.. !0 Or   