
    "
                     ~    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  \R                  r	 " S S\
5      rSS	 jrS
 rg)zHA utility for setting up lazy compiling of regex to improve performance.    )absolute_import)division)unicode_literalsN)lazy_regex_patternsc                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
_Lazy_SRE_Pattern    z A class to lazily compile regex.c                     [         R                  U SU5        [         R                  U SU5        [         R                  U SS 5        g )Npatternflagssre_pattern)object__setattr__)selfr   r   s      *lib/googlecloudsdk/core/util/lazy_regex.py__init___Lazy_SRE_Pattern.__init__#   s8    
tY0
tWe,
t]D1    c                 r    [        U R                  U R                  5      n[        R	                  U SU5        g )Nr   )real_compiler   r   r   r   )r   r   s     r   _compile_Lazy_SRE_Pattern._compile)   s(    t||TZZ8K
t]K8r   c                 N    U R                  5         [        U R                  U5      $ N)r   getattrr   )r   names     r   __getattr___Lazy_SRE_Pattern.__getattr__-   s    MMO4##T**r   c                 P    U R                  5         [        U R                  X5        g r   )r   setattrr   )r   r   values      r   r   _Lazy_SRE_Pattern.__setattr__1   s    MMODd*r    Nr   )
__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes__r#   r   r   r   r       s    (29++r   r   c                 V    U [         R                  ;   a  [        X5      $ [        X5      $ )aO  Return a Lazy or normal SRE_Pattern object depending on the args.

Patterns in lazy_regex_patterns.PATTERNS are known to be valid, so they will
be compiled lazily. Other patterns will be compiled immediately, as it is not
known if they will compile or raise an re.error.

For more information on the arguments, see:
https://docs.python.org/3/howto/regex.html#compilation-flags

Args:
  pattern: The pattern to be compiled.
  flags: Flags to be used during compilation.
Returns:
  An SRE_Pattern or a _Lazy_SRE_Pattern.
Raises:
  re.error: If the arguments do not form a valid regex pattern.
)r   PATTERNSr   r   )r   r   s     r   _lazy_compiler-   6   s)    $ #,,,W,,	g	%%r   c                  "    [         [        l        g r   )r-   recompiler#   r   r   initialize_lazy_compiler1   M   s	    "*r   r$   )r)   
__future__r   r   r   r/   googlecloudsdk.core.utilr   r0   r   r   r   r-   r1   r#   r   r   <module>r4      s;   " O &  ' 	 8 zz+ +,&.r   