Files
witness-fracture/.venv/lib/python3.12/site-packages/__pycache__/jsonpatch.cpython-312.pyc
T

229 lines
35 KiB
Plaintext
Raw Normal View History

2025-06-23 17:55:02 -05:00
Ë
‘»YhRtãó¢—dZddlmZddlZddlZddlZddlZddlZ ddlm Z  ddl m Z ddlmZmZdZdZ ddlmZmZd Zd
Zd Zd Zej6d
k\reefZGd„de«ZGd„de«Z Gd„de«Z!Gd„dee"«Z#d„Z$ejJejLe$¬«Z'defd„Z(efd„Z)Gd„de*«Z+Gd„de+«Z,Gd„d e+«Z-Gd!„d"e+«Z.Gd#„d$e+«Z/Gd%„d&e+«Z0Gd'„d(e+«Z1Gd)„d*e*«Z2Gd+„d,e*«Z3d-„Z4y#e
$r
ddlm Z Y�ŒwxYw#e
$re
Z Y�Œ wxYw#e
$rddlmZmZeZY�Œ
wxYw).z Apply JSON-Patches (RFC 6902) é)Úunicode_literalsN)ÚSequence)ÚMappingProxyType)Ú JsonPointerÚJsonPointerExceptioné)ÚMutableMappingÚMutableSequenceu Stefan Kögl <stefan@skoegl.net>z1.33z0https://github.com/stefankoegl/python-json-patchzModified BSD License)ércó—eZdZdZy)ÚJsonPatchExceptionzBase Json Patch exceptionN©Ú__name__Ú
__module__Ú __qualname__Ú__doc__©óúR/mnt/c/fieldcraft/witness-fracture/.venv/lib/python3.12/site-packages/jsonpatch.pyr
r
Pó„Ú#rr
có—eZdZdZy)ÚInvalidJsonPatchz, Raised if an invalid JSON Patch is created NrrrrrrTs„Ú6rrcó—eZdZdZy)ÚJsonPatchConflicta
Raised if patch could not be applied due to conflict situation such as:
- attempt to add object key when it already exists;
- attempt to operate with nonexistence object key;
- attempt to insert value to array at position beyond its size;
- etc.
NrrrrrrXs„òrrcó—eZdZdZy)ÚJsonPatchTestFailedz A Test operation failed Nrrrrrrarrrcó°—tjt«}|D]\}}||j|«Œt d„|j «D««S)z'Convert duplicate keys values to lists.c3óPK—|]\}}|t|«dk(r|dn|f–—Œ y­w)rrN)Úlen)Ú.0ÚkeyÚvaluess rú <genexpr>zmultidict.<locals>.<genexpr>ls4èø€òñ
ˆC�ð
œ3˜v›;¨!Ò+ˆf�QŠi°Ô8ñùs‚$&)Ú collectionsÚ defaultdictÚlistÚappendÚdictÚitems)Ú
ordered_pairsÚmdictr!Úvalues rÚ multidictr-es]€ô
× #Ñ #¤DÓ )€EØ#ò!‰
ˆˆUØ
ˆc‰
×ј%Õ ð!ô ñð!Ÿ;™;›=ôó ðr)Úobject_pairs_hookFcó�—t|t«rtj||¬«}n
t||¬«}|j ||«S)a¬Apply list of patches to specified json document.
:param doc: Document object.
:type doc: dict
:param patch: JSON patch as list of dicts or raw JSON-encoded string.
:type patch: list or str
:param in_place: While :const:`True` patch will modify target document.
By default patch will be applied to document copy.
:type in_place: bool
:param pointer_cls: JSON pointer class to use.
:type pointer_cls: Type[JsonPointer]
:return: Patched document object.
:rtype: dict
>>> doc = {'foo': 'bar'}
>>> patch = [{'op': 'add', 'path': '/baz', 'value': 'qux'}]
>>> other = apply_patch(doc, patch)
>>> doc is not other
True
>>> other == {'foo': 'bar', 'baz': 'qux'}
True
>>> patch = [{'op': 'add', 'path': '/baz', 'value': 'qux'}]
>>> apply_patch(doc, patch, in_place=True) == {'foo': 'bar', 'baz': 'qux'}
True
>>> doc == other
True
©Ú pointer_cls)Ú
isinstanceÚ
basestringÚ JsonPatchÚ from_stringÚapply)ÚdocÚpatchÚin_placer1s rÚ apply_patchr:xsA€ôB�%œÔ$Ü×%Ñ% e¸Ð%ÓE‰ä˜%¨[Ô9ˆØ �;‰;�s˜HÓ %Ð%rcó2—tj|||¬«S)a!Generates patch by comparing two document objects. Actually is
a proxy to :meth:`JsonPatch.from_diff` method.
:param src: Data source document object.
:type src: dict
:param dst: Data source document object.
:type dst: dict
:param pointer_cls: JSON pointer class to use.
:type pointer_cls: Type[JsonPointer]
>>> src = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
>>> dst = {'baz': 'qux', 'numbers': [1, 4, 7]}
>>> patch = make_patch(src, dst)
>>> new = patch.apply(src)
>>> new == dst
True
r0)r4Ú from_diff)ÚsrcÚdstr1s rÚ
make_patchr? s€ô* × Ñ ˜s C°[Ð Ó AÐArcóv—eZdZdZefd„Zd„Zd„Zd„Zd„Z e
d„«Z e
d„«Z e jd „«Z y
) ÚPatchOperationz'A single operation inside a JSON Patch.cód—||_|jd«s td«‚t|d|j«r&|dj|_|d|_||_y|d|_ |j|j
«|_||_y#t$r}td«‚d}~wwxYw)NÚpathz#Operation must have a 'path' memberzInvalid 'path') r1Ú __contains__rr2rCÚlocationÚpointerÚ TypeErrorÚ operation)ÚselfrHr1Úexs rÚ__init__zPatchOperation.__init__»s°€Ø&ˆÔà×%Ñ% fÔ-Ü"Ð#HÓIÐ Iä �i Ñ'¨×)9Ñ)9Ô :Ø% fÑ-×2Ñ2ˆDŒMØ$ VÑ,ˆDŒLð#ˆ�ð
& fÑ-ˆDŒMð
9Ø#×/Ñ/°·
±
Ó>�” ð#ˆ�øôò
9Ü&Ð'7Ó8Ð8ûð
9úsÁ. B B/ B*Â*B/có—td«‚)zGAbstract method that applies a patch operation to the specified object.z%should implement the patch operation.)ÚNotImplementedError)rIÚobjs rr6zPatchOperation.applyÍs€ä!Ð"IÓJÐJrcóZ—tt|jj«««S©N)ÚhashÚ frozensetrHr)©rIs rÚ__hash__zPatchOperation.__hash__Ñs€Ü”I˜dŸn™n×2Ñ2Ó4Ó5Ó6Ð6rcóV—t|t«sy|j|jk(S©NF)r2rArH©rIÚothers rÚ__eq__zPatchOperation.__eq__Ôs"€Ü˜%¤Ô0ØØ�~‰~ §¡Ñ0Ð0rcó—||k( SrPrrWs rÚ__ne__zPatchOperation.__ne__Ùó€Ø˜5‘=Ð!Ð!rcóR—dj|jjdd«S)Nú/éÿÿÿÿ)ÚjoinrFÚpartsrSs rrCzPatchOperation.pathÜs"€à�x‰x˜Ÿ ™ ×*Ñ*¨3¨BÐ/Ó0Ð0rcó˜— t|jjd«S#t$r|jjdcYSwxYw)Nr_)ÚintrFraÚ
ValueErrorrSs rr!zPatchOperation.keyàsE€ð *Ü�t—|‘|×)Ñ)¨"Ñ-Ó.Ð .øÜò *Ø—<‘<×%Ñ% bÑ)Ò )ð *ús‚!$¤"A ÁA có°—t|«|jjd<|jj|_|j|j
d<y)Nr_rC)ÚstrrFrarCrErH)rIr,s rr!zPatchOperation.keyçs=€ä!$ U£ˆ� ‰ ×ј2ÑØŸ ™ ×)Ñ)ˆŒ
Ø!%§¡ˆ�‰�vÒrN)rrrrrrKr6rTrYr[ÚpropertyrCr!ÚsetterrrrrArA¸sb„Ù1à.9ó#ò$Kò7ò1ò
"ðñ1óð1ðñ*óð*ð  ‡Z�Zñ/óñ/rrAcó"—eZdZdZd„Zd„Zd„Zy)ÚRemoveOperationz/Removes an object property or an array element.có$—|jj|«\}}t|t«r*t|t«st dj
|««‚ ||=|S#ttf$r!}dj
|«}t|«‚d}~wwxYw)Nzinvalid array index '{0}'z(can't remove a non-existent object '{0}')
rFÚto_lastr2rrcrÚformatÚKeyErrorÚ
IndexErrorr)rIrNÚsubobjÚpartrJÚmsgs rr6zRemoveOperation.applyñs‰€Ø—|‘|×+Ñ+¨CÓ0‰ ˆ�ä �fœhÔ '´
¸4ÄÔ0EÜ&Ð'B×'IÑ'IÈ$Ó'OÓPÐ Pð )Ø�t� ð
ˆ
øô œ*Ð%ò )Ø<×CÑCÀDÓIˆCÜ# CÓ(Ð (ûð )úsÁAÁBÁ.B
Â
Bcóz—|j|k(r+|j|k\r|xjdz
c_|S|dz}|S©Nr©rCr!©rIrCr!s rÚ_on_undo_removezRemoveOperation._on_undo_removeÿs=€Ø �9‰9˜Ò Ø�x‰x˜3ŠØ—’˜A‘
•ðˆ
ð�q‘�؈
rcóz—|j|k(r+|j|kDr|xjdzc_|S|dz}|Srtrurvs rÚ _on_undo_addzRemoveOperation._on_undo_addó=€Ø �9‰9˜Ò Ø�x‰x˜#Š~Ø—’˜A‘
•ðˆ
ð�q‘�؈
rN©rrrrr6rwryrrrrjrjîs„Ù9ò òórrjcó"—eZdZdZd„Zd„Zd„Zy)Ú AddOperationz,Adds an object property or an array element.có— |jd}|jj |«\}}t |t «rJ|dk(r|j|«|S|t|«kDs|dkr td«‚|j||«|St |t«r
|€|}|S|||<|S|€#tdjt|«««‚tdj|j|««‚#t$r}td«‚d}~wwxYw)Nr,ú/The operation does not contain a 'value' memberú-rzcan't insert outside of listúinvalid document type {0}ú2unable to fully resolve json pointer {0}, part {1})rHrnrrFrlr2r
r'rrÚinsertr rGrmÚtyperE)rIrNr,rJrprqs rr6zAddOperation.applys#€ð CØ—N‘N 7Ñ+ˆEð
—|‘|×+Ñ+¨CÓ0‰ ˆ�ä �fœoÔ .Ø�sŠ{Ø—
‘
˜eÔ$ð&ˆ
ð#œ˜F› Ò# t¨a¢xÜ'Ð(FÓGÐGð—
‘
˜d EÔ*ðˆ
ô˜¤Ô
/؈|Ø�ðˆ
ð %��t‘ ðˆ
ð ˆ|ÜÐ ;× BÑ BÄ4ÈÃ<Ó PÓQÐQä'Ð(\×(cÑ(cÐdh×dqÑdqÐswÓ(xÓyÐyøô5ò CÜ"ØAóCð
Cûð Cús‚C0Ã0 D Ã9 DÄD cóz—|j|k(r+|j|kDr|xjdz
c_|S|dz
}|Srtrurvs rrwzAddOperation._on_undo_remove3rzrcóz—|j|k(r+|j|kDr|xjdzc_|S|dz
}|Srtrurvs rryzAddOperation._on_undo_add;rzrNr{rrrr}r}s„Ù6òò@órr}có"—eZdZdZd„Zd„Zd„Zy)ÚReplaceOperationz?Replaces an object property or an array element by a new value.có— |jd}|jj |«\}}|€|S|dk(r td«‚t |t «r|t|«k\s|dkr…td«‚t |t«r ||vrfdj|«}t|«‚|€#tdjt|«««‚td j|j|««‚|||<|S#t$r}td«‚d}~wwxYw)
Nr,rr€z7'path' with '-' can't be applied to 'replace' operationrzcan't replace outside of listz)can't replace a non-existent object '{0}'r�r‚)rHrnrrFrlr2r
rrr rmrGr„rE)rIrNr,rJrprqrrs rr6zReplaceOperation.applyGs€ð CØ—N‘N 7Ñ+ˆEð
—|‘|×+Ñ+¨CÓ0‰ ˆ�à ˆ<؈Là �3Š;Ü"Ð#\Ó]Ð ]ä �fœoÔ .Ø”s˜6“{Ò" d¨Q¢hÜ'Ð(GÓHÐHä
˜¤Ô
/ؘ6Ñ!ØA×HÑHÈÓN�Ü'¨Ó,Ð,àˆ|ÜÐ ;× BÑ BÄ4ÈÃ<Ó PÓQÐQä'Ð(\×(cÑ(cÐdh×dqÑdqÐswÓ(xÓyÐyàˆˆt‰ ؈
øô7ò CÜ"ØAóCð
Cûð Cús‚C2Ã2 D Ã; DÄD có—|SrPrrvs rrwz ReplaceOperation._on_undo_removegó€Øˆ
rcó—|SrPrrvs rryzReplaceOperation._on_undo_addjr‹rNr{rrrrˆrˆDs„ÙIòò@órrˆcóf—eZdZdZd„Zed„«Zed„«Zejd„«Zd„Z d„Z
y) Ú
MoveOperationz?Moves an object property or an array element to a new location.cóΗ t|jd|j«r|jd}n|j|jd«}|j |«\}} ||}|j|k(r|St|t«r&|jj|«r td«‚td|jddœ|j¬«j|«}td|j|dœ|j¬«j|«}|S#t$r}t d«‚d}~wwxYw#tt f$r}tt|««‚d}~wwxYw) NÚfromú.The operation does not contain a 'from' memberz*Cannot move values into their own childrenÚremove©ÚoprCr0Úadd©r”rCr,)r2rHr1rnrrlrorrfrFr Úcontainsrjr6r}rE©rIrNÚfrom_ptrrJrprqr,s rr6zMoveOperation.applyqsg€ð Bܘ$Ÿ.™.¨Ñ0°$×2BÑ2BÔCØŸ>™>¨&Ñ1‘à×+Ñ+¨D¯N©N¸6Ñ,BÓC�ð
 ×'Ñ'¨Ó,‰ ˆ�ð -ؘ4‘LˆEð
