
    d                        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SK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rS:S jrS rS;S jrS rS rS r " S S\5      r\R4                  " \R6                  5       " S S\5      5       r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r! " S  S!\5      r" " S" S#\5      r#\R4                  " \R6                  5       " S$ S%\5      5       r$ " S& S'\$5      r% " S( S)\$5      r& " S* S+\$5      r' " S, S-\'5      r( " S. S/\'5      r) " S0 S1\)5      r* " S2 S3\$5      r+ " S4 S5\$5      r, " S6 S7\$5      r- " S8 S9\$5      r.g)<z8Cloud resource list filter expression evaluator backend.    )absolute_import)division)unicode_literalsN)log)resource_exceptions)resource_lex)resource_property)encoding)timesc                      [         R                  " X5      $ ! [         R                   a*  n[        R                  " SR                  X5      5      eSnAff = f)zReturns a compiled RE pattern.

Args:
  pattern: The RE pattern string.
  flags: Optional RE flags.

Raises:
  ExpressionSyntaxError: RE pattern error.

Returns:
  The compiled RE.
z%Filter expression RE pattern [{}]: {}N)recompileerrorr   ExpressionSyntaxErrorformat)patternflagses      1lib/googlecloudsdk/core/resource/resource_expr.py
_ReCompiler   $   sP    D::g%%	 D

