
    +h                        d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ ddZ e	dee          Z G d dee                   ZdS )z3Tools for representing MongoDB regular expressions.    )annotationsN)AnyGenericPatternTypeTypeVarUnion)_getstate_slots_setstate_slots)RE_TYPE	str_flagsstrreturnintc                    d}d| v r|t           j        z  }d| v r|t           j        z  }d| v r|t           j        z  }d| v r|t           j        z  }d| v r|t           j        z  }d| v r|t           j        z  }|S )Nr   ilmsux)re
IGNORECASELOCALE	MULTILINEDOTALLUNICODEVERBOSE)r   flagss     N/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/bson/regex.pystr_flags_to_intr!      s    E
i
i
i
i
i
iL    _Tc                  h    e Zd ZdZdZeZeZdZ	e
dd
            ZdddZddZdZddZddZd dZdS )!RegexzBSON regular expression data.patternr      clsType[Regex[Any]]regexPattern[_T]r   	Regex[_T]c                    t          |t                    st          dt          |          z            t	          |j        |j                  S )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   )r)   r+   s     r    from_nativezRegex.from_native8   sI    0 %)) 	aQTXY^T_T__```U]EK000r"   r   r'   r#   r   Union[str, int]Nonec                V   t          |t          t          f          st          dt	          |          z            || _        t          |t                    rt          |          | _        dS t          |t                    r	|| _        dS t          dt	          |          z            )aR  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/   r   bytesr0   r1   r'   r!   r   r   )selfr'   r   s      r    __init__zRegex.__init__U   s     'C<00 	P>gNOOO"eS!! 	S)%00DJJJs## 	SDJJJCd5kkQRRRr"   otherr   boolc                z    t          |t                    r | j        |j        k    o| j        |j        k    S t          S N)r/   r%   r'   r   NotImplementedr7   r9   s     r    __eq__zRegex.__eq__j   s7    eU## 	"<5=0NTZ5;5NN!!r"   Nc                    | |k     S r<    r>   s     r    __ne__zRegex.__ne__r   s    5=  r"   r   c                (    d| j         d| j        dS )NzRegex(z, )r&   r7   s    r    __repr__zRegex.__repr__u   s    999$*9999r"   c                @    t          j        | j        | j                  S )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   rE   s    r    try_compilezRegex.try_compilex   s     z$,
333r"   )r)   r*   r+   r,   r   r-   )r   )r'   r#   r   r3   r   r4   )r9   r   r   r:   )r   r   )r   r,   )__name__
__module____qualname____doc__	__slots__r
   __getstate__r   __setstate___type_markerclassmethodr2   r8   r?   __hash__rB   rF   rI   rA   r"   r    r%   r%   .   s        ''$I"L"LL1 1 1 [18S S S S S*" " " " H! ! ! !: : : :4 4 4 4 4 4r"   r%   )r   r   r   r   )rM   
__future__r   r   typingr   r   r   r   r   r	   bson._helpersr
   r   bson.sonr   r!   r   r6   r#   r%   rA   r"   r    <module>rX      s    : 9 " " " " " " 				 > > > > > > > > > > > > > > > > : : : : : : : :         $ WT3W4 W4 W4 W4 W4GBK W4 W4 W4 W4 W4r"   