fF6JddlmZddlmZddlmZmZmZddlmZddlm Z ddl Z ddl Z ddl m Z ddlZ ddlmZdd lmZddlm Ze j(eZd Zee j4d Ze j4dZe j4dZ ddlmZdZ!dZ"dZ#dZ$d&dZ%dZ&Gdde'Z(dZ)d'dZ*d(dZ+gZ,dZ-d Z.d!Z/d)d"Z0d#Z1d$Z2d%Z3y#e$rddlmZdZe j(d Zd ZYwxYw#e$rGddeZ e ddZYwxYw)*)abc) OrderedDict)datetime timedeltatzinfo) InvalidURI)versionN) unquote_plus)ObjectId) TimestampTz4.0Fz(^([^@]+@)?([^:]+|\[[^\]]+\])(:([^:]+))?$z^([^:]+|\[[^\]]+\])(:([^:]+))?$)utcc*eZdZdZdZdZdZdZy) _FixedOffsetc4t||_||_y)N)minutes)r_FixedOffset__offset_FixedOffset__name)selfoffsetnames Z/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/mongomock/helpers.py__init__z_FixedOffset.__init__%s%f5DMDKc2|j|jfSN)rrrs r__getinitargs__z_FixedOffset.__getinitargs__)s==$++- -rc|jSr)rrdts r utcoffsetz_FixedOffset.utcoffset,s == rc|jSr)rr s rtznamez_FixedOffset.tzname/s ;; rctdS)Nr)rr s rdstz_FixedOffset.dst2s Q< rN)__name__ __module__ __qualname__rrr"r$r&rrrr#s  . !  rrUTCc*tjS)aSimple wrapper for datetime.utcnow This provides a centralized definition of "now" in the mongomock realm, allowing users to transform the value of "now" to the future or the past, based on their testing needs. For example: ```python def test_x(self): with mock.patch("mongomock.utcnow") as mm_utc: mm_utc = datetime.utcnow() + timedelta(hours=100) # Test some things "100 hours" in the future ``` )rutcnowr*rrr/r/;s ?? rcFtjd|d|dty)N'zR' has been deprecated to be in line with pymongo implementation, a new parameter 'z]' should be used instead. the old parameter will be kept for backward compatibility purposes.)warningswarnDeprecationWarning)old_param_namenew_param_names rprint_deprecation_warningr7Ls MM&~ 78JLrct|tr ||xstfgSt|ttt j fs td|S)zHelper to generate a list of (key, direction) pairs. It takes such a list, or a single key, or a single key and direction. zEif no direction is specified, key_or_list must be an instance of list) isinstancestr ASCENDINGlisttuplerIterable TypeError) key_or_list directions rcreate_index_listrBSsQ +s#i49566 kD%#> ?BC C rcPdj|Dcgc]}d|z c}Scc}w)zAGenerate an index name based on the list of keys with directions._z%s_%s)join) index_listitems rgen_index_namerH`s% 99<gn< ==>> h1 = hashdict({'apples': 1, 'bananas':2}) >>> h2 = hashdict({'bananas': 3, 'mangoes': 5}) >>> h1+h2 hashdict(apples=1, bananas=3, mangoes=5) >>> d1 = {} >>> d1[h1] = 'salad' >>> d1[h1] 'salad' >>> d1[h2] Traceback (most recent call last): ... KeyError: hashdict(bananas=3, mangoes=5) based on answers from http://stackoverflow.com/questions/1151658/python-hashable-dicts cBtd|jDS)Nc3K|]A\}}|t|tr t|nt|tr t |n|fCywr)r9dictrJr<r=.0kvs r z!hashdict.__key..zsF3"Q )3At)<(1+&0D&9%(3sAA ) frozensetitemsrs r__keyzhashdict.__keyys$3&*ZZ\ 33 3rc dj|jjdjdt |j DS)Nz{0}({1})z, c3pK|].}djt|dt|d0yw)z{0}={1}rr,N)formatr:repr)rOis rrRz$hashdict.__repr__..s-\!i&&s1Q4y$qt*=\s46)rX __class__r'rEsorted_hashdict__keyrs r__repr__zhashdict.__repr__sA  NN # # II\vdjjlG[\ \^ ^rc4t|jSr)hashr]rs r__hash__zhashdict.__hash__sDJJL!!rc^tdj|jjNz${0} does not support item assignmentr?rXr[r')rkeyvalues r __setitem__zhashdict.__setitem__&> 7 78: :rc^tdj|jjrcrd)rres r __delitem__zhashdict.__delitem__rhrc^tdj|jjrcrdrs rclearzhashdict.clearrhrc^tdj|jjrcrdrargskwargss rpopz hashdict.poprhrc^tdj|jjrcrdrns rpopitemzhashdict.popitemrhrc^tdj|jjrcrdrns r setdefaultzhashdict.setdefaultrhrc^tdj|jjrcrdrns rupdatezhashdict.updaterhrcHt|}tj|||Sr)rJrMrw)rrightresults r__add__zhashdict.__add__s$ FE" rN)r'r(r)__doc__r]r^rargrjrlrqrsrurwr{r*rrrJrJfs?$3^ ":::::::rrJcXi}|D]"}t|ts tdd||<$|S)zTakes a list of field names and returns a matching dictionary. ['a', 'b'] becomes {'a': 1, 'b': 1} and ['a.b.c', 'd', 'a.c'] becomes {'a.b.c': 1, 'd': 1, 'a.c': 1} z;fields must be a list of key names, each an instance of strr,)r9r:r?)fieldsas_dictfields rfields_list_to_dictrs9G%%YZ Z Nrcd}|j|std|d|t|d}|s tdd}d|vr9|jd\}}}|s|}d}d|vrtd |zt |}n|j d\}}}|sd |vr td g} d |vr|j d } n|g} | D]} tj| } | s td | jd} | jdr| jdr| dd} | jd} | r! t| } | dks| dkDr tn|} | j| | f|r6|dd k7r.|j d \}}}d|vr|j dd\}}| t |}t| |dS#t$r}td| |d}~wwxYw)aA simplified version of pymongo.uri_parser.parse_uri. Returns a dict with: - nodelist, a tuple of (host, port) - database the name of the database or None if no database is provided in the URI. An invalid MongoDB connection URI may raise an InvalidURI exception, however, the URI is not fully parsed and some invalid URIs may not result in an exception. 'mongodb://host1/database' becomes 'host1', 27017, 'database' and 'mongodb://host1' becomes 'host1', 27017, None z mongodb://z)Invalid URI scheme: URI must begin with 'r1Nz)Must provide at least one hostname or IP..sock/r z7Any '/' in a unix domain socket must be URL encoded: %s?z8A '/' is required between the host list and any options.,Reserved characters such as ':' must be escaped according RFC 2396. An IPv6 address literal must be enclosed in '[' and ']' according to RFC 2732.[]r,r-r,Port must be an integer between 0 and 65535:.)nodelistdatabase) startswithrlen rpartitionr partitionsplit _HOST_MATCHmatch ValueErrorgroupendswithintappendr=)uri default_portr3SCHEME scheme_freedbase host_partrD path_partrhostshostrporterrs r parse_urirs7"F >>& !39<= =c&kl#K DEE E+"-"8"8"= 1i!II ) 02;<= = + "-"7"7"< 1i  ):; ;H i$ !!$')* *{{1~ ??3 DMM#$6":D{{1~  `4y!8te|$,& ,  Dt %-0Yq\S())#. q! %<{{3*HE1 U#hU ;; ` !OQUV\__ `s1F;; G GGcg}|jdD]}|}|jdrd}tj|}|s t d|j d}|j dr|jdr|dd}|j d r0 t|j d }|d ks|d kDr t  |j||f|S#t$r}t d ||d}~wwxYw) z8Split the entity into a list of tuples of host and port.rrNrr,rrr-rrr) rr_SIMPLE_HOST_MATCHrrrrrr)rrrentityrrrrs r split_hostsrsH++c" ??7 #D"((0)* *{{1~ ??3 DMM#$6":D ;;q> `5;;q>*!8te|$,& , t %/#2 O  ` !OQUV\__ `s.C C9' C44C9c ts tdttj}trtd|k(rtdxxdz cc<n tdd=tj |dgt|tdS)z5Get the current timestamp as a bson Timestamp object.z5timestamp is not supported. Import pymongo to use it.rr,N)r NotImplementedErrorrtime_LAST_TIMESTAMP_INCextend)nows rget_current_timestampr5sn !"YZZ diik C215<A!#  """C8, S-a0 11rcttfD]-}t||s|d|jDcSt|tt fr|Dcgc] }t |c}St|trT|jdzdz}|jr$||jz jd|S|j|Str2t|tr"|js|js tS|Scc}w)Nc3<K|]\}}|t|fywr)$patch_datetime_awareness_in_documentrNs rrRz7patch_datetime_awareness_in_document..Js ddaQRa!Ea!HIdsi)r microsecond)r)rrMr9rTr=r<rrrrr"replacer rincr)rf best_typerGmongo_uss rrrBs "4( eY 'dV[VaVaVcdd d)%%'GLMt4T:MM%"%%-5 <<EOO--66dPX6Y Y}}}22Zy1%**UYY$&& LNsD c@t|tr-|jDcic]\}}|t|c}}St|tt fr|Dcgc] }t|c}St|t r|jtS|Scc}}wcc}w)N)r) r9rMrT(make_datetime_timezone_aware_in_documentr=r<rrr)rfrPrQrGs rrrWs%KP;;=Y41a;A>>YY%%'KPQ48>QQ%"}}C}(( L ZQs BBc |}|jd}t|D]N\}}t|tr||}t|tt fr t |} ||}Et||S#t$rN}|s t||dj||d} |D cgc]} t| | ncc} wc} cYd}~cSd}~wwxYw#ttf$r}t||d}~wwxYw)z%Get dictionary value using dotted keyrN) r enumerater9rMr<r=rrKeyErrorrEget_value_by_dot IndexError) docrecan_generate_arrayrz key_items key_indexkey_itemint_keyr remaining_keysubdocs rrrds F #I(3 8 fd #H%F u . Vh- 3 9% %' 4* M V)"9-36 #9:)> ? NTUF(?UUU  V + 3y)s2 3sB A2C 2 C ;&C!B54C<C C  C, C''C,c@ |jdd\}}t||}t|tr|||<|St|t t fr ||t|<|St#t$r|}|}YWwxYw#ttf$r}t|d}~wwxYw)z%Set dictionary value using dotted keyrr,N) rsplitrrr9rMr<r=rrr)rrerf parent_key child_keyparentrs rset_value_by_dotrs # 3 2 I!#z2 &$!y J FT5M * &%*F3y> " Jj  J' &*# % &s)!A+A>+ A;:A;>B BBcv |jdd\}}t||}||=|S#t$r|}|}YwxYw)z`Delete dictionary value using dotted key. This function assumes that the value exists. rr,)rrr)rrerrrs rdelete_value_by_dotrsR  # 3 2 I!#z2 y J  s !( 88c |dvS)z2Converts any value to bool the way MongoDB does it)FNrr*)rfs rmongodb_to_boolrs ( ((rr)iF)r)F)4 collectionsrrrrr mongomockr packagingr rer urllib.parser r2bsonr r pymongopymongo_versionparsePYMONGO_VERSION HAVE_PYMONGO ImportErrormongomock.object_idtypecompileRE_TYPErr bson.tz_utilrrr; DESCENDINGr/r7rBrHrMrJrrrrrrrrrrrr*rrrsM#00  % 2#gmmO4OL zrzz"~ bjjDE RZZ BC! ,   "L > AtAH"T