
                            S r SSKJr  SSKJr  SSKrSSKrSSKJr  \R                  R                  S5      S:X  a  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  O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  \R"                  " S5      r\R"                  " S\R&                  5      r\R"                  " S\R&                  5      r\R"                  " S\R&                  5      rSrSrSrSrSr " S S\5      r " S S\5      r " S S\R>                  5      r  " S S\!5      r"S r#S r$ " S  S!\RJ                  5      r& " S" S#\RJ                  5      r'S%S$ jr(g)&ziDispatch configuration tools.

Library for parsing dispatch.yaml files and working with these in memory.
    )absolute_import)unicode_literalsN)
six_subsetAPPENGINE_RUNTIMEpython27)appinfo)
validation)yaml_builder)yaml_listener)yaml_objectz^([^/]+)(/.*)$z
# 0 or more . terminated hostname segments (may not start or end in -).
^([a-z0-9]([a-z0-9\-]*[a-z0-9])*\.)*
# followed by a host name segment.
([a-z0-9]([a-z0-9\-]*[a-z0-9])*)$z]
#4 1-3 digit numbers separated by .
^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$z
# Single star or
^([*]|
# Host prefix with no .,  Ex '*-a' or
[*][a-z0-9\-]*[a-z0-9]|
# Host prefix with ., Ex '*-a.b-c.d'
[*](\.|[a-z0-9\-]*[a-z0-9]\.)([a-z0-9]([a-z0-9\-]*[a-z0-9])*\.)*
([a-z0-9]([a-z0-9\-]*[a-z0-9])*))$
applicationdispatchurlmoduleservicec                       \ rS rSrSrSrg)ErrorT   z%Base class for errors in this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       0lib/googlecloudsdk/appengine/api/dispatchinfo.pyr   r   T   s    -r   r   c                       \ rS rSrSrSrg)#MalformedDispatchConfigurationErrorX   z-Configuration file for dispatch is malformed.r   Nr   r   r   r   r    r    X   s    5r   r    c                   "    \ rS rSrSrSS jrSrg)DispatchEntryURLValidator\   zValidater for URL patterns.Nc                    Uc  [         R                  " S5      e[        U[        R                  5      (       d"  [         R
                  " S[        U5      -  5      e[        U5      nUR                  (       a?  [        [        UR                  SUR                  -  5        [        UR                  5        U$ [        [        UR                  SUR                  -  5        U$ )zValidates an URL pattern.zurl must be specifiedzurl must be a string, not '%r'zinvalid host_pattern '%s')r	   MissingAttribute
isinstancer   string_typesValidationErrortype	ParsedURL
host_exact_ValidateMatch_URL_HOST_EXACT_PATTERN_REhost_ValidateNotIpV4Address_URL_HOST_SUFFIX_PATTERN_REhost_pattern)selfvalue
unused_key
url_holders       r   Validate"DispatchEntryURLValidator.Validate_   s    }''(?@@eZ4455&&'I'+E{(3 4 4 5!J/2Z__DF joo. L 0*2I2I2Z5L5LLN
 Lr   r   N)r   r   r   r   r   r7   r   r   r   r   r#   r#   \   s
    #r   r#   c                       \ rS rSrSrS rSrg)r+   w   a  Dispath Entry URL holder class.

Attributes:
  host_pattern: The host pattern component of the URL pattern.
  host_exact: True if the host pattern does not start with a *.
  host: host_pattern  with any leading * removed.
  path_pattern: The path pattern component of the URL pattern.
  path_exact: True if the path_pattern does not end with a *.
  path: path_pattern with any trailing * removed.
