Ë Ôš–u ò®�ãó(—dZddlmZdZdZdZdZ ddlmZe Z d„Z dd lmZmZdd lmZmZdd lZdd lZe«Zdd „Zefd„Zd„ZGd„de«ZGd„de«ZGd„de«Zd„Zd„Z y #e $re Zd „Z YŒ`wxYw#e $r dd lmZmZYŒjwxYw)z7 Identify specific nodes in a JSON document (RFC 6901) é)Úunicode_literalsu Stefan Kögl z2.4z2https://github.com/stefankoegl/python-json-pointerzModified BSD License)Úizipcó$—|jd«S)NÚraw_unicode_escape)Úencode©Úus ú0/usr/lib/python3.12/site-packages/jsonpointer.pyÚr /s€˜1Ÿ8™8Ð$8Ô9ócó—|S©N©rs r r r 2s€™1r )ÚMappingÚSequence)ÚteeÚchainNcó>—t|«}|j|||«S)a¼Resolves pointer against doc and sets the value of the target within doc. With inplace set to true, doc is modified as long as pointer is not the root. >>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}} >>> set_pointer(obj, '/foo/anArray/0/prop', 55) == {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}} True >>> set_pointer(obj, '/foo/yet another prop', 'added prop') == {'foo': {'another prop': {'baz': 'A string'}, 'yet another prop': 'added prop', 'anArray': [{'prop': 55}]}} True >>> obj = {'foo': {}} >>> set_pointer(obj, '/foo/a%20b', 'x') == {'foo': {'a%20b': 'x' }} True )Ú JsonPointerÚset)ÚdocÚpointerÚvalueÚinplaces r Ú set_pointerrAs!€ô,˜'Ó"€GØ �;‰;�s˜E 7Ó +Ð+r có<—t|«}|j||«S)aa Resolves pointer against doc and returns the referenced object >>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}, 'a%20b': 1, 'c d': 2} >>> resolve_pointer(obj, '') == obj True >>> resolve_pointer(obj, '/foo') == obj['foo'] True >>> resolve_pointer(obj, '/foo/another prop') == obj['foo']['another prop'] True >>> resolve_pointer(obj, '/foo/another prop/baz') == obj['foo']['another prop']['baz'] True >>> resolve_pointer(obj, '/foo/anArray/0') == obj['foo']['anArray'][0] True >>> resolve_pointer(obj, '/some/path', None) == None True >>> resolve_pointer(obj, '/a b', None) == None True >>> resolve_pointer(obj, '/a%20b') == 1 True >>> resolve_pointer(obj, '/c d') == 2 True >>> resolve_pointer(obj, '/c%20d', None) == None True )rÚresolve)rrÚdefaults r Úresolve_pointerr[s €ôH˜'Ó"€GØ �?‰?˜3 Ó (Ð(r cóF—t|«\}}|D]}nt||«S)zñ Transforms a list to a list of tuples of adjacent items s -> (s0,s1), (s1,s2), (s2, s3), ... >>> list(pairwise([])) [] >>> list(pairwise([1])) [] >>> list(pairwise([1, 2, 3, 4])) [(1, 2), (2, 3), (3, 4)] )rr)ÚiterableÚaÚbÚ_s r Úpairwiser%ƒs*€ô ˆx‹=�D€A€qÛ ˆÙ ðä ��1‹:Ðr có —eZdZy)ÚJsonPointerExceptionN)Ú__name__Ú __module__Ú __qualname__rr r r'r'—s„Ør r'có—eZdZdZd„Zd„Zy)Ú EndOfListz)Result of accessing element "-" of a listcó—||_yr)Úlist_)Úselfr.s r Ú__init__zEndOfList.__init__žs €Øˆ� r cóv—dj|jjt|j«¬«S)Nz {cls}({lst}))ÚclsÚlst)ÚformatÚ __class__r(Úreprr.©r/s r Ú__repr__zEndOfList.__repr__¡s2€Ø×$Ñ$¨¯©×)@Ñ)@Ü)-¨d¯j©jÓ)9ð%ó;ð ;r N)r(r)r*Ú__doc__r0r8rr r r,r,›s„Ù3òó;r r,cóê—eZdZdZej d«Zej d«Zd„Zd„Z e fd„Z e Z dd„Z ed„«Zd „Zd „Zd „Zd „Zd „Zd„ZeZed„«Zd„Zd„Zd„Zd„Zed„«Zy)rz:A JSON Pointer that can reference parts of a JSON documentz0|[1-9][0-9]*$z (~[^01]|~$)có6—|jj|«}|r(tdj|j «««‚|j d«}|j d«dk7r td«‚|D�cgc] }t|«‘Œ}}||_ycc}w)NzFound invalid escape {}Ú/rÚzLocation must start with /) Ú_RE_INVALID_ESCAPEÚsearchr'r4ÚgroupÚsplitÚpopÚunescapeÚparts)r/rÚinvalid_escaperDÚparts r r0zJsonPointer.__init__®s”€ð×0Ñ0×7Ñ7¸Ó@ˆÙ Ü&Ð'@×'GÑ'GØ×$Ñ$Ó&ó((ó)ð )ð— ‘ ˜cÓ"ˆØ �9‰9�Q‹<˜2Ò Ü&Ð'CÓDÐ Dá,1Ó2©E D”˜$•¨EˆÐ2؈� ùò3sÁ:Bcó¸—|js|dfS|jddD]}|j||«}Œ|tj||jd«fS)z>Resolves ptr until the last step, returns (sub-doc, last-step)Néÿÿÿÿ)rDÚwalkrÚget_part©r/rrFs r Úto_lastzJsonPointer.to_last½s[€ð�zŠzؘ�9Ð à—J‘J˜s “OˆDØ—)‘)˜C Ó&‰Cð$ð”K×(Ñ(¨¨d¯j©j¸©nÓ=Ð=Ð=r có†—|jD]} |j||«}Œ|S#t$r|tur‚|cYcSwxYw)zBResolves the pointer against doc and returns the referenced object)rDrIr'Ú_nothing)r/rrrFs r rzJsonPointer.resolveÈsO€ð—J”JˆDð #Ø—i‘i  TÓ*‘ððˆ øô (ò #ØœhÑ&Øà"”Nð  #ús‘'§A¿Acó—t|j«dk(r|r td«‚|S|stj|«}|j |«\}}t |t«r|dk(r|j|«|S|||<|S)zFResolve the pointer against the doc and replace the target with value.rzCannot set root in placeÚ-) ÚlenrDr'ÚcopyÚdeepcopyrLÚ isinstancerÚappend)r/rrrÚparentrFs r rzJsonPointer.setÙs~€ô ˆt�z‰z‹?˜aÒ ÙÜ*Ð+EÓFÐF؈LáÜ—-‘- Ó$ˆCàŸ™ cÓ*‰ˆ�ä �fœhÔ '¨D°CªKØ �M‰M˜%Ô ðˆ ð!ˆF�4‰Làˆ r có —t|t«r|St|t«rH|dk(r|Stjj t |««std|z«‚t|«St|d«r|Stdt|«z«‚)z)Returns the next step in the correct typerPz"'%s' is not a valid sequence indexÚ __getitem__zXDocument '%s' does not support indexing, must be mapping/sequence or support __getitem__) rTrrrÚ_RE_ARRAY_INDEXÚmatchÚstrr'ÚintÚhasattrÚtype)r2rrFs r rJzJsonPointer.get_partís”€ô �cœ7Ô #؈Kä ˜œXÔ &à�sŠ{Ø� ä×.Ñ.×4Ñ4´S¸³YÔ?Ü*Ð+OÐRVÑ+VÓWÐWä�t“9Ð ä �S˜-Ô (ðˆKô'ð(YÜ[_Ð`cÓ[dñ(eófð fr có—|jS)zYReturns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b'])rDr7s r Ú get_partszJsonPointer.get_partss€ð�z‰zÐr có8—tj||«}t|d«sJdt|«›�«‚t |t «r|dk(r t |«S ||S ||S#t$rtd|›d�«‚wxYw#t$rtd|›d|›�«‚wxYw)z7 Walks one step in doc and returns the referenced part rXzinvalid document type rPzindex 'z' is out of boundszmember 'z' not found in ) rrJr]r^rTrr,Ú IndexErrorr'ÚKeyErrorrKs r rIzJsonPointer.walk s°€ô×#Ñ# C¨Ó.ˆä�s˜MÔ*ÑUÌ$ÈsÌ)Ð,UÓUÐ*ä �cœ8Ô $Ø�sŠ{Ü  “~Ð%ð Uؘ4‘yÐ ð  TØ�t‘9Ð øô ò UÝ*ÊDÐ+SÓTÐTð Uûôò TÝ&ÊÉcÐ'RÓSÐ Sð TúsÁA"ÁA>Á"A;Á>Bcó`—|jdt|j«|jk(S)ú- Returns True if self contains the given ptr N)rDrQ)r/Úptrs r ÚcontainszJsonPointer.contains&s$€à�z‰z˜/œ3˜sŸy™y›>Ð*¨c¯i©iÑ7Ð7r có$—|j|«S)re)rg)r/Úitems r Ú __contains__zJsonPointer.__contains__*s€à�}‰}˜TÓ"Ð"r có—t|t«r |j}n(t|t«rt|«j}n|} tj t |j|««S#t d«‚xYw)zD Returns a new JsonPointer with the given suffix append to this ptr zInvalid suffix)rTrrDr[Ú from_partsrr')r/ÚsuffixÚ suffix_partss r ÚjoinzJsonPointer.join.sh€ä �fœkÔ *Ø!Ÿ<™<‰LÜ ˜¤Ô $Ü& vÓ.×4Ñ4‰Là!ˆLð 9Ü×)Ñ)¬%°· ± ¸LÓ*IÓJÐ Jøð 9Ü&Ð'7Ó8Ð 8ús Á(A0Á0 A=có$—|j|«Sr)ro)r/rms r Ú __truediv__zJsonPointer.__truediv__;s€Ø�y‰y˜Ó Ð r có€—|jD�cgc] }t|«‘Œ}}djd„|D««Scc}w)zwReturns the string representation of the pointer >>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1' r=c3ó&K—|] }d|z–—Œ y­w©r<Nr©Ú.0rFs r Ú z#JsonPointer.path..Fsèø€Ð4©e d�s˜T•z©eùó‚)rDÚescapero)r/rFrDs r ÚpathzJsonPointer.path?s:€ð +/¯*ª*Ó5©* $”˜•¨*ˆÐ5Ø�w‰wÑ4©eÓ4Ó4Ð4ùò6s�;cóV—t|t«sy|j|jk(S)aCompares a pointer to another object Pointers can be compared by comparing their strings (or splitted strings), because no two different parts can point to the same structure in an object (eg no different number representations) F)rTrrD)r/Úothers r Ú__eq__zJsonPointer.__eq__Hs$€ô˜%¤Ô-Øà�z‰z˜UŸ[™[Ñ(Ð(r có>—tt|j««Sr)ÚhashÚtuplerDr7s r Ú__hash__zJsonPointer.__hash__Us€Ü”E˜$Ÿ*™*Ó%Ó&Ð&r có,—t|j«Sr)Ú encode_strrzr7s r Ú__str__zJsonPointer.__str__Xs€Ü˜$Ÿ)™)Ó$Ð$r có8—dt|j«zdzS)Nz JsonPointer(Ú))r6rzr7s r r8zJsonPointer.__repr__[s€Ø¤ T§Y¡Y£Ñ/°#Ñ5Ð5r cóŽ—|D�cgc]}tt|««‘Œ}}|djd„|D«««}|Scc}w)zœConstructs a JsonPointer from a list of (unescaped) paths >>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0' True r=c3ó&K—|] }d|z–—Œ y­wrtrrus r rwz)JsonPointer.from_parts..fsèø€Ð7±¨˜# �*±ùrx)ryr[ro)r2rDrFrfs r rlzJsonPointer.from_parts^sD€ñ05Ó5©u t”œ˜D› Õ"¨uˆÐ5Ù�"—'‘'Ñ7±Ó7Ó7Ó8ˆØˆ ùò6s…AN©T)r(r)r*r9ÚreÚcompilerYr>r0rLrNrÚgetrÚ classmethodrJr`rIrgrjrorqÚ__div__Úpropertyrzr}r�r„r8rlrr r rr¦s½„ÙDð!�b—j‘jÐ!1Ó2€OØ#˜Ÿ™ MÓ2Ðò ò >ð$,ó ð €Cóð(ñfóðfò2ò Tò28ò#ò 9ò!à€Gà ñ5óð5ò )ò'ò%ò6ðñóñr rcóF—|jdd«jdd«S)NÚ~ú~0r<ú~1©Úreplace©Úss r ryryjs €Ø �9‰9�S˜$Ó × 'Ñ '¨¨TÓ 2Ð2r cóF—|jdd«jdd«S)Nr“r<r’r‘r”r–s r rCrCms €Ø �9‰9�T˜3Ó × 'Ñ '¨¨cÓ 2Ð2r r‰)!r9Ú __future__rÚ __author__Ú __version__Ú __website__Ú __license__Ú itertoolsrÚunicoder[rƒÚ ImportErrorÚzipÚcollections.abcrrÚ collectionsrrrŠrRÚobjectrNrrr%Ú Exceptionr'r,rryrCrr r Úr¦sÊðñB>å'ð0€ Ø€ ØB€ Ø$€ ðÝØ €CÙ9€Jð .ß1÷!Û Û ñ ‹8€ó,ð4+3ó%)òPô( ˜9ô ô;�ô;ôA�&ôAòH3ó3øð{ òØ €DÙ‚Jðûð ò.ß-Ñ-ð.ús"’ A1žBÁ1 A>Á=A> BÂB