Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.6/site-packages/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.6/site-packages/__pycache__/jsonpatch.cpython-36.pyc

3

!��c�p�@s�dZddlmZddlZddlZddlZddlZddlZyddlm	Z	Wne
k
r`eZ	YnXddlm
Z
mZdZdZyddlmZmZWn(e
k
r�ddlmZmZeZYnXdZd	Zd
ZdZejd1kr�eefZGd
d�de�ZGdd�de�ZGdd�de�Z Gdd�dee!�Z"dd�Z#ej$ej%e#d�Z&de
fdd�Z'e
fdd�Z(Gdd�de)�Z*Gdd �d e*�Z+Gd!d"�d"e*�Z,Gd#d$�d$e*�Z-Gd%d&�d&e*�Z.Gd'd(�d(e*�Z/Gd)d*�d*e*�Z0Gd+d,�d,e)�Z1Gd-d.�d.e)�Z2d/d0�Z3dS)2z Apply JSON-Patches (RFC 6902) �)�unicode_literalsN)�MappingProxyType)�JsonPointer�JsonPointerException�)�MutableMapping�MutableSequenceu Stefan Kögl <stefan@skoegl.net>z1.32z0https://github.com/stefankoegl/python-json-patchzModified BSD License�c@seZdZdZdS)�JsonPatchExceptionzBase Json Patch exceptionN)�__name__�
__module__�__qualname__�__doc__�rr�./tmp/pip-build-_uu8ur7s/jsonpatch/jsonpatch.pyr
Jsr
c@seZdZdZdS)�InvalidJsonPatchz, Raised if an invalid JSON Patch is created N)rrr
rrrrrrNsrc@seZdZdZdS)�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.
    N)rrr
rrrrrrRsrc@seZdZdZdS)�JsonPatchTestFailedz A Test operation failed N)rrr
rrrrrr[srcCs@tjt�}x|D]\}}||j|�qWtdd�|j�D��S)z'Convert duplicate keys values to lists.css.|]&\}}|t|�dkr |dn|fVqdS)rrN)�len)�.0�key�valuesrrr�	<genexpr>hszmultidict.<locals>.<genexpr>)�collections�defaultdict�list�append�dict�items)Z
ordered_pairsZmdictr�valuerrr�	multidict_s
r )�object_pairs_hookFcCs2t|t�rtj||d�}nt||d�}|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_placer"rrr�apply_patchrs!
r+cCstj|||d�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
    )r")r%�	from_diff)�src�dstr"rrr�
make_patch�sr/c@sbeZdZdZefdd�Zdd�Zdd�Zdd	�Zd
d�Z	e
dd
��Ze
dd��Zej
dd��ZdS)�PatchOperationz'A single operation inside a JSON Patch.cCs�||_|jd�std��t|d|j�r@|dj|_|d|_nH|d|_y|j|j�|_Wn*tk
r�}ztd��WYdd}~XnX||_dS)N�pathz#Operation must have a 'path' memberzInvalid 'path')	r"�__contains__rr#r1�location�pointer�	TypeError�	operation)�selfr6r"�exrrr�__init__�s

zPatchOperation.__init__cCstd��dS)zGAbstract method that applies a patch operation to the specified object.z%should implement the patch operation.N)�NotImplementedError)r7�objrrrr'�szPatchOperation.applycCstt|jj���S)N)�hash�	frozensetr6r)r7rrr�__hash__�szPatchOperation.__hash__cCst|t�sdS|j|jkS)NF)r#r0r6)r7�otherrrr�__eq__�s
zPatchOperation.__eq__cCs
||kS)Nr)r7r?rrr�__ne__�szPatchOperation.__ne__cCsdj|jjdd��S)N�/r���)�joinr4�parts)r7rrrr1�szPatchOperation.pathcCs2yt|jjd�Stk
r,|jjdSXdS)NrrCrC)�intr4rE�
ValueError)r7rrrr�szPatchOperation.keycCs*t|�|jjd<|jj|_|j|jd<dS)Nrr1rC)�strr4rEr1r3r6)r7rrrrr�s
N)rrr
rrr9r'r>r@rA�propertyr1r�setterrrrrr0�sr0c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�RemoveOperationz/Removes an object property or an array element.cCsX|jj|�\}}y
||=Wn8ttfk
rR}zdj|�}t|��WYdd}~XnX|S)Nz(can't remove a non-existent object '{0}')r4�to_last�KeyError�
IndexError�formatr)r7r;�subobj�partr8�msgrrrr'�s

zRemoveOperation.applycCs0|j|kr,|j|kr$|jd7_n|d8}|S)Nr)r1r)r7r1rrrr�_on_undo_remove�s


zRemoveOperation._on_undo_removecCs0|j|kr,|j|kr$|jd8_n|d8}|S)Nr)r1r)r7r1rrrr�_on_undo_add�s


zRemoveOperation._on_undo_addN)rrr
rr'rSrTrrrrrK�s
rKc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�AddOperationz,Adds an object property or an array element.cCs�y|jd}Wn*tk
r8}ztd��WYdd}~XnX|jj|�\}}t|t�r�|dkrh|j|�q�|t|�ks||dkr�t	d��q�|j
||�nPt|t�r�|dkr�|}q�|||<n.|dkr�tdj
t|����nt	dj
|j|���|S)Nrz/The operation does not contain a 'value' member�-rzcan't insert outside of listzinvalid document type {0}z2unable to fully resolve json pointer {0}, part {1})r6rMrr4rLr#rrrr�insertrr5rO�typer3)r7r;rr8rPrQrrrr'	s(



zAddOperation.applycCs0|j|kr,|j|kr$|jd7_n|d7}|S)Nr)r1r)r7r1rrrrrS)s


zAddOperation._on_undo_removecCs0|j|kr,|j|kr$|jd8_n|d7}|S)Nr)r1r)r7r1rrrrrT1s


zAddOperation._on_undo_addN)rrr
rr'rSrTrrrrrUs rUc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ReplaceOperationz?Replaces an object property or an array element by a new value.cCs�y|jd}Wn*tk
r8}ztd��WYdd}~XnX|jj|�\}}|dkrV|S|dkrftd��t|t�r�|t|�ks�|dkr�td��nTt|t	�r�||kr�dj
|�}t|��n.|dkr�tdj
t|����ntd	j
|j
|���|||<|S)
Nrz/The operation does not contain a 'value' memberrVz7'path' with '-' can't be applied to 'replace' operationrzcan't replace outside of listz)can't replace a non-existent object '{0}'zinvalid document type {0}z2unable to fully resolve json pointer {0}, part {1})r6rMrr4rLr#rrrrrOr5rXr3)r7r;rr8rPrQrRrrrr'=s,




zReplaceOperation.applycCs|S)Nr)r7r1rrrrrS]sz ReplaceOperation._on_undo_removecCs|S)Nr)r7r1rrrrrT`szReplaceOperation._on_undo_addN)rrr
rr'rSrTrrrrrY:s rYc@sNeZdZdZdd�Zedd��Zedd��Zejdd��Zd	d
�Z	dd�Z
d
S)�
MoveOperationz?Moves an object property or an array element to a new location.c!Csy2t|jd|j�r |jd}n|j|jd�}Wn*tk
r\}ztd��WYdd}~XnX|j|�\}}y||}Wn2ttfk
r�}ztt|���WYdd}~XnX|j	|kr�|St|t
�r�|j	j|�r�td��td|jdd�|jd�j
|�}td|j|d�|jd�j
|�}|S)	N�fromz.The operation does not contain a 'from' memberz*Cannot move values into their own children�remove)�opr1)r"�add)r]r1r)r#r6r"rMrrLrNrrHr4r�containsrKr'rUr3)r7r;�from_ptrr8rPrQrrrrr'gs6

