o
    'h                     @  s   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dZe	deeZG d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                 C  st   d}d| v r|t jO }d| v r|t jO }d| v r|t jO }d| v r&|t jO }d| v r/|t jO }d| v r8|t jO }|S )Nr   ilmsux)re
IGNORECASELOCALE	MULTILINEDOTALLUNICODEVERBOSE)r   flags r   F/var/www/html/olx_land/venv/lib/python3.10/site-packages/bson/regex.pystr_flags_to_int   s   





r    _Tc                   @  sf   e Zd ZdZdZeZeZdZ	e
d!d
dZd"d#ddZd$ddZdZd$ddZd%ddZd&dd ZdS )'RegexzBSON regular expression data.patternr      clsType[Regex[Any]]regexPattern[_T]r   	Regex[_T]c                 C  s(   t |tstdt| 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(   r   r   r   from_native8   s   
zRegex.from_nativer   r$   r!   r   Union[str, int]Nonec                 C  s`   t |ttfstdt| || _t |trt|| _dS t |tr(|| _dS tdt| )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   bytesr,   r-   r$   r    r   r   )selfr$   r   r   r   r   __init__U   s   



zRegex.__init__otherr   boolc                 C  s&   t |tr| j|jko| j|jkS tS N)r+   r"   r$   r   NotImplementedr2   r4   r   r   r   __eq__j   s   
zRegex.__eq__Nc                 C  s
   | |k S r6   r   r8   r   r   r   __ne__r   s   
zRegex.__ne__r   c                 C  s   d| j d| jdS )NzRegex(z, )r#   r2   r   r   r   __repr__u   s   zRegex.__repr__c                 C  s   t | 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<   r   r   r   try_compilex   s   zRegex.try_compile)r&   r'   r(   r)   r   r*   )r   )r$   r!   r   r/   r   r0   )r4   r   r   r5   )r   r   )r   r)   )__name__
__module____qualname____doc__	__slots__r	   __getstate__r
   __setstate___type_markerclassmethodr.   r3   r9   __hash__r:   r=   r?   r   r   r   r   r"   .   s    


r"   )r   r   r   r   )rC   
__future__r   r   typingr   r   r   r   r   r   bson._helpersr	   r
   bson.sonr   r    r   r1   r!   r"   r   r   r   r   <module>   s    