3
3/66wBD DDs    A%AAc                     U c  g[        U [        R                  5      (       d  [        U 5      n [        R                  " [
        R                  " U 5      5      $ )z4Returns the unicode string representation for value.null)
isinstancesixstring_typesrepr	text_typer
   Decodevalues    r   
_Stringizer!   8   s>    
]	E3++	,	,KE	xu-	..    c                 $   [        U 5      R                  5       nU(       a  [        R                  " SSU5      nSR	                  [
        R                  " SU5       Vs/ s H"  n[
        R                  " U5      (       a  M   UPM$     sn5      $ s  snf )a  Returns lowercase unicode NFKD form with accents stripped.

Args:
  value: The value to be normalized.
  html: If True the value is HTML text and HTML tags are converted to spaces.

Returns:
  The normalized unicode representation of value suitable for cloud search
  matching.
z<[^>]*> NFKD)r!   lowerr   subjoinunicodedata	normalize	combining)r    htmltextcs       r   NormalizeForSearchr/   A   sw     
E		 	 	"$	66)R&D	[2264@ 3@$..q1 @ 3 
4 4 3s   B Bc                     [        U [        5      (       d  [        U [        5      (       a  U $  [        U 5      $ ! [         a    [        U 5      s $ f = f)z-Returns value converted to int or float type.)r   intfloat
ValueErrorr   s    r   _NumericTyper4   V   sJ     sz%77Lu:	 <s   
9 AAc           
         Uu  pgn[        U[        [        45      (       aj   U[        U5      :X  a  g US:X  a  UR                  5       S:X  a  gUS:X  a  UR                  5       S:X  a  g[        R                  " SS[        U5      5      n	OXF:X  a  gUc  US	;   a  gUS
:X  a  US:X  a  gSn	OU(       ar  [        U[        R                  R                  5      (       aI   UR                  (       a  [        R                  OSn
U[        R                  " XjS9:X  a  g [!        USS9n	O
[!        USS9n	[#        UR%                  U	5      5      nU(       d  U$ [#        UR%                  U	5      5      n['        U5      S:X  a8  US   S;   a/  U[#        UR%                  U	R)                  S5      S   5      5      -  nX:w  au  U(       an  [+        XS5      (       d]  [-        XS5        U(       a  SOSnU(       a  SOSn[.        R0                  " SR3                  [4        R6                  " U5      UUUUS95        U$ ! [         a     GNf = f! [        [        R                  [        R                  4 a     GNRf = f)a  Returns True if value word matches pattern.

Args:
  backend: The parser backend object.
  key: The parsed expression key.
  op: The expression operator string.
  warned_attribute: Deprecation warning Boolean attribute name.
  value: The value to be matched by pattern.
  pattern: An (operand, standard_regex, deprecated_regex) tuple.

Raises:
  ValueError: To catch codebase reliance on deprecated usage.

Returns:
  True if pattern matches value.

Examples:
  See surface/topic/filters.py for a table of example matches.
Tr   false   truez\.0*$r$   N)r$   N*:Fr   tzinfo)r,   )zoneregion/matcheszdoes not matchz
will matchzwill not matchz--filter : operator evaluation is changing for consistency across Google APIs.  {key}{op}{operand} currently {old_match} but {new_match} in the near future.  Run `gcloud topic filters` for details.)keyopoperand	old_match	new_match)r   r1   r2   r4   r3   r&   r   r'   r!   r   datetimer<   LOCALParseDateTimeDateTimeSyntaxErrorDateTimeValueErrorr/   boolsearchlensplitgetattrsetattrr   warningr   r   
GetKeyName)backendrB   rC   warned_attributer    r   rD   standard_regexdeprecated_regexr-   r<   matcheddeprecated_matchedrE   rF   s                  r   _MatchOneWordInTextrZ   a   s>   ( /6+'+U|$$	,w'	' 
( zgmmo0zgmmo/66(B
5 12D}*#~")D:eU^^%<%<==#llu{{f	%%%g=	= 
> e$/De$/D &&t,-'	N,33D9: 	X]s1v!33$/66tzz#r7JKLL#(8
'U
3
3Gt,/	5EI '-=IKK 6 7=f$//4#'' 7= 7)* 
u  
* 1153K3KL 
s#   H. ;H? .
H<;H<?)I,+I,c           
         [        U[        5      (       aV  Sn/ nU(       aJ  UR                  [        R                  " U5      5        UR                  [        R
                  " U5      5        O![        U[        [        45      (       a  UnOU/n[        U[        [        45      (       a  UnOU1nU H!  nU H  n	[        XX#X5      (       d  M      g   M#     g)a  Applies _MatchOneWordInText to determine if value matches pattern.

Both value and operand can be lists.

Args:
  backend: The parser backend object.
  key: The parsed expression key.
  op: The expression operator string.
  warned_attribute: Deprecation warning Boolean attribute name.
  value: The key value or list of values.
  pattern: Pattern value or list of values.

Returns:
  True if the value (or any element in value if it is a list) matches pattern
  (or any element in operand if it is a list).
NTF)	r   dictextendr   iterkeys
itervalueslisttuplerZ   )
rT   rB   rC   rU   r    r   valuespatternsvps
             r   
_WordMatchrf      s    " t FmmCLL'(mmCNN5)*%$''FWF$''HyHa	W2	F	F   
r"   c                       \ rS rSrSrS rS rS rS rS r	S r
SS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrS rSrg	)Backend   a   Cloud resource list filter expression evaluator backend.

This is a backend for resource_filter.Parser(). The generated "evaluator" is a
parsed resource expression tree with branching factor 2 for binary operator
nodes, 1 for NOT and function nodes, and 0 for TRUE nodes. Evaluation for a
resource object starts with expression_tree_root.Evaluate(obj) which
recursively evaluates child nodes. The logic operators use left-right shortcut
pruning, so an evaluation may not visit every node in the expression tree.
c                     [        U 5      $ N)	_ExprTRUEselfs    r   ExprTRUEBackend.ExprTRUE   s    T?r"   c                     [        XU5      $ rk   )_ExprANDrn   leftrights      r   ExprANDBackend.ExprAND   s    D&&r"   c                     [        XU5      $ rk   )_ExprORrs   s      r   ExprORBackend.ExprOR   s    4u%%r"   c                     [        X5      $ rk   )_ExprNOT)rn   exprs     r   ExprNOTBackend.ExprNOT   s    Dr"   c                     [        X5      $ rk   )_ExprGlobal)rn   calls     r   
ExprGlobalBackend.ExprGlobal   s    t""r"   c                     [        X5      $ rk   )_ExprOperand)rn   r    s     r   ExprOperandBackend.ExprOperand   s    $$r"   Nc                     [        XX#5      $ rk   )_ExprLTrn   rB   rD   	transforms       r   ExprLTBackend.ExprLT       4g11r"   c                     [        XX#5      $ rk   )_ExprLEr   s       r   ExprLEBackend.ExprLE  r   r"   c                     [        XX#5      $ )a  Case insensitive membership node.

This is the pre-compile Expr for the ':' operator. It compiles into an
_ExprHAS node for prefix*suffix matching.

The * operator splits the operand into prefix and suffix matching strings.

Args:
  key: Resource object key (list of str, int and/or None values).
  operand: The term ExprOperand operand.
  transform: Optional key value transform calls.

Returns:
  _ExprHAS.
)_ExprHASr   s       r   ExprHASBackend.ExprHAS  s      Dw22r"   c                     [        XX#5      $ )zCase sensitive EQ node.

Args:
  key: Resource object key (list of str, int and/or None values).
  operand: The term ExprOperand operand.
  transform: Optional key value transform calls.

Returns:
  _ExprEQ.
)_ExprEQr   s       r   ExprEQBackend.ExprEQ  s     4g11r"   c                     [        XX#5      $ rk   )_ExprNEr   s       r   ExprNEBackend.ExprNE$  r   r"   c                     [        XX#5      $ rk   )_ExprGEr   s       r   ExprGEBackend.ExprGE'  r   r"   c                     [        XX#5      $ rk   )_ExprGTr   s       r   ExprGTBackend.ExprGT*  r   r"   c                     [        XX#5      $ rk   )_ExprREr   s       r   ExprREBackend.ExprRE-  r   r"   c                     [        XX#5      $ rk   )
_ExprNotREr   s       r   	ExprNotREBackend.ExprNotRE0  s    d44r"   c                     gNF rm   s    r   
IsRewriterBackend.IsRewriter3  s    r"   r   rk   )__name__
__module____qualname____firstlineno____doc__ro   rv   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r"   r   rh   rh      sW    '& #%223$222225r"   rh   c                   R    \ rS rSrSrS r\R                  S 5       r\	S 5       r
Srg)_Expri:  zExpression base class.c                     Xl         g rk   rT   )rn   rT   s     r   __init___Expr.__init__>  s    Lr"   c                     g)zReturns the value of the subexpression applied to obj.

Args:
  obj: The current resource object.

Returns:
  True if the subexpression matches obj, False if it doesn't match, or
  None if the subexpression is not supported.
Nr   rn   objs     r   Evaluate_Expr.EvaluateA       	r"   c                     gr   r   rm   s    r   contains_key_Expr.contains_keyN  s    r"   r   N)r   r   r   r   r   r   abcabstractmethodr   propertyr   r   r   r"   r   r   r   :  s8     
	 
	  r"   r   c                       \ rS rSrSrS rSrg)rl   iS  z#TRUE node.

Always evaluates True.
c                     gNTr   )rn   
unused_objs     r   r   _ExprTRUE.EvaluateY  s    r"   r   Nr   r   r   r   r   r   r   r   r"   r   rl   rl   S  s    
r"   rl   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )_ExprLogicali]  zaBase logical operator node.

Attributes:
  left: Left Expr operand.
  right: Right Expr operand.
c                 D   > [         [        U ]  U5        X l        X0l        g rk   )superr   r   _left_right)rn   rT   rt   ru   	__class__s       r   r   _ExprLogical.__init__e  s    	,&w/JKr"   )r   r   )r   r   r   r   r   r   r   __classcell__r   s   @r   r   r   ]  s     r"   r   c                       \ rS rSrSrS rSrg)rr   ik  z4AND node.

AND with left-to-right shortcut pruning.
c                     U R                   R                  U5      (       d  gU R                  R                  U5      (       d  gg)NFTr   r   r   r   s     r   r   _ExprAND.Evaluateq  s5    ::s##;;$$r"   r   Nr   r   r"   r   rr   rr   k  s    
r"   rr   c                       \ rS rSrSrS rSrg)ry   iy  z2OR node.

OR with left-to-right shortcut pruning.
c                     U R                   R                  U5      (       a  gU R                  R                  U5      (       a  gg)NTFr   r   s     r   r   _ExprOR.Evaluate  s5    zz3{{C  r"   r   Nr   r   r"   r   ry   ry   y  s    
r"   ry   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r}   i  z	NOT node.c                 8   > [         [        U ]  U5        X l        g rk   )r   r}   r   _expr)rn   rT   r~   r   s      r   r   _ExprNOT.__init__  s    	(D"7+Jr"   c                 B    U R                   R                  U5      (       + $ rk   )r   r   r   s     r   r   _ExprNOT.Evaluate  s    zz""3'''r"   )r   	r   r   r   r   r   r   r   r   r   r   s   @r   r}   r}     s    ( (r"   r}   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r   i  zWGlobal restriction function call node.

Attributes:
  _call: The function call object.
c                 8   > [         [        U ]  U5        X l        g rk   )r   r   r   _call)rn   rT   r   r   s      r   r   _ExprGlobal.__init__  s    	+t%g.Jr"   c                 8    U R                   R                  U5      $ rk   )r   r   r   s     r   r   _ExprGlobal.Evaluate  s    ::s##r"   )r   r   r   s   @r   r   r     s    $ $r"   r   c                   6    \ rS rSrSrSSS.rS
S jrS
S jrS	rg)r   i  a  Operand node.

Converts an expession value token string to internal string and/or numeric
values. If an operand has a numeric value then the actual key values are
converted to numbers at Evaluate() time if possible for Apply(); if the
conversion fails then the key and operand string values are passed to Apply().

Attributes:
  list_value: A list of operands.
  numeric_value: The int or float number, or None if the token string does not
    convert to a number.
  string_value: The token string.
r   r7   )r6   r8   Nc                 f    Xl         S U l        SU l        S U l        S U l        U R                  X#S9  g )NFr*   )rT   
list_valuenumeric_constantnumeric_valuestring_value
Initialize)rn   rT   r    r*   s       r   r   _ExprOperand.__init__  s4    LDO!DDDOOEO/r"   c           	         [        U[        5      (       a>  / U l        U H0  nU R                  R                  [	        U R
                  X2S95        M2     gU(       a  U(       a  U" U5      U l        g[        U[        R                  5      (       a1  Xl         U R                  UR                  5          U l        SU l        g[!        U5      U l        Xl        g! [         a%     [        U5      U l         g! [         a      gf = ff = f)zInitializes an operand string_value and numeric_value from value.

Args:
  value: The operand expression string value.
  normalize: Optional normalization function.
r   TN)r   r`   r   appendr   rT   r   r   r   _NUMERIC_CONSTANTSr&   r   r   KeyErrorr4   r3   r!   )rn   r    r*   vals       r   r   _ExprOperand.Initialize  s     %do#s@	B  
9#E*d	E3++	,	,!44U[[]C $ %U+d   	+E2$
 	
	s*   )C 
D"C44
D>DDD)rT   r   r   r   r   rk   )	r   r   r   r   r   r   r   r   r   r   r"   r   r   r     s!     
0!r"   r   c                   (  ^  \ rS rSrSr\R                  R                  \R                  R                  \R                  R                  \R                  R                  4rU 4S jrS r\S 5       r\S 5       rS r\R&                  S 5       rS	rU =r$ )
_ExprOperatori  a  Base term (<key operator operand>) node.

ExprOperator subclasses must define the function Apply(self, value, operand)
that returns the result of <value> <op> <operand>.

Attributes:
  _key: Resource object key (list of str, int and/or None values).
  _normalize: The resource value normalization function.
  _operand: The term ExprOperand operand.
  _transform: Optional key value transform calls.
  key : Property decorator for the resource object key.
c                    > [         [        U ]  U5        X l        X0l        X@l        U(       a	  S U l        g U R                  U l        g )Nc                     U $ rk   r   xs    r   <lambda>(_ExprOperator.__init__.<locals>.<lambda>  s    !r"   )r   r  r   _key_operand
_transform
_normalizeInitializeNormalizationrn   rT   rB   rD   r   r   s        r   r   _ExprOperator.__init__  s8    	-'0IMO#do44dor"   c                   ^ S U l         [        R                  " SU5      (       a   [        R                  " U5      nUR
                  (       a  [        R                  OSmU R                  R                  U R                  R                  =(       d    U R                  R                  U4S jS9  [        R                  U l         U$ U$ ! [         a     U$ f = f)a  Checks the first non-empty resource value to see if it can be normalized.

This method is called at most once on the first non-empty resource value.
After that a new normalization method is set for the remainder of the
resource values.

Resource values are most likely well defined protobuf string encodings. The
RE patterns match against those.

Args:
  value: A resource value to normalize.

Returns:
  The normalized value.
c                     U $ rk   r   r  s    r   r  7_ExprOperator.InitializeNormalization.<locals>.<lambda>
  s    r"   z$\d\d\d\d-\d\d-\d\d[ T]\d\d:\d\d:\d\dNc                 .   > [         R                  " U TS9$ )Nr;   )r   rI   )r  r<   s    r   r  r    s     3 3Af Er"   r   )r  r   matchr   rI   r<   rH   r
  r   r   r   r3   )rn   r    r<   s     @r   r  %_ExprOperator.InitializeNormalization  s      "DO 
xx7??
##E* !&$  MM$$B(B(BE 	! 	G  -- L5L   Ls   BC 
CCc                     gr   r   rm   s    r   r   _ExprOperator.contains_key  s    r"   c                     U R                   $ rk   )r	  rm   s    r   rB   _ExprOperator.key#  s    99r"   c           	         [         R                  " XR                  5      nU R                  (       a  U R                  R	                  U5      nU(       a  [        U[        [        45      (       a  UnOU/n/ nU H-  nU(       a   U R                  U5      nUR                  U5        M/     U R                  R                  (       a  U R                  R                  nOU R                  /nU H  nU H  nUR                  bB   U R                  [!        U5      UR                  5      (       a      gUR"                  (       d  MQ   U(       d'  [        UR$                  U R&                  5      (       a  M   U R                  X&R$                  5      (       a      gM     M     g! [        [        4 a     GNf = f! [        [        4 a     Nf = f! [(        [        4 a     M  [         a    UbX  [        U[*        R,                  [.        [        45      (       d.  U R                  [1        U5      UR$                  5      (       a       g[*        R2                  (       a0  Uc)  U R                  SUR$                  5      (       a       g GM   GM   GM  f = f)zEvaluate a term node.

Args:
  obj: The resource object to evaluate.
Returns:
  The value of the operator applied to the key value and operand.
Tr$   F)r	   Getr	  r  r   r   r`   ra   r  	TypeErrorr3   r   r
  r   r   Applyr4   r   r   _TIME_TYPESAttributeErrorr   r   r\   r!   PY3)rn   r   r    resource_valuesrb   operandsrD   s          r   r   _ExprOperator.Evaluate'  s    !!#yy1Eoo&&u-eED%=11ooF 		//%(% mmE ! }}))h--h '   ,zz,u-w/D/DEE++ ,
 G$8$8$:J:JKK
	ZZ3344 5#  H ] :& 	
	* Z(  
+ 	
 	 )9)94(FGG**Z.0D0DEEgg-**R!5!566 7   	sI   F*F4.F41 G
F10F14GG
JA J9J
Jc                     g)zReturns the value of applying a <value> <operator> <operand> term.

Args:
  value: The term key value.
  operand: The term operand value.

Returns:
  The Boolean value of applying a <value> <operator> <operand> term.
Nr   rn   r    rD   s      r   r  _ExprOperator.Applyl  r   r"   )r	  r  r
  r  )r   r   r   r   r   r   rG   datetime	timedeltar<   r  r   r  r   r   rB   r   r   r   r  r   r   r   s   @r   r  r    s     nnnnnnnn	+5#J    CJ 
	 
	r"   r  c                       \ rS rSrSrS rSrg)r   iz  zLT node.c                 
    X:  $ rk   r   r%  s      r   r  _ExprLT.Apply}  
    ?r"   r   Nr   r   r   r   r   r  r   r   r"   r   r   r   z  
    r"   r   c                       \ rS rSrSrS rSrg)r   i  zLE node.c                 
    X:*  $ rk   r   r%  s      r   r  _ExprLE.Apply      r"   r   Nr.  r   r"   r   r   r     
    r"   r   c                   ^   ^  \ rS rSrSr  SU 4S jjr\R                  S 5       rS r	Sr
U =r$ )_ExprWordMatchBasei  z${ HAS EQ NE } word match base class.c                   > [         [        U ]  XX45        XPl        X`l        / U l        U R                  R                  bY  U R                  R                   H>  nUR                  c  M  UR                  Ul        U R                  UR                  5        M@     g U R                  R                  b7  UR                  Ul        U R                  U R                  R                  5        g g rk   )
r   r6  r   _op_warned_attribute	_patternsr
  r   r   _AddPattern)rn   rT   rB   rD   r   rC   rU   r   s          r   r   _ExprWordMatchBase.__init__  s    	
d,W7NH-DN}}+]]--'+!(!5!5'



7//
0 . 
	#	#	/$11g
t}}112 
0r"   c                     g)z,Adds a word match pattern to self._patterns.Nr   )rn   r   s     r   r;  _ExprWordMatchBase._AddPattern  s     	r"   c                     [        U R                  U R                  U R                  U R                  XR
                  5      $ )a%  Checks if value word matches operand ignoring case differences.

Args:
  value: The number, string, dict or list object value.
  operand: Non-pattern operand for equality check. The ':' HAS operator
    operand can be a prefix*suffix pattern or a literal value. Literal
    values are first checked by the _Equals method to handle numeric
    constant matching. String literals and patterns are then matched by the
    _Has method.

Returns:
  True if value HAS matches operand (or any value in operand if it is a
  list) ignoring case differences.
)rf   rT   r	  r8  r9  r:  r%  s      r   r  _ExprWordMatchBase.Apply  s2     dllDIItxx9O9O^^- -r"   )r8  r:  r9  )NN)r   r   r   r   r   r   r   r   r;  r  r   r   r   s   @r   r6  r6    s5    ,:> $3  	 	- -r"   r6  c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r   i  zHAS word match node.c           	      .   > [         [        U ]  XX4SSS9  g )Nr:   _deprecated_has_warnedrC   rU   )r   r   r   r  s        r   r   _ExprHAS.__init__  s!    	(D"74L # Nr"   c                    US:X  a  SnSnGOSnSnSn[        U5      nUR                  S5      n[        U5      S:  a%  [        R                  " SR                  U5      5      eUR                  S5      (       a  USS nSn[        R                  " U5      n	XI-   U-   n[        U5      S	:X  a  UR                  S5        O4UR                  S5      (       a  SnOUR                  S5      (       a  SnOS
nUS   (       a  [        R                  " US   5      OSn
US	   (       a  [        R                  " US	   5      OSnU(       a%  U(       a  U(       a  SU
-   U-   U-   S-   nO/X-   U-   nO'U(       a  SU
-   U-   U-   nOU(       a  X-   U-   S-   nOSn[        R                  [        R                  -  [        R                  -  n[        X,5      nU(       a  [        X<5      nOSnU R                  R                  XU45        g)a8  Adds a HAS match pattern to self._patterns.

A pattern is a word that optionally contains one trailing * that matches
0 or more characters.

This method re-implements both the original and the OnePlatform : using REs.
It was tested against the original tests with no failures.  This cleaned up
the code (really!) and made it easier to reason about the two
implementations.

Args:
  pattern: A string containing at most one trailing *.

Raises:
  resource_exceptions.ExpressionSyntaxError if the pattern contains more
    than one leading or trailing * glob character.
r9   .N\br$      z*At most one * expected in : patterns [{}].r@   r7   z.*r   ^$)r/   rO   rN   r   r   r   endswithr   escaper   
startswith
IGNORECASE	MULTILINEUNICODEr   r:  )rn   r   standard_patterndeprecated_patternheadglobtailnormalized_patternpartswordrt   ru   reflagsrV   rW   s                  r   r;  _ExprHAS._AddPattern  s   $ #~ddd-g6 &&s+e	Ua!778??HJ 	J 
	$	$S	)	)/4YY)*dt+ 
UqRc""C  $)!HRYYuQx "d%*1Xbiia!2e	$"TzD0583>
#{U2
 D[4/%7![5036!mmBLL(3G 0:N#$6@NN74DEFr"   r   	r   r   r   r   r   r   r;  r   r   r   s   @r   r   r     s    NCG CGr"   r   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r   i   zEQ word match node.c           	      @   > [         [        U ]  XX4U=(       d    SSS9  g )N=_deprecated_eq_warnedrD  )r   r   r   )rn   rT   rB   rD   r   rC   r   s         r   r   _ExprEQ.__init__  s&    	'4!'%'Y33J " Lr"   c                 0   [        U5      n[        R                  " U5      nSU-   S-   nSU-   S-   n[        R                  [        R                  -  [        R
                  -  n[        XF5      n[        XV5      nU R                  R                  XU45        g)ab  Adds an EQ match pattern to self._patterns.

A pattern is a word.

This method re-implements both the original and the OnePlatform = using REs.
It was tested against the original tests with no failures.  This cleaned up
the code (really!) and made it easier to reason about the two
implementations.

Args:
  pattern: A string containing a word to match.
rH  rJ  rK  N)	r/   r   rM  rO  rP  rQ  r   r:  r   )	rn   r   rW  rY  rR  rS  rZ  rV   rW   s	            r   r;  _ExprEQ._AddPattern  s     ,G499'(D t|e+ tc)mmBLL(3G 0:N!"4>NN74DEFr"   r   rk   r\  r   s   @r   r   r      s    L
G Gr"   r   c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )r   i$  zNE node.c                 ,   > [         [        U ]  XX4SS9  g )Nz!=)rC   )r   r   r   r  s        r   r   _ExprNE.__init__'  s    	'4!'t!Lr"   c                 4   > [         [        U ]  X5      (       + $ rk   )r   r   r  )rn   r    rD   r   s      r   r  _ExprNE.Apply*  s    Wd)%999r"   r   	r   r   r   r   r   r   r  r   r   r   s   @r   r   r   $  s    M: :r"   r   c                       \ rS rSrSrS rSrg)r   i.  zGE node.c                 
    X:  $ rk   r   r%  s      r   r  _ExprGE.Apply1  r3  r"   r   Nr.  r   r"   r   r   r   .  r4  r"   r   c                       \ rS rSrSrS rSrg)r   i5  zGT node.c                 
    X:  $ rk   r   r%  s      r   r  _ExprGT.Apply8  r-  r"   r   Nr.  r   r"   r   r   r   5  r/  r"   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r   i<  zUnanchored RE match node.c                 v   > [         [        U ]  XX45        [        U R                  R
                  5      U l        g rk   )r   r   r   r   r
  r   r   r  s        r   r   _ExprRE.__init__?  s*    	'4!'Cdmm889DLr"   c                     [        U[        R                  5      (       d  [        S5      eU R                  R                  U5      S L$ Nz(RE match subject value must be a string.r   r   r   r  r   rM   rn   r    unused_operands      r   r  _ExprRE.ApplyC  s;    eS--..@AA<<u%T11r"   r   ri  r   s   @r   r   r   <  s    !:2 2r"   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r   iJ  zUnanchored RE not match node.c                 v   > [         [        U ]  XX45        [        U R                  R
                  5      U l        g rk   )r   r   r   r   r
  r   r   r  s        r   r   _ExprNotRE.__init__M  s*    	*d$W7Fdmm889DLr"   c                     [        U[        R                  5      (       d  [        S5      eU R                  R                  U5      S L $ rt  ru  rv  s      r   r  _ExprNotRE.ApplyQ  s;    eS--..@AA<<u%--r"   ry  ri  r   s   @r   r   r   J  s    %:. .r"   r   )r   )F)/r   
__future__r   r   r   r   r   r)   googlecloudsdk.corer   googlecloudsdk.core.resourcer   r   r	   googlecloudsdk.core.utilr
   r   r   r   r!   r/   r4   rZ   rf   objectrh   add_metaclassABCMetar   rl   r   rr   ry   r}   r   r   r  r   r   r6  r   r   r   r   r   r   r   r   r"   r   <module>r     s    ? &  ' 
 	  # < 5 : - * 
D(/4*Sl&RTf Tt 3;;F   0 5 | l (u ($% $6!6 6!r 3;;\	E \	  \	~m m (- (-VJG! JGZ!G  !GH:g :m m 2m 2. .r"   