
    z                     ~    S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSK
r
 " S S	\	R                  5      rg)
z4Backend rewrite tool for Cloud Datastore operations.    )absolute_import)division)unicode_literalsN)	constants)resource_expr_rewritec                      ^  \ rS rSrSrSSSSSSSS.rSS	0rS\R                  S
00r	U 4S jr
SU 4S jjrS rS rS rSrU =r$ )OperationsRewriteBackend   z<Rewrites for Cloud Datastore server side filter expressions.zmetadata.common.labels.\1z#metadata.entity_filter.namespace_idzmetadata.common.operation_typezmetadata.entity_filter.kind)z^label\.(.*)z^labels\.(.*)z^namespace$z^namespaceId$z^type$z^operationType$z^kind$:= c                    > U R                  U5      nU R                  U5      nU R                  X5      n[        [        U ]  XX45      $ )zRewrites a <key op operand> term of a filter expression.

Args:
  key: The key, a string.
  op: The op, a string.
  operand: The operand, a string or list of strings.
  key_type: The key type, unknown if None.

Returns:
  the new term, as a string.
)_RewriteKey
_RewriteOp_RewriteOperandsuperr	   RewriteTerm)selfkeyopoperandkey_type	__class__s        7lib/googlecloudsdk/api_lib/datastore/rewrite_backend.pyr   $OperationsRewriteBackend.RewriteTerm4   sM     

3
C		B""30G)4<$ $    c                 F   > U=(       d    U(       + n[         [        U ]  XS9$ )ae  Returns value or value "..." quoted with C-style escapes if needed.

Defers to BackendBase.Quote for everything but the empty string, which it
force quotes.

Args:
  value: The string value to quote if needed.
  always: Always quote non-numeric value if True.

Returns:
  A string: value or value "..." quoted with C-style escapes if needed or
  requested.
)always)r   r	   Quote)r   valuer   r   s      r   r   OperationsRewriteBackend.QuoteF   s'       5yF)46u6LLr   c                     [        U[        5      (       a!  U Vs/ s H  o0R                  X5      PM     sn$ U R                  R	                  U0 5      R	                  X"5      $ s  snf N)
isinstancelistr   _KEY_OPERAND_MAPPINGget)r   r   r   operand_items       r   r   (OperationsRewriteBackend._RewriteOperandY   s_    '4  FMFMl

s
1g  $$((b155gGGs   A"c                     [         R                  " U R                  5       H9  u  p#[        R                  " X!5      (       d  M"  [        R
                  " X#U5      s  $    U$ r#   )six	iteritems_KEY_MAPPINGrematchsub)r   r   regexreplacements       r   r   $OperationsRewriteBackend._RewriteKey`   sE    !mmD,=,=>	%		vve#.. ? Jr   c                 8    U R                   R                  X5      $ r#   )_OPERATOR_MAPPINGr'   )r   r   s     r   r   #OperationsRewriteBackend._RewriteOpf   s    !!%%b--r    )F)__name__
__module____qualname____firstlineno____doc__r-   r5   r   DEFAULT_NAMESPACEr&   r   r   r   r   r   __static_attributes____classcell__)r   s   @r   r	   r	      sp    D 44:<09-, 
3 ,

%
%r.$$M&H. .r   r	   )r<   
__future__r   r   r   r.    googlecloudsdk.api_lib.datastorer   googlecloudsdk.core.resourcer   r+   Backendr	   r7   r   r   <module>rD      s4    ; &  ' 	 6 > 
K.4<< K.r   