
                            S r SSKJr  SSKJr  SrSSKrSSKrSSKrSSKrSr	SSK
Jr  \R                  (       a  SSKJr  SSKJr  OSr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rS\< S\< S3r " S S\R>                  5      r  " S S\R>                  5      r!Sr"Sr#Sr$Sr%S r&S!r'S"r(S#r)S$r*S%r+S&r,S'r- " S( S)\.5      r/ " S* S+\R`                  5      r1 " S, S-\R`                  5      r2 " S. S/\R`                  5      r3S1S0 jr4g)2zCronInfo tools.

A library for working with CronInfo records, describing cron entries for an
application. Supports loading the records from yaml.
    )absolute_import)unicode_literalszarb@google.com (Anthony Baxter)N)
six_subset)groc)groctimespecificationAPPENGINE_RUNTIMEpython27)appinfo)
validation)yaml_builder)yaml_listener)yaml_objectz^/.*$z
^.{0,100}$z
^.{0,499}$z(?!-)[a-z\d\-]{1,63}z(?!-)[a-z\d\-]{1,100}z^(?:(?:(z):)?)(z)$c                   "    \ rS rSrSrSS jrSrg)GrocValidatorP   z/Checks that a schedule is in valid groc format.Nc                    Uc  [         R                  " S5      e[        U[        R                  5      (       d  [        S[        U5      -  5      e[        (       a$  [        (       a   [        R                  " U5        U$ U$ ! [        R                   a0  n[         R                  " SU< SUR                  S   < 35      eSnAff = f)zValidates a schedule.Nzschedule must be specifiedz#schedule must be a string, not '%r'z
schedule 'z' failed to parse: r   )r   MissingAttribute
isinstancer   string_types	TypeErrortyper   r   GrocTimeSpecificationGrocExceptionValidationErrorargs)selfvaluekeyes       ,lib/googlecloudsdk/appengine/api/croninfo.pyValidateGrocValidator.ValidateS   s    }''(DEEeZ4455=d5kIJJ t%%33E: L5L  ((166!9*  	s   'B C+C  C N__name__
__module____qualname____firstlineno____doc__r!   __static_attributes__r#       r    r   r   P   s
    7r,   r   c                   "    \ rS rSrSrSS jrSrg)TimezoneValidatord   z<Checks that a timezone can be correctly parsed and is known.Nc           	         [        U[        R                  5      (       d  [        S[	        U5      -  5      e[
        c  U$  [
        R                  U5        U$ ! [
        R                   a    [        R                  " SU-  5      e[         a    Us $   [        R                  " 5       u  p4n[        R                  " SU-  S-   SR                  [         R"                  " U5      5      -   5        e = f)zValidates a timezone.z#timezone must be a string, not '%r'ztimezone '%s' is unknownz%pytz raised an unexpected error: %s.
zTraceback:

)r   r   r   r   r   pytztimezoneUnknownTimeZoneErrorr   r   IOErrorsysexc_infologgingwarningjoin	traceback	format_tb)r   r   r   unused_evts         r    r!   TimezoneValidator.Validateg   s    eZ4455=UKLL|l
mmE L $$ M&&'Ce'KLL  l ||~nh1oo>!D$%'+yy1D1DQ1G'HI Js   A 8C.AC.r#   r$   r%   r#   r,   r    r.   r.   d   s
    Dr,   r.   cronurlscheduler3   descriptiontargetretry_parametersjob_retry_limitjob_age_limitmin_backoff_secondsmax_backoff_secondsmax_doublingsc                       \ rS rSrSrSrg)MalformedCronfigurationFile   z)Configuration file for Cron is malformed.r#   N)r&   r'   r(   r)   r*   r+   r#   r,   r    rM   rM      s    1r,   rM   c                      \ rS rSrSr\\R                  " \R                  " S\	R                  \S95      \\R                  " \R                  " 5       5      \\R                  " \R                  " SS\S95      \\R                  " \R                  " SS\S95      \\R                  " \R                  " SS\S95      0rSrg)	RetryParameters   z'Retry parameters for a single cron job.r   )minimummaximum
range_typeg        N)rT   r#   )r&   r'   r(   r)   r*   JOB_RETRY_LIMITr   OptionalRanger6   maxsizeintJOB_AGE_LIMIT	TimeValueMIN_BACKOFF_SECONDSfloatMAX_BACKOFF_SECONDSMAX_DOUBLINGS
ATTRIBUTESr+   r#   r,   r    rP   rP      s    /z**


1#&;;&)+,
 Z(()=)=)?@:..


3
79:..


3
79Z((


1ds
35*r,   rP   c                       \ rS rSrSr\\\\" 5       \	\
R                  " \" 5       5      \\
R                  " \5      \\
R                  " \5      \\
R                  " \5      0rSrg)	CronEntry   z)A cron entry describes a single cron job.r#   N)r&   r'   r(   r)   r*   URL
_URL_REGEXSCHEDULEr   TIMEZONEr   rV   r.   DESCRIPTION_DESCRIPTION_REGEXRETRY_PARAMETERSrP   TARGET_VERSION_REGEXr`   r+   r#   r,   r    rb   rb      s]    1	:
##$5$78:&&'9:
++O<j!!.1*r,   rb   c                       \ rS rSrSr\R                  \R                  " \R                  5      \
\R                  " \R                  " \5      5      0rSrg)CronInfoExternal   z?CronInfoExternal describes all cron entries for an application.r#   N)r&   r'   r(   r)   r*   r
   APPLICATIONr   rV   APPLICATION_RE_STRINGCRONRepeatedrb   r`   r+   r#   r,   r    rn   rn      sC    G:..w/L/LM
J
 3 3I >?*r,   rn   c                 B   [         R                  " [        5      n[        R                  " U5      n[
        R                  " U5      nUR                  U 5        UR                  5       n[        U5      S:  a  [        S5      e[        U5      S:  a  [        S5      eUS   $ )zELoad a cron.yaml file or string and return a CronInfoExternal object.   zEmpty cron configuration.z(Multiple cron sections in configuration.r   )r   ObjectBuilderrn   r   BuilderHandlerr   EventListenerParse
GetResultslenrM   )	cron_infoopen_fnbuilderhandlerlistenercron_info_results         r    LoadSingleCronr      s    %%&67'''0'((1(
..'')	Q
%&A
BB	Q
% ': ; ;	!	r,   r$   )5r*   
__future__r   r   
__author__r8   osr6   r;   r2   "googlecloudsdk.appengine._internalr   PY2#googlecloudsdk.appengine.googlecronr   r   environgetgoogle.appengine.apir
   r   r   r   r   googlecloudsdk.appengine.apire   _TIMEZONE_REGEXri   SERVER_ID_RE_STRINGSERVER_VERSION_RE_STRINGrl   	Validatorr   r.   rr   rd   rf   rg   rh   rk   rj   rU   rZ   r\   r^   r_   	ExceptionrM   	ValidatedrP   rb   rn   r   r#   r,   r    <module>r      s\   ' '.
  	 
  : >>6G	$::>>%&*4*-/0.25786 
"  .  4  -@,DFJ(( (
,, 8 	% #+ + ) 
j** $	
$$ 	z++ r,   