
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKrSrSr\r	\R                  S:  a  \R                  r	SS	 jr " S
 S\	R                  5      rg)zEWraps a Cloud Run Condition messages, making fields easier to access.    )absolute_import)division)unicode_literalsNErrorWarning)      c                 >   / nU R                  5        H  nU(       a  US:X  a  M  X   S   [        :X  a1  UR                  SR                  X0U   S   =(       d    S5      5        MR  X   S   (       d  M`  UR                  SR                  X0U   S   5      5        M     U$ )a  Get messages for non-terminal subconditions.

Only show a message for some non-terminal subconditions:
- if severity == warning
- if message is provided
Non-terminal subconditions that aren't warnings are effectively neutral,
so messages for these aren't included unless provided.

Args:
  conditions: Conditions
  ignore_retry: bool, if True, ignores the "Retry" condition

Returns:
  list(str) messages of non-terminal subconditions
Retryseverityz{}: {}messagezUnknown Warning.)NonTerminalSubconditions_SEVERITY_WARNINGappendformat)
conditionsignore_retrymessagescs       +lib/googlecloudsdk/api_lib/run/condition.pyGetNonTerminalMessagesr   !   s      (..0aW}Z $55oohoo
]9%;);= >	y	!	!oohooaAy)ABC 1 
/    c                   t    \ rS rSrSr  SS j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 rSrg)
Conditions=   a0  Represents the status Conditions of a resource in a dict-like way.

Resource means a Cloud Run resource, e.g: Configuration.

The conditions of a resource describe error, warning, and completion states of
the last set of operations on the resource. True is success, False is failure,
and "Unknown" is an operation in progress.

The special "ready condition" describes the overall success state of the
(last operation on) the resource.

Other conditions may be "terminal", in which case they are required to be True
for overall success of the operation, and being False indicates failure.

If a condition has a severity of "info" or "warning" in the API, it's not
terminal.

More info: https://github.com/knative/serving/blob/master/docs/spec/errors.md

Note, status field of conditions is converted to boolean type.
Nc                 l   0 U l         U H  nSnUR                  R                  5       S:X  a  SnO UR                  R                  5       S:X  a  SnUR                  UR                  UR
                  UR                  US.U R                   UR                  '   M     X l        USL =(       d    X4:H  U l	        g)aG  Constructor.

Args:
  conditions: A list of objects of condition_class.
  ready_condition: str, The one condition type that indicates it is ready.
  observed_generation: The observedGeneration field of the status object
  generation: The generation of the object. Incremented every time a user
    changes the object directly.
NtrueTfalseF)r   reasonr   lastTransitionTimestatus)
_conditionsr!   lowerr   r   r   r    type_ready_condition_fresh)selfr   ready_conditionobserved_generation
generationcondr!   s          r   __init__Conditions.__init__T   s     Df					&;;')mmKK\\ $ 7 7%dtyy!  ,&$. 7'5 	Kr   c                      U R                   U   $ )z%Implements evaluation of `self[key]`.r"   )r'   keys     r   __getitem__Conditions.__getitem__r   s    C  r   c                 B   ^ [        U4S jU R                   5       5      $ )z(Implements evaluation of `item in self`.c              3   ,   >#    U  H	  oT:H  v   M     g 7fN ).0	cond_typeitems     r   	<genexpr>*Conditions.__contains__.<locals>.<genexpr>x   s     C2BYD 2Bs   )anyr"   )r'   r9   s    `r   __contains__Conditions.__contains__v   s    C$2B2BCCCr   c                 ,    [        U R                  5      $ )z%Implements evaluation of `len(self)`.)lenr"   r'   s    r   __len__Conditions.__len__z   s    t  r   c              #   :   #    U R                    H  nUv   M	     g7f)z1Returns a generator yielding the condition types.Nr/   )r'   r8   s     r   __iter__Conditions.__iter__~   s     %%	o &s   c              #      #    U  H5  nXR                   :w  d  M  X   S   (       a  X   S   [        :X  d  M1  Uv   M7     g7f)zFYields keys of the conditions which if all True, Ready should be true.r   Nr%   _SEVERITY_ERRORr'   ks     r   TerminalSubconditions Conditions.TerminalSubconditions   s8     
$$
$wz"dgj&9_&L s   ??	?c              #      #    U  H7  nXR                   :w  d  M  X   S   (       d  M"  X   S   [        :w  d  M3  Uv   M9     g7f)zAYields keys of the conditions which do not directly affect Ready.r   NrH   rJ   s     r   r   #Conditions.NonTerminalSubconditions   s;     
$$
$)<)<
'*

0 s   A
AA	Ac                     U R                   $ r5   r%   rA   s    r   TerminalConditionConditions.TerminalCondition   s       r   c                     U R                   (       a7  U R                   U ;   a'  X R                      S   (       a  X R                      S   $ g)z-Returns the reason of the terminal condition.r   NrQ   rA   s    r   TerminalConditionReason"Conditions.TerminalConditionReason   sC     	!!T)&&'1''(22r   c                     U R                   (       a7  U R                   U ;   a'  X R                      S   (       a  X R                      S   $ g)zEDescriptive message about what's happened to the last user operation.r   NrQ   rA   s    r   DescriptiveMessageConditions.DescriptiveMessage   sA    %""#I.''(33r   c                     U R                   (       d
  [        5       eU R                  (       d  gU R                   U R                  ;  a  gU R                  U R                      S   SL$ )zTrue if the resource has finished the last operation, for good or ill.

conditions are considered terminal if and only if the ready condition is
either true or false.

Returns:
  A bool representing if terminal.
Fr!   N)r%   NotImplementedErrorr&   r"   rA   s    r   
IsTerminalConditions.IsTerminal   sX       !!;;D$4$44D1128<DHHr   c                 f    U R                  5       (       d  gU R                  U R                     S   $ )z@Return True if the resource has succeeded its current operation.Fr!   )r\   r"   r%   rA   s    r   IsReadyConditions.IsReady   s.    ??D1128<<r   c                 Z    U R                  5       =(       a    U R                  5       (       + $ )z>"Return True if the resource has failed its current operation.)r\   r_   rA   s    r   IsFailedConditions.IsFailed   s    ??3T\\^!33r   c                     U R                   $ r5   )r&   rA   s    r   IsFreshConditions.IsFresh   s    ;;r   )r"   r&   r%   )NNN)__name__
__module____qualname____firstlineno____doc__r,   r1   r=   rB   rE   rL   r   rR   rU   rX   r\   r_   rb   re   __static_attributes__r6   r   r   r   r   =   sW    . )-+/8<!D!
!I"=4r   r   )F)rk   
__future__r   r   r   collectionssysrI   r   collections_abcversion_infoabcr   Mappingr   r6   r   r   <module>rt      s\    L &  '  
  fOO/8E(( Er   