fdZddlmZddlZddlmZmZmZmZm Z m Z ddl m Z m Z ddlmZd dZe deeZGd d eeZy) z3Tools for representing MongoDB regular expressions.) annotationsN)AnyGenericPatternTypeTypeVarUnion)_getstate_slots_setstate_slots)RE_TYPEcd}d|vr|tjz}d|vr|tjz}d|vr|tjz}d|vr|tjz}d|vr|tj z}d|vr|tj z}|S)Nrilmsux)re IGNORECASELOCALE MULTILINEDOTALLUNICODEVERBOSE) str_flagsflagss S/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/bson/regex.pystr_flags_to_intrs E i  i  i  i  i  i  L_Tc`eZdZdZdZeZeZdZ e d dZ d d dZ ddZ dZddZdd Zdd Zy)RegexzBSON regular expression data.patternr ct|tstdt|zt |j |j S)aConvert 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 TypeErrortyper"r$r)clsregexs r from_nativezRegex.from_native8s;0%)QTXY^T__` `U]]EKK00rc t|ttfstdt |z||_t|trt ||_yt|tr||_ytdt |z)aRBSON 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'strbytesr(r)r$rrint)selfr$rs r__init__zRegex.__init__Usj'C<0>gNO O" eS !)%0DJ s #DJCd5kQR Rrct|tr4|j|jk(xr|j|jk(StSN)r'r"r$rNotImplementedr1others r__eq__z Regex.__eq__js7 eU #<<5==0NTZZ5;;5N N! !rNc||k( Sr4r6s r__ne__z Regex.__ne__rs5=  rc<d|jd|jdS)NzRegex(z, )r#r1s r__repr__zRegex.__repr__us  'r$**q99rcVtj|j|jS)aCompile 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/ )rcompiler$rr>s r try_compilezRegex.try_compilexszz$,, 33r)r*zType[Regex[Any]]r+ Pattern[_T]returnz Regex[_T])r)r$r rzUnion[str, int]rDNone)r7rrDbool)rDr.)rDrC)__name__ __module__ __qualname____doc__ __slots__r __getstate__r __setstate__ _type_marker classmethodr,r2r8__hash__r;r?rBr:rrr"r".sL'$I"L"LL118S*" H!: 4rr")rr.rDr0)rJ __future__rrtypingrrrrrr bson._helpersr r bson.sonr rr.r/r r"r:rrrUsC:" >>:$ T3W4GBKW4r