foUdZddlmZddlZddlZddlmZddlm Z m Z m Z m Z mZm Z mZmZmZmZmZmZeej*dZded<ed Zed Zed ZGd d e eefZy)zTools for creating and manipulating SON, the Serialized Ocument Notation. Regular dictionaries can be used instead of SON objects, but not when the order of keys is important. A SON object can be used just like a normal Python dictionary. ) annotationsN)Mapping) AnyDictIterableIteratorrOptionalPatternTupleTypeTypeVarUnioncastzType[Pattern[Any]]RE_TYPE_Key_Value_TceZdZUdZded< d ddZdfd ZddZddZddZ d d Z d!d Z d"d Z d!d Z d#d Zd$dZd%fd Zd&dZd'dZd(dZdd)dZ d d*dZd+dZd+dZd,dZd-dZd.dZxZS)/SONzSON data. A subclass of dict that maintains ordering of keys and provides a few extra niceties for dealing with SON. SON provides an API similar to collections.OrderedDict. z list[Any] _SON__keysc g|_tj||j||j|yN)rdict__init__update)selfdatakwargss Q/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/bson/son.pyrz SON.__init__<s/   d D Fc<t||g|i|}g|_|Sr)super__new__r)clsargsrinstance __class__s r r$z SON.__new__Fs'7?3888r!cg}|jD]}|jd|d||dddj|zS)N(z, )z SON([%s]))rappendjoin)rresultkeys r __repr__z SON.__repr__KsH;;C MMAcWBtCym15 6TYYv...r!c||jvr|jj|tj|||yr)rr,r __setitem__)rr/values r r2zSON.__setitem__Qs2 dkk ! KK  s # sE*r!cf|jj|tj||yr)rremover __delitem__rr/s r r6zSON.__delitem__Vs$ 3 s#r!c<t}|j||Sr)rrrothers r copyzSON.copyZs#&5 T r!c#8K|jEd{y7wrrrs r __iter__z SON.__iter__bs;;s c||jvSrr=r7s r has_keyz SON.has_keyesdkk!!r!c"|jSr)r?r>s r iterkeysz SON.iterkeyshs}}r!c#DK|jD] \}}| ywritemsr_vs r itervalueszSON.itervalueslsJJLDAqG!s cT|jDcgc]\}}| c}}Scc}}wrrErGs r valuesz SON.valuesps "jjl+da+++s $c0g|_t| yr)rr#clear)rr(s r rNz SON.clearss   r!c8 ||S#t$r |||<Y|SwxYwrKeyErrorrr/defaults r setdefaultzSON.setdefaultws. 9  DI s c t|dkDr#tdtdt|zz ||}||=|S#t$r |r|dcYSwxYw)Nz&pop expected at most 2 arguments, got r)len TypeErrorreprrQ)rr/r&r3s r popzSON.pop~sj t9q=DtAPSTXPYMGZZ[ [ IE I  Aw  s=AAc tt|j\}}||=||fS#t$r t ddwxYw)Nzcontainer is empty)nextiterrF StopIterationrQ)rkrIs r popitemz SON.popitemsQ ;TZZ\*+DAq G1v  ;/0d : ;s %.Ac |nUt|dr|jD] \}}|||< n+t|dr|D] }||||< n|D] \}}|||< |r|j|yy)NrFkeys)hasattrrFr)rr:rr_rIs r rz SON.updates =  UG $ 1Q& UF #(Q1Q  KK  r!c0 ||S#t$r|cYSwxYwrrPrRs r getzSON.gets% 9  N s  ct|trLt|t|k(xr3t|j t|j k(St t |j|k(S)z|Comparison to another SON is order-sensitive while comparison to a regular dictionary is order-insensitive. ) isinstancerrWlistrFrboolto_dictr9s r __eq__z SON.__eq__sY eS !t9E *XtDJJL/AT%++-EX/X XD$,,.E122r!c||k( Srr9s r __ne__z SON.__ne__s5=  r!c,t|jSr)rWrr>s r __len__z SON.__len__s4;;r!cFdfd tdt|S)zConvert a SON document to a normal Python dictionary instance. This is trickier than just *dict(...)* because it needs to be recursive. ct|tr|Dcgc] }| c}St|tr*|jDcic]\}}||c}}S|Scc}wcc}}wr)rgrh_MappingrF)r3rIr_transform_values r rtz$SON.to_dict..transform_values_%&49:q*::E8,:?++-H$!Q?1--HH ;Hs A$ A)dict[_Key, _Value])r3rreturnr)rr)rrts @r rjz SON.to_dicts! (/$t**EFFr!ct}t|}||vr||S|||<|jD]0\}}t|tst j ||}|||<2|Sr)ridrFrgrr;deepcopy)rmemooutval_idr_rIs r __deepcopy__zSON.__deepcopy__sj!$D T>< V JJLDAqa)MM!T*CF! r!r)rzEOptional[Union[Mapping[_Key, _Value], Iterable[Tuple[_Key, _Value]]]]rrrvNone)r%zType[SON[_Key, _Value]]r&rrrrvSON[_Key, _Value])rvstr)r/rr3rrvr~)r/rrvr~)rvr)rvzIterator[_Key])r/rrvri)rvzIterator[_Value])rvz list[_Value])rvr~)r/rrSrrvr)r/rr&Union[_Value, _T]rvr)rvzTuple[_Key, _Value])r:z Optional[Any]rrrvr~)r/rrSzOptional[Union[_Value, _T]]rvzUnion[_Value, _T, None])r:rrvri)rvint)rvru)rzzdict[int, SON[_Key, _Value]]rvr)__name__ __module__ __qualname____doc____annotations__rr$r0r2r6r;r?rArCrJrLrNrTrZr`rrerkrnrprjr} __classcell__)r(s@r rr2s W[S   / + $",  "AE"= 3! G" r!r)r __future__rr;recollections.abcrrstypingrrrrr r r r r rrtypecompilerrrrrrrmr!r rs{ # /    "#:2::b>2 2v   T]a$tV| ar!