
    G                        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                  (       a  SSK	r	OS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  SrSrSrSr " S S\R.                  5      r " S S\5      r " S S\R6                  5      r " S S\R6                  5      rSS jrg)z_DOS configuration tools.

Library for parsing dos.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
^.{0,499}$	blacklistdescriptionsubnetc                   "    \ rS rSrSrSS jrSrg)SubnetValidator?   zFChecks that a subnet can be parsed and is a valid IPv4 or IPv6 subnet.Nc                    Uc  [         R                  " S5      e[        U[        R                  5      (       d"  [         R
                  " S[        U5      -  5      e[        (       a   [        R                  " U5        UR                  S5      n[        U5      S:X  a8  [        R                  " SUS   5      (       d  [         R
                  " SU-  5      eU$ ! [         a    [         R
                  " SU-  5      ef = f)	zValidates a subnet.zsubnet must be specifiedz!subnet must be a string, not '%r'z%%s is not a valid IPv4 or IPv6 subnet/   z^[0-9]+$   zSPrefix length of subnet %s must be an integer (quad-dotted masks are not supported))r	   MissingAttribute
isinstancer   string_typesValidationErrortypeipaddr	IPNetwork
ValueErrorsplitlenrematch)selfvalue
unused_keypartss       +lib/googlecloudsdk/appengine/api/dosinfo.pyValidateSubnetValidator.ValidateB   s    }''(BCCeZ4455&&'L'+E{(3 4 4 v= KKE
5zQrxx
E!H==&& (46;(< = = L  =((3e;= 	==s   'C $C; N)__name__
__module____qualname____firstlineno____doc__r(   __static_attributes__r*       r'   r   r   ?   s
    Nr2   r   c                       \ rS rSrSrSrg)MalformedDosConfiguration\   z,Configuration file for DOS API is malformed.r*   N)r,   r-   r.   r/   r0   r1   r*   r2   r'   r4   r4   \   s    4r2   r4   c                   N    \ rS rSrSr\\R                  " \5      \	\
" 5       0rSrg)BlacklistEntry`   z;A blacklist entry describes a blocked IP address or subnet.r*   N)r,   r-   r.   r/   r0   DESCRIPTIONr	   Optional_DESCRIPTION_REGEXSUBNETr   
ATTRIBUTESr1   r*   r2   r'   r7   r7   `   s%    C:&&'9:o*r2   r7   c                       \ rS rSrSr\R                  \R                  " \R                  5      \
\R                  " \R                  " \5      5      0rSrg)DosInfoExternalh   z(Describes the format of a dos.yaml file.r*   N)r,   r-   r.   r/   r0   r   APPLICATIONr	   r:   APPLICATION_RE_STRING	BLACKLISTRepeatedr7   r=   r1   r*   r2   r'   r?   r?   h   sC    0:..w/L/LM$$Z%8%8%HI*r2   r?   c                 0   [         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   $ )a  Load a dos.yaml file or string and return a DosInfoExternal object.

Args:
  dos_info: The contents of a dos.yaml file as a string, or an open file
    object.
  open_fn: Function for opening files. Unused.

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

Raises:
  MalformedDosConfiguration: The yaml file contains multiple blacklist
    sections.
  yaml_errors.EventError: An error occured while parsing the yaml file.
r   z.Multiple blacklist: sections in configuration.r   )r   ObjectBuilderr?   r
   BuilderHandlerr   EventListenerParse
GetResultsr    r4   )dos_infoopen_fnbuilderhandlerlistenerparsed_yamls         r'   LoadSingleDosrQ   p   s    " %%o6'''0'((1(
..""$+	
# %8 9 9	Qr2   r+   )r0   
__future__r   r   osr!   "googlecloudsdk.appengine._internalr   PY2r   environgetgoogle.appengine.apir   r	   r
   r   r   googlecloudsdk.appengine.apir;   rC   r9   r<   	Validatorr   	Exceptionr4   	Validatedr7   r?   rQ   r*   r2   r'   <module>r]      s    
 ' ' 
 	 9 >>& ::>>%&*4*-/0.25786 # 		j** :5	 5Z)) j** r2   