� M�gi)����dZdZdZdZdZddlZddlZddlmZm Z ddl m Z m Z e ��Zdd �Zefd �Zd �ZGd �de��ZGd�de ��ZGd�de ��Zd�Zd�ZdS)z7 Identify specific nodes in a JSON document (RFC 6901) u Stefan Kögl <stefan@skoegl.net>z3.0.0z2https://github.com/stefankoegl/python-json-pointerzModified BSD License�N)�Mapping�Sequence)�tee�chainTc�N�t|��}|�|||��S)a�Resolves a 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 �[/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/jsonpointer.py� set_pointerr1s'��,�'�"�"�G� �;�;�s�E�7� +� +�+�c�L�t|��}|�||��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)r r �defaults r�resolve_pointerrKs&��H�'�"�"�G� �?�?�3�� (� (�(rc�P�t|��\}}|D]}t||��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)] )r�zip)�iterable�a�b�_s r�pairwiserss3�� �x�=�=�D�A�q� ���� � �q�!�9�9�rc��eZdZdS)�JsonPointerExceptionN)�__name__� __module__� __qualname__�rrrr�s�������Drrc��eZdZdZd�Zd�ZdS)� EndOfListz)Result of accessing element "-" of a listc��||_dS�N)�list_)�selfr&s r�__init__zEndOfList.__init__�s ���� � � rc�h�d�|jjt|j�����S)Nz {cls}({lst}))�cls�lst)�format� __class__r�reprr&�r's r�__repr__zEndOfList.__repr__�s3���$�$���)@�)-�d�j�)9�)9�%�;�;� ;rN)rrr �__doc__r(r0r!rrr#r#�s8������3�3����;�;�;�;�;rr#c���eZdZdZejd��Zejd��Zd�Zd�Z e fd�Z e Z dd�Z ed ���Zd �Zd �Zd �Zd �Zd�Zd�Zed���Zd�Zd�Zd�Zd�Zed���ZdS)rz:A JSON Pointer that can reference parts of a JSON documentz0|[1-9][0-9]*$z (~[^01]|~$)c�F�|j�|��}|r4td�|��������|�d��}|�d��dkrtd���d�|D��}||_dS)NzFound invalid escape {}�/r�zLocation must start with /c�,�g|]}t|����Sr!)�unescape��.0�parts r� <listcomp>z(JsonPointer.__init__.<locals>.<listcomp>�s��2�2�2�D��$���2�2�2r)�_RE_INVALID_ESCAPE�searchrr,�group�split�pop�parts)r'r �invalid_escaperAs rr(zJsonPointer.__init__�s����0�7�7��@�@�� � )�&�'@�'G�'G��$�$�&�&�((�((�)�)� )�� � �c�"�"�� �9�9�Q�<�<�2� � �&�'C�D�D� D�2�2�E�2�2�2���� � � rc��|js|dfS|jdd�D]}|�||��}�|t�||jd��fS)z>Resolves ptr until the last step, returns (sub-doc, last-step)N�����)rA�walkr�get_part�r'r r:s r�to_lastzJsonPointer.to_last�sg���z� ���9� ��J�s��s�O� '� '�D��)�)�C��&�&�C�C��K�(�(��d�j��n�=�=�=�=rc��|jD]7} |�||��}�#t$r|tur�|cYcSwxYw|S)zBResolves the pointer against doc and returns the referenced object)rArEr�_nothing)r'r rr:s rrzJsonPointer.resolve�sl���J� #� #�D� #��i�i��T�*�*����'� #� #� #��h�&�&��"�N�N�N�N�N�  #���� � s �"�=�=Tc�$�t|j��dkr|rtd���|S|stj|��}|�|��\}}t |t��r|dkr|�|��n|||<|S)zFResolve the pointer against the doc and replace the target with value.rzCannot set root in place�-) �lenrAr�copy�deepcopyrH� isinstancer�append)r'r r r �parentr:s rr zJsonPointer.set�s��� �t�z�?�?�a� � �� G�*�+E�F�F�F��L�� %��-��$�$�C����c�*�*���� �f�h� '� '� !�D�C�K�K� �M�M�%� � � � � �F�4�L�� rc�f�t|t��r|St|t��rU|dkr|Stj�t |����std|z���t|��St|d��r|Stdt|��z���)z)Returns the next step in the correct typerLz"'%s' is not a valid sequence index� __getitem__zXDocument '%s' does not support indexing, must be mapping/sequence or support __getitem__) rPrrr�_RE_ARRAY_INDEX�match�strr�int�hasattr�type)r*r r:s rrFzJsonPointer.get_part�s��� �c�7� #� #� f��K� ��X� &� &� f��s�{�{�� ��.�4�4�S��Y�Y�?�?� X�*�+O�RV�+V�W�W�W��t�9�9� � �S�-� (� (� f��K�'�(Y�[_�`c�[d�[d�(e�f�f� frc��|jS)zYReturns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b'])rAr/s r� get_partszJsonPointer.get_parts�s ���z�rc��t�||��}t|d��sJdt|�������t |t ��r?|dkrt |��S ||S#t$rtd|�d����wxYw ||S#t$rtd|�d|�����wxYw)z7 Walks one step in doc and returns the referenced part rTzinvalid document type rLzindex 'z' is out of boundszmember 'z' not found in ) rrFrYrZrPrr#� IndexErrorr�KeyErrorrGs rrEzJsonPointer.walk�s����#�#�C��.�.���s�M�*�*�U�U�U�$�s�)�)�)�,U�U�U�*� �c�8� $� $� T��s�{�{� ��~�~�%� T��4�y� ��� T� T� T�*�*�D�D�D�+R�S�S�S� T���� T��t�9� ��� T� T� T�&�&����c�c�'R�S�S� S� T���s�1A9�9B�B#�# Cc�V�|jdt|j���|jkS)�- Returns True if self contains the given ptr N)rArM)r'�ptrs r�containszJsonPointer.containss"���z�/�3�s�y�>�>�/�*�c�i�7�7rc�,�|�|��S)ra)rc)r'�items r� __contains__zJsonPointer.__contains__s���}�}�T�"�"�"rc��t|t��r|j}n,t|t��rt|��j}n|} t�t |j|����S#t d���xYw)zD Returns a new JsonPointer with the given suffix append to this ptr zInvalid suffix)rPrrArW� from_partsrr)r'�suffix� suffix_partss r�joinzJsonPointer.joins��� �f�k� *� *� "�!�<�L�L� ��� $� $� "�&�v�.�.�4�L�L�!�L� 9��)�)�%�� �L�*I�*I�J�J� J�� 9�&�'7�8�8� 8���s � ,A8�8B c�,�|�|��Sr%�rk)r'ris r� __truediv__zJsonPointer.__truediv__)s���y�y�� � � rc�b�d�|jD��}d�d�|D����S)zwReturns the string representation of the pointer >>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1' c�,�g|]}t|����Sr!)�escaper8s rr;z$JsonPointer.path.<locals>.<listcomp>2s��5�5�5�$�����5�5�5rr5c3� K�|] }d|zV�� dS�r4Nr!r8s r� <genexpr>z#JsonPointer.path.<locals>.<genexpr>3s&����4�4�d�s�T�z�4�4�4�4�4�4r)rArk)r'rAs r�pathzJsonPointer.path,s:�� 6�5�$�*�5�5�5���w�w�4�4�e�4�4�4�4�4�4rc�P�t|t��sdS|j|jkS)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)rPrrA)r'�others r�__eq__zJsonPointer.__eq__5s*���%��-�-� ��5��z�U�[�(�(rc�D�tt|j����Sr%)�hash�tuplerAr/s r�__hash__zJsonPointer.__hash__Bs���E�$�*�%�%�&�&�&rc��|jSr%)rur/s r�__str__zJsonPointer.__str__Es ���y�rc�`�t|��jdzt|j��zdzS)N�(�))rZrr.rur/s rr0zJsonPointer.__repr__Hs(���D�z�z�"�S�(�4�� �?�?�:�S�@�@rc�n�d�|D��}|d�d�|D������}|S)z�Constructs a JsonPointer from a list of (unescaped) paths >>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0' True c�F�g|]}tt|������Sr!)rqrWr8s rr;z*JsonPointer.from_parts.<locals>.<listcomp>Rs&��5�5�5�t���D� � �"�"�5�5�5rr5c3� K�|] }d|zV�� dSrsr!r8s rrtz)JsonPointer.from_parts.<locals>.<genexpr>Ss&����7�7��#��*�7�7�7�7�7�7rrm)r*rArbs rrhzJsonPointer.from_partsKsF��6�5�u�5�5�5���c�"�'�'�7�7��7�7�7�7�7�8�8��� rN�T)rrr r1�re�compilerUr<r(rHrJr�getr � classmethodrFr\rErcrfrkrn�propertyrurxr|r~r0rhr!rrrr�s�������D�D�!�b�j�!1�2�2�O�#���M�2�2�� � � � >� >� >�$,� � � � � �C�����(�f�f��[�f�2��� T�T�T�08�8�8�#�#�#� 9� 9� 9�!�!�!��5�5��X�5� )� )� )�'�'�'����A�A�A�����[���rrc�V�|�dd���dd��S)N�~�~0r4�~1��replace��ss rrqrqWs&�� �9�9�S�$� � � '� '��T� 2� 2�2rc�V�|�dd���dd��S)Nr�r4r�r�r�r�s rr7r7[s&�� �9�9�T�3� � � '� '��c� 2� 2�2rr�)r1� __author__� __version__� __website__� __license__rNr��collections.abcrr� itertoolsrr�objectrJrrr� Exceptionrr#rrqr7r!rr�<module>r�s]��B>�=�0� �� �B� �$� � � � � � � � � �-�-�-�-�-�-�-�-� � � � � � � � � �6�8�8��,�,�,�,�4+3�%)�%)�%)�%)�P���( � � � � �9� � � �;�;�;�;�;��;�;�;�~�~�~�~�~�&�~�~�~�B3�3�3�3�3�3�3�3r
Memory