Current File : //usr/lib/python3.6/site-packages/__pycache__/jsonpatch.cpython-36.opt-1.pyc |
3
d�GZ�_ �
@ s� d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl Z ddl
mZmZ dZ
dZyddlmZmZ W n( ek
r� ddlmZmZ eZY nX dZdZd Zd
Ze jd0kr�eefZG dd
� d
e�ZG dd� de�ZG dd� de�ZG dd� dee �Z!dd� Z"ej#ej$e"d�Z%d1dd�Z&dd� Z'G dd� de(�Z)G dd� de(�Z*G d d!� d!e*�Z+G d"d#� d#e*�Z,G d$d%� d%e*�Z-G d&d'� d'e*�Z.G d(d)� d)e*�Z/G d*d+� d+e*�Z0G d,d-� d-e(�Z1d.d/� Z2dS )2z Apply JSON-Patches (RFC 6902) � )�unicode_literalsN)�JsonPointer�JsonPointerException� )�MutableMapping�MutableSequenceu Stefan Kögl <[email protected]>z1.21z0https://github.com/stefankoegl/python-json-patchzModified BSD License� c @ s e Zd ZdZdS )�JsonPatchExceptionzBase Json Patch exceptionN)�__name__�
__module__�__qualname__�__doc__� r r �/usr/lib/python3.6/jsonpatch.pyr G s r c @ s e Zd ZdZdS )�InvalidJsonPatchz, Raised if an invalid JSON Patch is created N)r
r r r
r r r r r K s r c @ s e Zd ZdZdS )�JsonPatchConflicta Raised if patch could not be applied due to conflict situation such as:
- attempt to add object key then it already exists;
- attempt to operate with nonexistence object key;
- attempt to insert value to array at position beyond of it size;
- etc.
N)r
r r r
r r r r r O s r c @ s e Zd ZdZdS )�JsonPatchTestFailedz A Test operation failed N)r
r r r
r r r r r X s r c C s@ t jt�}x| D ]\}}|| j|� qW tdd� |j� D ��S )z'Convert duplicate keys values to lists.c s s. | ]&\}}|t |�d kr |d n|fV qdS )r r N)�len)�.0�key�valuesr r r � <genexpr>e s zmultidict.<locals>.<genexpr>)�collections�defaultdict�list�append�dict�items)Z
ordered_pairsZmdictr �valuer r r � multidict\ s
r )Zobject_pairs_hookFc C s* t |t�rtj|�}nt|�}|j| |�S )aO 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
: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
)�
isinstance�
basestring� JsonPatch�from_string�apply)�doc�patch�in_placer r r �apply_patcho s
r( c C s t j| |�S )a� Generates patch by comparing of 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
>>> 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
)r"