�<‰<˜8Ò #؈Jä �fœnÔ -Ø— ‘ ×%Ñ% hÔ/Ü#Ð$PÓQÐ Q䨨—N‘N 6Ñ*ñ
ð×'Ñ'ô)÷*/©¨s«ð ô
ØØ—M‘MØñ
ð×'Ñ'ô )÷*/©¨s«ð ð ˆ
øô;ò BÜ"Ø@óBð
Bûð Bûôœ*Ð%ò -Ü#¤C¨£GÓ,Ð ,ûð -ús0‚AD Á(D<Ä D9Ä) D4Ä4D9Ä<E$Å EÅE$cóz—|j|jd«}dj|jdd«S)Nr�r^r_)r1rHr`ra©rIr™s rÚ from_pathzMoveOperation.from_path–s5€à×#Ñ# D§N¡N°6Ñ$:Ó;ˆØ�x‰x˜Ÿ™ s¨Ð+Ó,Ð,rcó¬—|j|jd«} t|jd«S#t$r|jdcYSwxYw©Nr�r_)r1rHrcrarGr›s rÚfrom_keyzMoveOperation.from_key›sR€à×#Ñ# D§N¡N°6Ñ$:Ó;ˆð &Ü�x—~‘~ bÑ)Ó*Ð *øÜò &Ø—>‘> "Ñ%Ò %ð &ús 8¸AÁAcó¢—|j|jd«}t|«|jd<|j|jd<yrž)r1rHrfrarC)rIr,r™s rrŸzMoveOperation.from_key£s?€à×#Ñ# D§N¡N°6Ñ$:Ó;ˆÜ  ›Zˆ�‰�rÑØ!)§¡ˆ�‰�vÒrcóì—|j|k(r*|j|k\r|xjdz
c_n|dz}|j|k(r+|j|kDr|xjdz
c_|S|dz
}|Srt©rœrŸrCr!rvs rrwzMoveOperation._on_undo_remove©sl€Ø �>‰>˜TÒ !Ø�}‰} Ò#Ø—
’
 Ñ"–
