
    @hq                        S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
  SSKJrJr  SSKJr  SS jr\	" S\\5      r " S	 S
\\   5      rg)z3Tools for representing MongoDB regular expressions.    )annotationsN)AnyGenericPatternTypeTypeVarUnion)_getstate_slots_setstate_slots)RE_TYPEc                6   SnSU ;   a  U[         R                  -  nSU ;   a  U[         R                  -  nSU ;   a  U[         R                  -  nSU ;   a  U[         R                  -  nSU ;   a  U[         R
                  -  nSU ;   a  U[         R                  -  nU$ )Nr   ilmsux)re
IGNORECASELOCALE	MULTILINEDOTALLUNICODEVERBOSE)	str_flagsflagss     OC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\bson/regex.pystr_flags_to_intr      s    E
i
i
i
i
i
iL    _Tc                  v    \ rS rSrSrSr\r\r	Sr
\SS j5       rSSS jjrSS jrSrSS	 jrSS
 jrSS jrSrg)Regex.   zBSON regular expression data.patternr      c                    [        U[        5      (       d  [        S[        U5      -  5      e[	        UR
                  UR                  5      $ )a,  Convert a Python regular expression into a ``Regex`` instance.

Note that in Python 3, a regular expression compiled from a
:class:`str` has the ``re.UNICODE`` flag set. If it is undesirable
to store this flag in a BSON regular expression, unset it first::

  >>> pattern = re.compile('.*')
  >>> regex = Regex.from_native(pattern)
  >>> regex.flags ^= re.UNICODE
  >>> db.collection.insert_one({'pattern': regex})

:param regex: A regular expression object from ``re.compile()``.

.. warning::
   Python regular expressions use a different syntax and different
   set of flags than MongoDB, which uses `PCRE`_. A regular
   expression retrieved from the server may not compile in
   Python, or may match a different set of strings in Python than
   when used in a MongoDB query.

.. _PCRE: http://www.pcre.org/
z3regex must be a compiled regular expression, not %s)
isinstancer   	TypeErrortyper"   r%   r   )clsregexs     r   from_nativeRegex.from_native8   s>    0 %))QTXY^T__``U]]EKK00r   c                $   [        U[        [        45      (       d  [        S[	        U5      -  5      eXl        [        U[        5      (       a  [        U5      U l        g[        U[        5      (       a  X l        g[        S[	        U5      -  5      e)a"  BSON regular expression data.

This class is useful to store and retrieve regular expressions that are
incompatible with Python's regular expression dialect.

:param pattern: string
:param flags: an integer bitmask, or a string of flag
    characters like "im" for IGNORECASE and MULTILINE
z pattern must be a string, not %sz%flags must be a string or int, not %sN)	r(   strbytesr)   r*   r%   r   r   int)selfr%   r   s      r   __init__Regex.__init__U   so     'C<00>gNOO"eS!!)%0DJs##JCd5kQRRr   c                    [        U[        5      (       a9  U R                  UR                  :H  =(       a    U R                  UR                  :H  $ [        $ N)r(   r"   r%   r   NotImplementedr3   others     r   __eq__Regex.__eq__j   s:    eU##<<5==0NTZZ5;;5NN!!r   Nc                    X:X  + $ r7    r9   s     r   __ne__Regex.__ne__r   s      r   c                @    SU R                   < SU R                  < S3$ )NzRegex(z, )r$   r3   s    r   __repr__Regex.__repr__u   s     'r$**q99r   c                X    [         R                  " U R                  U R                  5      $ )a  Compile this :class:`Regex` as a Python regular expression.

.. warning::
   Python regular expressions use a different syntax and different
   set of flags than MongoDB, which uses `PCRE`_. A regular
   expression retrieved from the server may not compile in
   Python, or may match a different set of strings in Python than
   when used in a MongoDB query. :meth:`try_compile()` may raise
   :exc:`re.error`.

.. _PCRE: http://www.pcre.org/
)r   compiler%   r   rC   s    r   try_compileRegex.try_compilex   s     zz$,,

33r   )r   r%   )r+   zType[Regex[Any]]r,   Pattern[_T]returnz	Regex[_T])r   )r%   r    r   zUnion[str, int]rK   None)r:   r   rK   bool)rK   r0   )rK   rJ   )__name__
__module____qualname____firstlineno____doc__	__slots__r
   __getstate__r   __setstate___type_markerclassmethodr-   r4   r;   __hash__r?   rD   rH   __static_attributes__r>   r   r   r"   r"   .   sL    '$I"L"LL1 18S*" H!:4r   r"   )r   r0   rK   r2   )rR   
__future__r   r   typingr   r   r   r   r   r	   bson._helpersr
   r   bson.sonr   r   r0   r1   r    r"   r>   r   r   <module>r^      sC    : " 	 > > : $ T3W4GBK W4r   