
    h                     H    d Z ddlZddlmZ ddlmZmZ d Z G d de      Z	y)z4Tools for representing MongoDB regular expressions.
    N)RE_TYPE)string_type	text_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     M/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/bson/regex.pystr_flags_to_intr      s    E
i
i
i
i
i
iL    c                   H    e Zd ZdZdZed        Zd
dZd ZdZ	d Z
d Zd	 Zy)RegexzBSON regular expression data.   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({'pattern': regex})

        :Parameters:
          - `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   patternr   )clsregexs     r   from_nativezRegex.from_native.   sA    2 %)Eu+  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        )ap  BSON regular expression data.

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

        :Parameters:
          - `pattern`: string
          - `flags`: (optional) 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   bytesr   r   r    r   r   r   int)selfr    r   s      r   __init__zRegex.__init__N   sq     'Iu#56>gNOOe[))%0DJs#DJ7$u+EG Gr   c                     t        |t              r4| j                  |j                  k(  xr | j                  |j                  k(  S t        S N)r   r   r    r   NotImplementedr'   others     r   __eq__zRegex.__eq__e   s7    eU#<<5==0NTZZ5;;5NN!!r   Nc                     | |k(   S r*    r,   s     r   __ne__zRegex.__ne__m   s    5=  r   c                 <    d| j                   d| j                  dS )NzRegex(z, ))r    r   r'   s    r   __repr__zRegex.__repr__p   s    "&,,

;;r   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   r4   s    r   try_compilezRegex.try_compiles   s     zz$,,

33r   )r   )__name__
__module____qualname____doc___type_markerclassmethodr#   r(   r.   __hash__r1   r5   r8   r0   r   r   r   r   *   s=    'L1 1>G." H!<4r   r   )
r<   r   bson.sonr   bson.py3compatr   r   r   objectr   r0   r   r   <module>rC      s(    
  1$V4F V4r   