à�q‘�Ø �9‰9˜Ò Ø�x‰x˜#Š~Ø—’˜A‘
•ðˆ
ð�q‘�؈
rcóì—|j|k(r*|j|kDr|xjdzc_n|dz}|j|k(r+|j|kDr|xjdzc_|S|dz
}|Srtr¢rvs rryzMoveOperation._on_undo_add¶sl€Ø �>‰>˜TÒ !Ø�}‰}˜sÒ"Ø—
’
 Ñ"–
à�q‘�Ø �9‰9˜Ò Ø�x‰x˜#Š~Ø—’˜A‘
•ðˆ
ð�q‘�؈
rN) rrrrr6rgrœrŸrhrwryrrrrŽrŽnsU„ÙIò#ðJñ-óð-ðñ&óð&ð‡_�_ñ/óð/ò
ó rrŽcó—eZdZdZd„Zy)Ú
TestOperationz!Test value by specified location.c
ó”— |jj|«\}}|€|}n|jj||«} |j d}||k7r1d}t |j|t|«|t|«««‚|S#t$r}t t |««‚d}~wwxYw#t$r}td«‚d}~wwxYw)Nr,rz0{0} ({1}) is not equal to tested value {2} ({3})) rFrlÚwalkrrrfrHrnrrmr„)rIrNrprqÚvalrJr,rrs rr6zTestOperation.applyÇsÚ€ð /ØŸ<™<×/Ñ/°Ó4‰LˆF�D؈|Ø‘à—l‘l×'Ñ'¨°Ó5�ð CØ—N‘N 7Ñ+ˆEð
�%Š<ØDˆCÜ% c§j¡j°´d¸3³iØ16¼¸U» ó'EóFð
Fðˆ
øô$ò /Ü%¤c¨"£gÓ.Ð .ûð /ûô
ò CÜ"ØAóCð
Cûð Cús/‚?B ÁB. B+ÂB&Â&B+Â. CÂ7 CÃCN©rrrrr6rrrr¥r¥Äs
„Ù+órr¥có—eZdZdZd„Zy)Ú
CopyOperationzA Copies an object property or an array element to a new location có”— |j|jd«}|j |«\}} t j ||«}td|j|dœ|j¬«j|«}|S#t$r}td«‚d}~wwxYw#ttf$r}tt|««‚d}~wwxYw)Nr�r‘r•r–r0)
r1rHrnrrlÚcopyÚdeepcopyrorrfr}rEr6r˜s rr6zCopyOperation.applyâs×€ð BØ×'Ñ'¨¯©°vÑ(>Ó?ˆHð
 ×'Ñ'¨Ó,‰ ˆ�ð -Ü—M‘M &¨¡,Ó/ˆEôØØ—M‘MØñ
ð×'Ñ'ô )÷*/©¨s«ð ð ˆ
øô!ò BÜ"Ø@óBð
Bûð Bûôœ*Ð%ò -Ü#¤C¨£GÓ,Ð ,ûð -ús.‚BµB B BÂBÂCÂ.CÃCNr©rrrr«r«ßs
„ÙKórr«c óæ—eZdZeej
«Zee«Ze e
e e e
eedœ«Z efd„Zd„Zd„ZeZd„Zd„Zd„Zd„Zed efd
„«Zed d efd „«Zdd
„Zed„«Zdd„Z d„Z!y )r4)r’r•ÚreplaceÚmoveÚtestr­cóš—||_||_|jD].}t|t«r t d«‚|j |«Œ0y)NzMDocument is expected to be sequence of operations, got a sequence of strings.)r8r1r2r3rÚ_get_operation)rIr8r1r”s rrKzJsonPatch.__init__2sW€ØˆŒ
Ø&ˆÔð —*‘*ò $ˆBô˜"œjÔ)Ü&ð(PóQðQð
× Ñ  Õ #ñ $rcó"—|j«S)zstr(self) -> self.to_string())Ú to_stringrSs rÚ__str__zJsonPatch.__str__Js€à�~‰~ÓÐrcó,—t|j«SrP)Úboolr8rSs rÚ__bool__zJsonPatch.__bool__Nó€Ü�D—J‘JÓÐrcó,—t|j«SrP)Úiterr8rSs rÚ__iter__zJsonPatch.__iter__Sr»rcó>—tt|j««SrP)rQÚtupleÚ_opsrSs rrTzJsonPatch.__hash__Vs€Ü”E˜$Ÿ)™)Ó$Ó%Ð%rcóV—t|t«sy|j|jk(SrV)r2r4rÁrWs rrYzJsonPatch.__eq__Ys"€Ü˜%¤Ô+ØØ�y‰y˜EŸJ™JÑ&Ð&rcó—||k( SrPrrWs rr[zJsonPatch.__ne__^r\rNcóF—|xs |j}||«}|||¬«S)a¨Creates JsonPatch instance from string source.
:param patch_str: JSON patch as raw string.
:type patch_str: str
:param loads: A function of one argument that loads a serialized
JSON string.
:type loads: function
:param pointer_cls: JSON pointer class to use.
:type pointer_cls: Type[JsonPointer]
:return: :class:`JsonPatch` instance.
r0)Ú json_loader)ÚclsÚ patch_strÚloadsr1rÅr8s rr5zJsonPatch.from_stringas)€ð Ò.˜sŸ™ˆ Ù˜IÓ&ˆÙ�5 kÔ2Ð2rTcó®—|xs |j}t||||¬«}|jdd||«t|j ««}|||¬«S)aCCreates JsonPatch instance based on comparison of two document
objects. Json patch would be created for `src` argument against `dst`
one.
:param src: Data source document object.
:type src: dict
:param dst: Data source document object.
:type dst: dict
:param dumps: A function of one argument that produces a serialized
JSON string.
:type dumps: function
:param pointer_cls: JSON pointer class to use.
:type pointer_cls: Type[JsonPointer]
:return: :class:`JsonPatch` instance.
>>> src = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
>>> dst = {'baz': 'qux', 'numbers': [1, 4, 7]}
>>> patch = JsonPatch.from_diff(src, dst)
>>> new = patch.apply(src)
>>> new == dst
True
r0ÚN)Ú json_dumperÚ DiffBuilderÚ_compare_valuesr&Úexecute) rÆr=r>Ú optimizationÚdumpsr1rËÚbuilderÚopss rr<zJsonPatch.from_diffusT€ð>Ò.˜sŸ™ˆ ܘc 3¨ ÀÔMˆØ×Ñ  D¨#¨sÔ3Ü�7—?‘?Ó$Ó%ˆÙ�3 KÔ0Ð0rcóF—|xs |j}||j«S)z!Returns patch set as JSON string.)rËr8)rIrÐrËs rr¶zJsonPatch.to_stringšs!€àÒ/˜t×/Ñ/ˆ Ù˜4Ÿ:™:Ó&Ð&rcóT—tt|j|j««SrP)rÀÚmapr´r8rSs rrÁzJsonPatch._opsŸs€ä”S˜×,Ñ,¨d¯j©jÓ9Ó:Ð:rcóx—|stj|«}|jD]}|j|«}Œ|S)a5Applies the patch to a given object.
:param obj: Document object.
:type obj: dict
:param in_place: Tweaks the way how patch would be applied - directly to
specified `obj` or to its copy.
:type in_place: bool
:return: Modified `obj`.