zMoveOperation.applycCs$|j|jd�}dj|jdd��S)Nr[rBrrC)r"r6rDrE)r7r`rrr�	from_path�szMoveOperation.from_pathcCs>|j|jd�}yt|jd�Stk
r8|jdSXdS)Nr[rrCrC)r"r6rFrEr5)r7r`rrr�from_key�s
zMoveOperation.from_keycCs.|j|jd�}t|�|jd<|j|jd<dS)Nr[rrC)r"r6rHrEr1)r7rr`rrrrb�scCs\|j|kr,|j|kr$|jd7_n|d8}|j|krX|j|krP|jd7_n|d7}|S)Nr)rarbr1r)r7r1rrrrrS�s



zMoveOperation._on_undo_removecCs\|j|kr,|j|kr$|jd8_n|d8}|j|krX|j|krP|jd8_n|d7}|S)Nr)rarbr1r)r7r1rrrrrT�s



zMoveOperation._on_undo_addN)rrr
rr'rIrarbrJrSrTrrrrrZds%
rZc@seZdZdZdd�ZdS)�
TestOperationz!Test value by specified location.c#Cs�y0|jj|�\}}|dkr |}n|jj||�}Wn.tk
r^}ztt|���WYdd}~XnXy|jd}Wn*tk
r�}ztd��WYdd}~XnX||kr�d}t|j	|t
|�|t
|����|S)Nrz/The operation does not contain a 'value' memberz0{0} ({1}) is not equal to tested value {2} ({3}))r4rL�walkrrrHr6rMrrOrX)r7r;rPrQ�valr8rrRrrrr'�s"zTestOperation.applyN)rrr
rr'rrrrrc�srcc@seZdZdZdd�ZdS)�
CopyOperationzA Copies an object property or an array element to a new location c!Cs�y|j|jd�}Wn*tk
r>}ztd��WYdd}~XnX|j|�\}}ytj||�}Wn2ttfk
r�}ztt	|���WYdd}~XnXt
d|j|d�|jd�j|�}|S)Nr[z.The operation does not contain a 'from' memberr^)r]r1r)r")
r"r6rMrrL�copy�deepcopyrNrrHrUr3r')r7r;r`r8rPrQrrrrr'�s zCopyOperation.applyN)rrr
rr'rrrrrf�srfc@s�eZdZeej�Zee�Ze	e
eee
eed��Zefdd�Zdd�Zdd�ZeZdd	�Zd
d�Zdd
�Zdd�Zedefdd��Zeddefdd��Zddd�Zedd��Zd dd�Z dd�Z!dS)!r%)r\r^�replace�move�testrgcCs*||_||_x|jD]}|j|�qWdS)N)r)r"�_get_operation)r7r)r"r]rrrr9(szJsonPatch.__init__cCs|j�S)zstr(self) -> self.to_string())�	to_string)r7rrr�__str__3szJsonPatch.__str__cCs
t|j�S)N)�boolr))r7rrr�__bool__7szJsonPatch.__bool__cCs
t|j�S)N)�iterr))r7rrr�__iter__<szJsonPatch.__iter__cCstt|j��S)N)r<�tuple�_ops)r7rrrr>?szJsonPatch.__hash__cCst|t�sdS|j|jkS)NF)r#r%rt)r7r?rrrr@Bs
zJsonPatch.__eq__cCs
||kS)Nr)r7r?rrrrAGszJsonPatch.__ne__NcCs|p|j}||�}|||d�S)a�Creates JsonPatch instance from string source.

        :param patch_str: JSON patch as raw string.
        :type patch_str: str

        :param loads: A function of one argument that loads a serialized
                      JSON string.
        :type loads: function

        :param pointer_cls: JSON pointer class to use.
        :type pointer_cls: Type[JsonPointer]

        :return: :class:`JsonPatch` instance.
        )r")�json_loader)�clsZ	patch_str�loadsr"rur)rrrr&Js
