Current File : /home/inlingua/miniconda3/lib/python3.1/site-packages/__pycache__/jsonpatch.cpython-312.pyc |
�
6�0fRt � � � d Z ddlmZ ddlZddlZddlZddlZddlZ ddlm Z ddlmZ ddlmZmZ dZdZ ddlmZmZ d Zd
ZdZdZej6 d
k\ reefZ G d� de� Z G d� de� Z G d� de� Z! G d� dee"� Z#d� Z$ ejJ ejL e$�� Z'defd�Z(efd�Z) G d� de*� Z+ G d� de+� Z, G d� d e+� Z- G d!� d"e+� Z. G d#� d$e+� Z/ G d%� d&e+� Z0 G d'� d(e+� Z1 G d)� d*e*� Z2 G d+� d,e*� Z3d-� Z4y# e
$ r
ddlm Z Y ��w xY w# e
$ r e
ZY ��w xY w# e
$ r ddlmZmZ eZY ��
w xY w).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)� r c � � e Zd ZdZy)�JsonPatchExceptionzBase Json Patch exceptionN��__name__�
__module__�__qualname__�__doc__� � �)lib/python3.12/site-packages/jsonpatch.pyr
r
P � � �#r r
c � � e Zd ZdZy)�InvalidJsonPatchz, Raised if an invalid JSON Patch is created Nr r r r r r T s � �6r r c � � e Zd ZdZy)�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.
Nr r r r r r X s � �r r c � � e Zd ZdZy)�JsonPatchTestFailedz A Test operation failed Nr r r r r r a r r r c � � t j t � }| D ] \ }}|| j |� � t d� |j � D � � S )z'Convert duplicate keys values to lists.c 3 �P K � | ] \ }}|t |� d k( r|d n|f�� � y�w)r r N)�len)�.0�key�valuess r � <genexpr>zmultidict.<locals>.<genexpr>l s4 � �� � �
�C��
�3�v�;�!�+�f�Q�i��8��s �$&)�collections�defaultdict�list�append�dict�items)�
ordered_pairs�mdictr! �values r � multidictr- e s] � �
�#�#�D�)�E�#� !�
��U�
�c�
���%� �!� � � !�;�;�=�� � r )�object_pairs_hookFc � � t |t � rt j ||�� }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_placer1 s r �apply_patchr: x sA � �B �%��$��%�%�e��%�E���%�[�9���;�;�s�H�%�%r c �2 � t j | ||�� 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�dstr1 s r �
make_patchr? � s � �* ���s�C�[��A�Ar c �v � e Zd ZdZefd�Zd� Zd� Zd� Zd� Z e
d� � Ze
d� � Zej d � � Zy
)�PatchOperationz'A single operation inside a JSON Patch.c �d � || _ |j d� st d� �t |d | j � r&|d j | _ |d | _ || _ y |d | _ | j | j
� | _ || _ y # t $ r}t d� �d }~ww xY w)N�pathz#Operation must have a 'path' memberzInvalid 'path') r1 �__contains__r r2 rC �location�pointer� TypeError� operation)�selfrH r1 �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 � � t d� �)zGAbstract method that applies a patch operation to the specified object.z%should implement the patch operation.)�NotImplementedError)rI �objs r r6 zPatchOperation.apply� s � �!�"I�J�Jr c �Z � t t | j j � � � S �N)�hash� frozensetrH r) �rI s r �__hash__zPatchOperation.__hash__� s � ��I�d�n�n�2�2�4�5�6�6r c �V � t |t � sy| j |j k( S �NF)r2 rA rH �rI �others r �__eq__zPatchOperation.__eq__� s"