c                    [        [        USU-  5      nUR                  5       u  U l        U l        U R                  R                  S5      (       a  SU l        U R                  SS U l        OSU l        U R                  U l        U R                  R                  S5      (       a  SU l	        U R                  SS U l
        gSU l	        U R                  U l
        g)a	  Initializes this ParsedURL with an URL pattern value.

Args:
  url_pattern: An URL pattern that conforms to the regular expression
      '^([^/]+)(/.*)$'.

Raises:
  validation.ValidationError: When url_pattern does not match the required
      regular expression.
zinvalid url '%s'*F   NT)r-   _URL_SPLITTER_REgroupsr2   path_pattern
startswithr,   r/   endswith
path_exactpath)r3   url_patternsplit_matchers      r   __init__ParsedURL.__init__   s     ##3[#7+#EGM+8+?+?+A(Dt(##C((do##AB'dido##di!!#&&do##CR(dido##dir   )r/   r,   r2   rF   rE   rB   N)r   r   r   r   r   rI   r   r   r   r   r+   r+   w   s    	$r   r+   c                 b    U R                  U5      nU(       d  [        R                  " U5      eU$ )zValidate value matches regex.)matchr	   r)   )regexr4   messagematchers       r   r-   r-      s)    KK'	

$
$W
--	.r   c                     [         R                  U 5      nU(       a=  [        S UR                  5        5       5      S:X  a  [        R
                  " SU -  5      eU$ )z%Validate host is not an IPV4 address.c              3   H   #    U  H  n[        U5      S ::  d  M  Sv   M     g7f)   r>   N)int).0xs     r   	<genexpr>*_ValidateNotIpV4Address.<locals>.<genexpr>   s     B 01CFcMQQ 0s   "	"   z'Host may not match an ipv4 address '%s')_URL_IP_V4_ADDR_RErL   sumrA   r	   r)   )r/   rO   s     r   r0   r0      sQ    $$T*'B 0BBaG

$
$%P'+&, - -	.r   c            	           \ rS rSrSr\\" 5       \\R                  " \
\R                  5      \
\R                  " \\R                  5      0rSrg)DispatchEntry   zDA Dispatch entry describes a mapping from a URL pattern to a module.r   N)r   r   r   r   r   URLr#   SERVICEr	   	PreferredMODULEr   MODULE_ID_RE_STRING
Deprecated
ATTRIBUTESr   r   r   r   r\   r\      sE    L	$&z##FG,G,GHj##GW-H-HI*r   r\   c                       \ rS rSrSr\\R                  " \R                  5      \
\R                  " \R                  " \5      5      0rSrg)DispatchInfoExternal   z-Describes the format of a dispatch.yaml file.r   N)r   r   r   r   r   APPLICATIONr	   Optionalr   APPLICATION_RE_STRINGDISPATCHRepeatedr\   rd   r   r   r   r   rf   rf      s=    5:&&w'D'DE
##J$7$7$FG*r   rf   c                 T   [         R                  " [        5      n[        R                  " U5      n[
        R                  " U5      nUR                  U 5        UR                  5       nU(       d
  [        5       $ [        U5      S:  a  [        S5      eUS   nUR                  5         U$ )a^  Load a dispatch.yaml file or string and return a DispatchInfoExternal.

Args:
  dispatch_info: The contents of a dispatch.yaml file as a string, or an open
    file object.
  open_fn: Function for opening files. Unused here, needed to provide
    a polymorphic API used by appcfg.py yaml parsing.

Returns:
  A DispatchInfoExternal instance which represents the contents of the parsed
    yaml file.

Raises:
  MalformedDispatchConfigurationError: The yaml file contains multiple
    dispatch sections or is missing a required value.
  yaml_errors.EventError: An error occured while parsing the yaml file.
r>   z-Multiple dispatch: sections in configuration.r   )r   ObjectBuilderrf   r
   BuilderHandlerr   EventListenerParse
GetResultslenr    CheckInitialized)dispatch_infoopen_fnbuilderhandlerlistenerparsed_yamldispatch_info_externals          r   LoadSingleDispatchr|      s    $ %%&:;'''0'((1(
..""$+	!!
- /B C C
 'q>))+	r   r9   ))r   
__future__r   r   osre"googlecloudsdk.appengine._internalr   environgetgoogle.appengine.apir   r	   r
   r   r   googlecloudsdk.appengine.apicompiler@   VERBOSEr.   rY   r1   rh   rk   r^   ra   r_   	Exceptionr   r    	Validatorr#   objectr+   r-   r0   	Validatedr\   rf   r|   r   r   r   <module>r      sF  
 ' ' 
 	 9 ::>>%&*4*-/0.25786 ::/0   ZZ )% ')jj	2  ZZ !<=?ZZI  !jj * ZZ  	
.I .6% 6
 4 4 6&$ &$RJ(( :// " r   