zJsonPatch.from_stringTc	CsB|p|j}t||||d�}|jdd||�t|j��}|||d�S)aCCreates JsonPatch instance based on comparison of two document
        objects. Json patch would be created for `src` argument against `dst`
        one.

        :param src: Data source document object.
        :type src: dict

        :param dst: Data source document object.
        :type dst: dict

        :param dumps: A function of one argument that produces a serialized
                      JSON string.
        :type dumps: function

        :param pointer_cls: JSON pointer class to use.
        :type pointer_cls: Type[JsonPointer]

        :return: :class:`JsonPatch` instance.

        >>> src = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
        >>> dst = {'baz': 'qux', 'numbers': [1, 4, 7]}
        >>> patch = JsonPatch.from_diff(src, dst)
        >>> new = patch.apply(src)
        >>> new == dst
        True
        )r"�N)�json_dumper�DiffBuilder�_compare_valuesr�execute)	rvr-r.�optimization�dumpsr"ryZbuilder�opsrrrr,^s

zJsonPatch.from_diffcCs|p|j}||j�S)z!Returns patch set as JSON string.)ryr))r7r~ryrrrrm�s
zJsonPatch.to_stringcCstt|j|j��S)N)rs�maprlr))r7rrrrt�szJsonPatch._opsFcCs,|stj|�}x|jD]}|j|�}qW|S)a5Applies the patch to a given object.

        :param obj: Document object.
        :type obj: dict

        :param in_place: Tweaks the way how patch would be applied - directly to
                         specified `obj` or to its copy.
        :type in_place: bool

        :return: Modified `obj`.
        )rgrhrtr')r7r;r*r6rrrr'�s


zJsonPatch.applycCsZd|krtd��|d}t|t�s*td��||jkrBtdj|���|j|}|||jd�S)Nr]z&Operation does not contain 'op' memberzOperation must be a stringzUnknown operation {0!r})r")rr#r$�
operationsrOr")r7r6r]rvrrrrl�s


zJsonPatch._get_operation)N)F)"rrr
�staticmethod�jsonr~ry�
_jsonloadsrurrKrUrYrZrcrfr�rr9rnrp�__nonzero__rrr>r@rA�classmethodr&r,rmrIrtr'rlrrrrr%�s4

0"

r%c@s�eZdZejefdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)rzcCsL||_||_iig|_ggg|_g|_}||_||_||dg|dd�<dS)N)r~r"�
index_storage�index_storage2�_DiffBuilder__root�src_doc�dst_doc)r7r�r�r~r"�rootrrrr9�s


zDiffBuilder.__init__cCst|t|�f}y:|j|}|j|�}|dkr6|g||<n||j|�Wn(tk
rn|j|j||f�YnXdS)N)rXr��getrr5r�)r7r�index�st�	typed_key�storage�storedrrr�store_index�s

