Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
jsonpointer.cpython-313.pyc103 linesDownload Raw Back to __pycache__
1�

2��j7)���SrSrSrSrSrSSKrSSKrSSKJrJ	r	 SSK3JrJr \
"5rSS	jr\4S4jrSr"SS
\5r"SS5r"SS5rSrSrg)z6Identify specific nodes in a JSON document (RFC 6901) u Stefan Kögl <stefan@skoegl.net>z3.1.1z2https://github.com/stefankoegl/python-json-pointerzModified BSD License�N)�Mapping�Sequence)�tee�chainc�<�[U5nURXU5$)a�Resolves a pointer against doc and sets the value of the target within doc.5 6With inplace set to true, doc is modified as long as pointer is not the7root.8 9>>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}}10 11>>> set_pointer(obj, '/foo/anArray/0/prop', 55) ==     {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}}12True13 14>>> set_pointer(obj, '/foo/yet another prop', 'added prop') ==     {'foo': {'another prop': {'baz': 'A string'}, 'yet another prop': 'added prop', 'anArray': [{'prop': 55}]}}15True16 17>>> obj = {'foo': {}}18>>> set_pointer(obj, '/foo/a%20b', 'x') ==     {'foo': {'a%20b': 'x' }}19True20)�JsonPointer�set)�doc�pointer�value�inplaces    �QD:\code\apps\devtools\python\user_packages\Python313\site-packages\jsonpointer.py�set_pointerr/s��,�'�"�G��;�;�s�7�+�+�c�:�[U5nURX5$)aResolves pointer against doc and returns the referenced object21 22>>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}, 'a%20b': 1, 'c d': 2}23 24>>> resolve_pointer(obj, '') == obj25True26 27>>> resolve_pointer(obj, '/foo') == obj['foo']28True29 30>>> resolve_pointer(obj, '/foo/another prop') == obj['foo']['another prop']31True32 33>>> resolve_pointer(obj, '/foo/another prop/baz') == obj['foo']['another prop']['baz']34True35 36>>> resolve_pointer(obj, '/foo/anArray/0') == obj['foo']['anArray'][0]37True38 39>>> resolve_pointer(obj, '/some/path', None) == None40True41 42>>> resolve_pointer(obj, '/a b', None) == None43True44 45>>> resolve_pointer(obj, '/a%20b') == 146True47 48>>> resolve_pointer(obj, '/c d') == 249True50 51>>> resolve_pointer(obj, '/c%20d', None) == None52True53)r�resolve)r54r�defaults   r�resolve_pointerrIs��H�'�"�G��?�?�3�(�(rc�D�[U5upUHn O [X5$)z�Transforms a list to a list of tuples of adjacent items55 56s -> (s0,s1), (s1,s2), (s2, s3), ...57 58>>> list(pairwise([]))59[]60 61>>> list(pairwise([1]))62[]63 64>>> list(pairwise([1, 2, 3, 4]))65[(1, 2), (2, 3), (3, 4)]66)r�zip)�iterable�a�b�_s    r�pairwiserqs&���x�=�D�A�
��
���q�9�rc��\rSrSrSrg)�JsonPointerException��N)�__name__�67__module__�__qualname__�__firstlineno__�__static_attributes__rrrrr�s��rrc�$�\rSrSrSrSrSrSrg)�	EndOfList�z)Result of accessing element "-" of a listc��Xlg�N��list_)�selfr+s  r�__init__�EndOfList.__init__�s���68rc�p�SRURR[UR5S9$)Nz{cls}({lst}))�cls�lst)�format�	__class__r �reprr+�r,s r�__repr__�EndOfList.__repr__�s2���$�$����)@�)@�)-�d�j�j�)9�%�;�	;rr*N)r r!r"r#�__doc__r-r6r$rrrr&r&�s��3��;rr&c���\rSrSrSr\R"S5r\R"S5rSr	Sr69\4Sjr\r
SSjr\S	5rS70rSrSrS
rSrSr\S5rSrSrSrSr\S5rSrg)r�z:A JSON Pointer that can reference parts of a JSON documentz0|[1-9][0-9]*$z(~[^01]|~$)c�F�URRU5nU(a([SRUR	555eURS5nUR
S5S:wa[S5eUVs/sHn[U5PM nnX0lgs snf)NzFound invalid escape {}�/r�zLocation must start with /)	�_RE_INVALID_ESCAPE�searchrr2�group�split�pop�unescape�parts)r,r�invalid_escaperD�parts     rr-�JsonPointer.__init__�s����0�0�7�7��@���&�'@�'G�'G��$�$�&�((�)�
)��
�
�c�"���9�9�Q�<�2��&�'C�D�D�,1�2�E�D��$��E��2��71��3s�Bc���UR(dUS4$URSSHnURX5nM U[RXRS54$)z>Resolves ptr until the last step, returns (sub-doc, last-step)N�����)rD�walkr�get_part�r,r72rFs   r�to_last�JsonPointer.to_last�sW���z�z���9���J�J�s��O�D��)�)�C�&�C�$��K�(�(��j�j��n�=�=�=rc��URHnURX5nM U$![a U[LaeUss $f=f)zBResolves the pointer against doc and returns the referenced object)rDrJr�_nothing)r,r73rrFs    rr�JsonPointer.resolve�sM���J�J�D�
#��i�i��*����74��
(�
#��h�&��"�N�	
#�s�(�A�Ac�$�[UR5S:XaU(a[S5eU$U(d[R"U5nURU5upE[
U[5(aUS:XaURU5 U$X$U'U$)zFResolve the pointer against the doc and replace the target with value.rzCannot set root in place�-)	�lenrDr�copy�deepcopyrM�75isinstancer�append)r,r76rr
�parentrFs      rr	�JsonPointer.set�s}���t�z�z�?�a���*�+E�F�F��L���-�-��$�C����c�*����f�h�'�'�D�C�K��M�M�%� ��77�!�4�L��78rc�J�[U[5(aU$[U[5(aNUS:XaU$[RR[
U55(d[SU-5e[U5$[US5(aU$[S[U5-5e)z)Returns the next step in the correct typerSz"'%s' is not a valid sequence index�__getitem__zXDocument '%s' does not support indexing, must be mapping/sequence or support __getitem__)rWrrr�_RE_ARRAY_INDEX�	fullmatch�strr�int�hasattr�type)r0r79rFs   rrK�JsonPointer.get_part�s����c�7�#�#��K�
��X�
&�
&��s�{����.�.�8�8��T��C�C�*�+O�RV�+V�W�W��t�9��
�S�-�
(�
(��K�'�(Y�[_�`c�[d�(e�f�
frc��UR$)zYReturns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b']�rDr5s r�	get_parts�JsonPointer.get_parts�s���z�z�rc�T�[RX5n[US5(dS[U5<35e[	U[805(aUS:Xa[
U5$X$X$![a [SU<S35ef=f![a [SU<SU<35ef=f)z6Walks one step in doc and returns the referenced part r\zinvalid document type rSzindex 'z' is out of boundszmember 'z' not found in )81rrKrarbrWrr&�82IndexErrorr�KeyErrorrLs   rrJ�JsonPointer.walk�s����#�#�C�.���s�M�*�*�U�$�s�)�,U�U�*��c�8�$�$��s�{� ��~�%�
T��y� �	T��9����
T�*�D�+R�S�S�
T���	T�&��c�'R�S�S�	T�s�"A+�'B	�+B�	B'c�`�URS[UR5UR:H$)�,Returns True if self contains the given ptr N)rDrT)r,�ptrs  r�contains�JsonPointer.containss$���z�z�/�3�s�y�y�>�*�c�i�i�7�7rc�$�URU5$)rm)ro)r,�items  r�__contains__�JsonPointer.__contains__s���}�}�T�"�"rc��[U[5(a
URnO-[U[5(a[U5RnOUn[R	[URU55$! [
S5e=f)zCReturns a new JsonPointer with the given suffix append to this ptr zInvalid suffix)rWrrDr_�83from_partsrr)r,�suffix�suffix_partss   r�join�JsonPointer.joinsn���f�k�*�*�!�<�<�L�
���
$�
$�&�v�.�4�4�L�!�L�	9��)�)�%��84�85�L�*I�J�J��	9�&�'7�8�8�s�(A:�:
Bc�$�URU5$r))ry)r,rws  r�__truediv__�JsonPointer.__truediv__'s���y�y�� � rc��URVs/sHn[U5PM nnSRSU55$s snf)zgReturns the string representation of the pointer86 87>>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1'88r=c3�,# �UH89nSU-v� M g7f�r<Nr��.0rFs  r�	<genexpr>�#JsonPointer.path.<locals>.<genexpr>1s���4�e�d�s�T�z�e���)rD�escapery)r,rFrDs   r�path�JsonPointer.path*s:��+/�*�*�5�*�$����*��5��w�w�4�e�4�4�4��6s�>c�`�[U[5(dgURUR:H$)z�Compares a pointer to another object90 91Pointers can be compared by comparing their strings (or splitted92strings), because no two different parts can point to the same93structure in an object (eg no different number representations)94F)rWrrD)r,�others  r�__eq__�JsonPointer.__eq__3s'���%��-�-���z�z�U�[�[�(�(rc�>�[[UR55$r))�hash�tuplerDr5s r�__hash__�JsonPointer.__hash__@s���E�$�*�*�%�&�&rc��UR$r))r�r5s r�__str__�JsonPointer.__str__Cs���y�y�rc�d�[U5RS-[UR5-S-$)N�(�))rbr r4r�r5s rr6�JsonPointer.__repr__Fs)���D�z�"�"�S�(�4��	�	�?�:�S�@�@rc��UVs/sHn[[U55PM nnU"SRSU555nU$s snf)z�Constructs a JsonPointer from a list of (unescaped) paths95 96>>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0'97True98r=c3�,# �UH99nSU-v� M g7fr�rr�s  rr��)JsonPointer.from_parts.<locals>.<genexpr>Qs���7���#��*��r�)r�r_ry)r0rDrFrns    rrv�JsonPointer.from_partsIsD��05�5�u�t���D�	�"�u��5��"�'�'�7��7�7�8���100��6s�AreN�T)r r!r"r#r8�re�compiler]r>r-rMrPr�getr	�classmethodrKrfrJrorsryr|�propertyr�r�r�r�r6rvr$rrrrr�s���D��j�j�!1�2�O����M�2��
�	>�$,�
��C��(�f��f�2�101T�08�#�9�!��5��5�)�'��A����rrc�F�URSS5RSS5$)N�~�~0r<�~1��replace��ss rr�r�Us ���9�9�S�$��'�'��T�2�2rc�F�URSS5RSS5$)Nr�r<r�r�r�r�s rrCrCYs ���9�9�T�3��'�'��c�2�2rr�)r8�102__author__�__version__�__website__�__license__rUr��collections.abcrr�	itertoolsrr�objectrPrrr�	Exceptionrr&rr�rCrrr�<module>r�su��>>�0�103���B��$���	�-� ��8��,�4+3�%)�P�(	�9�	�;�;�~�~�B3�3r
codekingpro/portable-devtools · Team Ai