
    FCf                        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y)z3Tools for representing MongoDB regular expressions.    )annotationsN)AnyGenericPatternTypeTypeVarUnion)_getstate_slots_setstate_slots)RE_TYPEc                   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)	str_flagsflagss     J/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/bson/regex.pystr_flags_to_intr      s    E
i
i
i
i
i
iL    _Tc                  `    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y)RegexzBSON regular expression data.patternr      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   )clsregexs     r   from_nativezRegex.from_native8   s;    0 %)QTXY^T__``U]]EKK00r   c                
   t        |t        t        f      st        dt	        |      z        || _        t        |t              rt        |      | _        yt        |t              r|| _        y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'   strbytesr(   r)   r$   r   r   int)selfr$   r   s      r   __init__zRegex.__init__U   sj     'C<0>gNOO"eS!)%0DJs#DJCd5kQRRr   c                    t        |t              r4| j                  |j                  k(  xr | j                  |j                  k(  S t        S N)r'   r"   r$   r   NotImplementedr1   others     r   __eq__zRegex.__eq__j   s7    eU#<<5==0NTZZ5;;5NN!!r   Nc                    | |k(   S r4    r6   s     r   __ne__zRegex.__ne__r   s    5=  r   c                <    d| j                   d| j                  dS )NzRegex(z, )r#   r1   s    r   __repr__zRegex.__repr__u   s     'r$**q99r   c                V    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   r>   s    r   try_compilezRegex.try_compilex   s     zz$,,

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