
    "
                     |    d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ej                  Z	 G d de
      Zdd	Zd
 Zy)zHA utility for setting up lazy compiling of regex to improve performance.    )absolute_import)division)unicode_literalsN)lazy_regex_patternsc                   *    e Zd ZdZddZd Zd Zd Zy)_Lazy_SRE_Patternz A class to lazily compile regex.c                     t         j                  | d|       t         j                  | d|       t         j                  | dd        y )Npatternflagssre_pattern)object__setattr__)selfr
   r   s      *lib/googlecloudsdk/core/util/lazy_regex.py__init__z_Lazy_SRE_Pattern.__init__#   s8    
tY0
tWe,
t]D1    c                 r    t        | j                  | j                        }t        j	                  | d|       y )Nr   )real_compiler
   r   r   r   )r   r   s     r   _compilez_Lazy_SRE_Pattern._compile)   s(    t||TZZ8K
t]K8r   c                 N    | j                          t        | j                  |      S N)r   getattrr   )r   names     r   __getattr__z_Lazy_SRE_Pattern.__getattr__-   s    MMO4##T**r   c                 R    | j                          t        | j                  ||       y r   )r   setattrr   )r   r   values      r   r   z_Lazy_SRE_Pattern.__setattr__1   s    MMODdE*r   Nr   )__name__
__module____qualname____doc__r   r   r   r    r   r   r   r       s    (29++r   r   c                 V    | t         j                  v rt        | |      S t        | |      S )ai  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-    $ #,,,We,,	gu	%%r   c                  "    t         t        _        y r   )r&   recompiler#   r   r   initialize_lazy_compiler*   M   s	    "*r   r   )r"   
__future__r   r   r   r(   googlecloudsdk.core.utilr   r)   r   r   r   r&   r*   r#   r   r   <module>r-      s;   " O &  ' 	 8 zz+ +,&.r   