
                             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  \R                  (       a  SS	KJr  SS
KJr  OSrSrSrS rS rS r " S S\5      r " S S\5      r " S S\5      rg)zDirectly processes text of cron.xml.

CronXmlParser is called with an XML string to produce a CronXml object
containing the data from the XML.

CronXmlParser: converts XML to CronXml objct
Cron: describes a single cron specified in cron.xml
    )absolute_import)division)unicode_literals)ElementTree)xml_parser_utils)AppEngineConfigException)
six_subset)groc)groctimespecificationN)zjob-retry-limitzjob-age-limitzmin-backoff-secondszmax-backoff-secondszmax-doublingsc                 F    [        [        5       R                  U5      5      $ )N)_MakeCronListIntoYamlCronXmlParser
ProcessXml)unused_applicationcron_xml_strs     5lib/googlecloudsdk/appengine/tools/cron_xml_parser.pyGetCronYamlr   5   s    	}99,G	HH    c                 f    S/nU  H  nXR                  5       -  nM     SR                  U5      S-   $ )zDConverts list of yaml statements describing cron jobs into a string.zcron:
)ToYamljoin)	cron_list
statementscrons      r   r   r   9   s5    y*d++-J 	:		%%r   c           	         [         R                  " U S5      nUc  SUl        g[        5       nX1l        [         HM  n[         R                  " X$5      c  M  [        UUR                  SS5      [         R                  " X$5      5        MO     g)z=Converts <retry-parameters> in node to cron.retry_parameters.zretry-parametersN-_)r   GetChildretry_parameters_RetryParameters_RETRY_PARAMETER_TAGSsetattrreplaceGetChildNodeText)noder   retry_parameters_noder    tags        r   _ProcessRetryParametersNoder)   A   s}     +33D:LM" D
%'*"c  !6<H

++c3


+
+,A
GI #r   c                   *    \ rS rSrSrS rS rS rSrg)r   S   z:Provides logic for walking down XML tree and pulling data.c                     / U l         / U l        [        R                  " U5      nUR                  S:w  a  [        S5      e[        U5       H  nU R                  U5        M     U R                  (       a$  [        SR                  U R                  5      5      eU R                   $ ! [        R                   a    [        S5      ef = f)a  Parses XML string and returns object representation of relevant info.

Args:
  xml_str: The XML string.
Returns:
  A list of Cron objects containing information about cron jobs from the
  XML.
Raises:
  AppEngineConfigException: In case of malformed XML or illegal inputs.
cronentrieszRoot tag must be <cronentries>r   zBad input -- not valid XML)
cronserrorsr   
fromstringr(   r   listProcessCronNoder   
ParseError)selfxml_strxml_rootchilds       r   r   CronXmlParser.ProcessXmlV   s    Cdjdk''0h		&&'GHH>%U# " 
&tyy'=>>ZZ!! C$%ABBCs   B"B% % Cc                 Z   [         R                  " U5      nUS:w  a  U R                  R                  SU-  5        g[	        5       n[         R
                  " US5      Ul        [         R
                  " US5      Ul        [         R
                  " US5      Ul        [         R
                  " US5      Ul	        [         R
                  " US5      Ul
        [        X5        U R                  U5      nU(       a  U R                  R                  U5        gU R                  R                  U5        g)	a  Processes XML <cron> nodes into Cron objects.

The following information is parsed out:
  description: Describing the purpose of the cron job.
  url: The location of the script.
  schedule: Written in groc; the schedule according to which the job is
    executed.
  timezone: The timezone that the schedule runs in.
  target: Which version of the app this applies to.

Args:
  node: <cron> XML node in cron.xml.
r   zUnrecognized node: <%s>Nurltimezonetargetdescriptionschedule)r   GetTagr/   appendCronr%   r:   r;   r<   r=   r>   r)   _ValidateCronEntryr.   )r4   r&   r(   r   validation_errors        r   r2   CronXmlParser.ProcessCronNodes   s     
!
!$
'C
f}
kk2S896D00u=DH$55dJGDM"33D(CDK'88}MD$55dJGDM+..t4
kk)*
jjr   c                 L   UR                   (       d  gUR                  (       d  SUR                   -  $ [        (       a.  [        (       a"   [        R                  " UR                  5        g g g ! [        R
                   a"    SUR                  < SUR                   < S3s $ f = f)NzNo URL for <cron> entryz3No schedule provided for <cron> entry with URL '%s'zText 'z@' in <schedule> node failed to parse, for <cron> entry with url .)r:   r>   r
   r   GrocTimeSpecificationGrocException)r4   r   s     r   rB    CronXmlParser._ValidateCronEntry   s     88&==BTXXMM t%%-33DMMB &t  - ==$((, 	--s   
 A- -3B#"B#)r.   r/   N)	__name__
__module____qualname____firstlineno____doc__r   r2   rB   __static_attributes__ r   r   r   r   S   s    BC:B-r   r   c                       \ rS rSrSrS rSrg)r!      zCObject that contains retry xml tags converted to object attributes.c                     / nS [          5       nU H1  n[        XS5      nU(       d  M  UR                  SU< SU< 35        M3     U(       d  S/$ S/U-   $ )z9Converts retry parameter fields to a YAML statement list.c              3   D   #    U  H  oR                  S S5      v   M     g7f)r   r   Nr$   ).0r(   s     r   	<genexpr>9_RetryParameters.GetYamlStatementsList.<locals>.<genexpr>   s     J4IS;;sC((4Is    Nz    : z  retry_parameters: {}z  retry_parameters:)r"   getattrr@   )r4   tag_statementsfield_namesfieldfield_values        r   GetYamlStatementsList&_RetryParameters.GetYamlStatementsList   s^     NJ4IJKD.k	e[AB 
 &''!"^33r   rP   N)rJ   rK   rL   rM   rN   r_   rO   rP   r   r   r!   r!      s
    K4r   r!   c                   (    \ rS rSrSrSrS rS rSrg)rA      z<Instances contain information about individual cron entries.UTCc           	      T   SU R                  U R                  5      -  SU R                  U R                  5      -  /nS H?  n[        X5      nU(       d  M  UR	                  SU< SU R                  U5      < 35        MA     [        U SS5      nU(       a  XR                  5       -  nU$ )z;Returns data from Cron object as a list of Yaml statements.z	- url: %sz  schedule: %s)r<   r;   r=   z  rY   r    N)_SanitizeForYamlr:   r>   rZ   r@   r_   )r4   r   optionalr]   r    s        r   r   Cron.ToYaml   s     	d++DHH55400??AJ :d%e	$2G2G2NOP : t%7>::<<jr   c                 L    SUR                  SS5      R                  SS5      -  $ )Nz'%s'r    'z''rU   )r4   r]   s     r   re   Cron._SanitizeForYaml   s%    EMM$,44S$???r   rP   N)	rJ   rK   rL   rM   rN   TZ_GMTr   re   rO   rP   r   r   rA   rA      s    D&@r   rA   )rN   
__future__r   r   r   	xml.etreer   googlecloudsdk.appengine.toolsr   :googlecloudsdk.appengine.tools.app_engine_config_exceptionr   "googlecloudsdk.appengine._internalr	   PY2#googlecloudsdk.appengine.googlecronr
   r   r"   r   r   r)   objectr   r!   rA   rP   r   r   <module>ru      s    '  ' ! ; _ : >>6G	$* I&I$P-F P-f4v 4$@6 @r   