o
    C©Ì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   úY/var/www/html/Moveonwheels/move_on_wheels/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    