zDiffBuilder.store_indexcCs�|t|�f}y |j|j|�}|r*|j�SWnZtk
r�|j|}x:tt|�ddd�D]"}||d|kr\|j|�dSq\WYnXdS)NrrrCrC)rXr�r��popr5r��ranger)r7rr�r�r�r��irrr�
take_index�s
zDiffBuilder.take_indexcCs,|j}|d}|||g|d<|d<|dS)Nrr)r�)r7r]r��lastrrrrW�szDiffBuilder.insertcCs*|\}}}||d<||d<g|dd�<dS)Nrrr)r7r�Z	link_prevZ	link_next�_rrrr\�s
zDiffBuilder.removeccs2|j}|d}x||k	r,|dV|d}qWdS)Nr�)r�)r7�startr��currrrr�	iter_from�s


zDiffBuilder.iter_fromccs2|j}|d}x||k	r,|dV|d}qWdS)Nrr�)r�)r7r�r�rrrrr�s


zDiffBuilder.__iter__ccs�|j}|d}x�||k	r�|d|k	r�|d|dd}}|j|jkr�t|�tkr�t|�tkr�td|j|jdd�|jd�jV|dd}q|djV|d}qWdS)Nrr�rir)r]r1r)r")r�r3rXrKrUrYr6r")r7r�r�Zop_firstZ	op_secondrrrr|�s"
zDiffBuilder.executec	Cs�|j|t�}|dk	r�|d}t|j�tkr\t|�tkr\x$|j|�D]}|j|j|j�|_qBW|j|�|j	t
||�kr�td|j	t
||�d�|jd�}|j
|�n4tdt
||�|d�|jd�}|j
|�}|j||t�dS)Nr�rj)r]r[r1)r"r^)r]r1r)r��
_ST_REMOVErXrrFr�rSr1r\r3�
_path_joinrZr"rWrUr��_ST_ADD)	r7r1r�itemr�r]�v�new_op�	new_indexrrr�_item_addeds*



zDiffBuilder._item_addedc
Cs�tdt||�d�|jd�}|j|t�}|j|�}|dk	r�|d}|jj|j�d}t	|�t
kr�x$|j|�D]}	|	j|j
|j�|_qjW|j|�|j|jkr�td|j|jd�|jd�}||d<q�|j|�n|j||t�dS)Nr\)r]r1)r"r�rrj)r]r[r1)rKr�r"r�r�rWr4rLr�rXrr�rTr1rr\r3rZr�r�)
r7r1rr�r�r�r�r]Z
added_itemr�rrr�
_item_removeds,




zDiffBuilder._item_removedcCs&|jtdt||�|d�|jd��dS)Nri)r]r1r)r")rWrYr�r")r7r1rr�rrr�_item_replaced?s
zDiffBuilder._item_replacedc	Cs�t|j��}t|j��}||}||}x"|D]}|j|t|�||�q.Wx"|D]}|j|t|�||�qRWx(||@D]}|j||||||�qzWdS)N)�set�keysr�rHr�r{)	r7r1r-r.Zsrc_keysZdst_keysZ
added_keysZremoved_keysrrrr�_compare_dictsFs

zDiffBuilder._compare_dictscCst|�t|�}}t||�}t||�}x�t|�D]�}||kr�||||}	}
|	|
krZq0q�t|	t�r�t|
t�r�|jt||�|	|
�q�t|	t�r�t|
t�r�|j	t||�|	|
�q�|j
|||	�|j|||
�q0||kr�|j
||||�q0|j||||�q0WdS)N)r�max�minr�r#rr�r�r�_compare_listsr�r�)r7r1r-r.Zlen_srcZlen_dst�max_lenZmin_lenr�old�newrrrr�Us&





zDiffBuilder._compare_listscCs~t|t�r*t|t�r*|jt||�||�nPt|t�rTt|t�rT|jt||�||�n&|j|�|j|�krldS|j|||�dS)N)r#rr�r�rr�r~r�)r7r1rr-r.rrrr{qs



	zDiffBuilder._compare_valuesN)rrr
r�r~rr9r�r�rWr\r�rrr|r�r�r�r�r�r{rrrrrz�s


!rzcCs,|dkr|S|dt|�jdd�jdd�S)NrB�~z~0z~1)rHri)r1rrrrr��sr�)r	r)4r�
__future__rrrg�	functoolsr��sys�typesr�ImportErrorrZjsonpointerrrr�r��collections.abcrr�unicoderH�
__author__�__version__Z__website__�__license__�version_info�bytesr$�	Exceptionr
rr�AssertionErrorrr �partialrwr�r+r/�objectr0rKrUrYrZrcrfr%rzr�rrrr�<module>!sX


	(64*VDX

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists