%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2379/lib/python3/dist-packages/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2379/lib/python3/dist-packages/__pycache__/jsonpatch.cpython-38.pyc

U

M
b[b�@s�dZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
dZdZzddl
mZmZWn(ek
r�ddlmZmZeZYnXdZdZd	Zd
Zejdkr�eefZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�dee�Zdd�Z ej!ej"e d�Z#d0dd�Z$dd�Z%Gdd�de&�Z'Gdd�de&�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(�Z-Gd*d+�d+e(�Z.Gd,d-�d-e&�Z/d.d/�Z0dS)1z Apply JSON-Patches (RFC 6902) �)�unicode_literalsN)�JsonPointer�JsonPointerException�)�MutableMapping�MutableSequenceu Stefan Kögl <stefan@skoegl.net>z1.22z0https://github.com/stefankoegl/python-json-patchzModified BSD License)�rc@seZdZdZdS)�JsonPatchExceptionzBase Json Patch exceptionN��__name__�
__module__�__qualname__�__doc__�rr�+/usr/lib/python3/dist-packages/jsonpatch.pyr	Esr	c@seZdZdZdS)�InvalidJsonPatchz, Raised if an invalid JSON Patch is created Nr
rrrrrIsrc@seZdZdZdS)�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.
    Nr
rrrrrMsrc@seZdZdZdS)�JsonPatchTestFailedz A Test operation failed Nr
rrrrrVsrcCs<t�t�}|D]\}}||�|�qtdd�|��D��S)z'Convert duplicate keys values to lists.css.|]&\}}|t|�dkr |dn|fVqdS)rrN)�len)�.0�key�valuesrrr�	<genexpr>as�zmultidict.<locals>.<genexpr>)�collections�defaultdict�list�append�dict�items)Z
ordered_pairsZmdictr�valuerrr�	multidictZs
�r )Zobject_pairs_hookFcCs*t|t�rt�|�}nt|�}|�||�S)aOApply 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_placerrr�apply_patchms
r)cCst�||�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#�	from_diff)�src�dstrrr�
make_patch�sr-c@s�eZdZdZdd�Zdd�Zdd�ZeZdd	�Zd
d�Z	dd
�Z
dd�Zedd��Z
eddd��Zdd�Zedd��Zd dd�Zdd�ZdS)!r#agA JSON Patch is a list of Patch Operations.

    >>> patch = JsonPatch([
    ...     {'op': 'add', 'path': '/foo', 'value': 'bar'},
    ...     {'op': 'add', 'path': '/baz', 'value': [1, 2, 3]},
    ...     {'op': 'remove', 'path': '/baz/1'},
    ...     {'op': 'test', 'path': '/baz', 'value': [1, 3]},
    ...     {'op': 'replace', 'path': '/baz/0', 'value': 42},
    ...     {'op': 'remove', 'path': '/baz/1'},
    ... ])
    >>> doc = {}
    >>> result = patch.apply(doc)
    >>> expected = {'foo': 'bar', 'baz': [42]}
    >>> result == expected
    True

    JsonPatch object is iterable, so you could easily access to each patch
    statement in loop:

    >>> lpatch = list(patch)
    >>> expected = {'op': 'add', 'path': '/foo', 'value': 'bar'}
    >>> lpatch[0] == expected
    True
    >>> lpatch == patch.patch
    True

    Also JsonPatch could be converted directly to :class:`bool` if it contains
    any operation statements:

    >>> bool(patch)
    True
    >>> bool(JsonPatch([]))
    False

    This behavior is very handy with :func:`make_patch` to write more readable
    code:

    >>> old = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
    >>> new = {'baz': 'qux', 'numbers': [1, 4, 7]}
    >>> patch = make_patch(old, new)
    >>> if patch:
    ...     # document have changed, do something useful
    ...     patch.apply(old)    #doctest: +ELLIPSIS
    {...}
    cCs||_ttttttd�|_dS)N)�remove�add�replace�moveZtest�copy)r'�RemoveOperation�AddOperation�ReplaceOperation�
MoveOperation�
TestOperation�
CopyOperation�
operations)�selfr'rrr�__init__�s�zJsonPatch.__init__cCs|��S)zstr(self) -> self.to_string())�	to_string�r:rrr�__str__�szJsonPatch.__str__cCs
t|j�S�N)�boolr'r=rrr�__bool__�szJsonPatch.__bool__cCs
t|j�Sr?)�iterr'r=rrr�__iter__�szJsonPatch.__iter__cCstt|j��Sr?)�hash�tuple�_opsr=rrr�__hash__�szJsonPatch.__hash__cCst|t�sdS|j|jkS�NF)r!r#rF�r:�otherrrr�__eq__�s
zJsonPatch.__eq__cCs
||kSr?rrIrrr�__ne__�szJsonPatch.__ne__cCst|�}||�S)z�Creates JsonPatch instance from string source.

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

        :return: :class:`JsonPatch` instance.
        )�
_jsonloads)�clsZ	patch_strr'rrrr$�s	zJsonPatch.from_stringTcCs*t�}|�dd||�t|���}||�S)aOCreates JsonPatch instance based on comparing 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

        :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
        �N)�DiffBuilder�_compare_valuesr�execute)rNr+r,�optimizationZbuilderZopsrrrr*szJsonPatch.from_diffcCst�|j�S)z!Returns patch set as JSON string.)�json�dumpsr'r=rrrr<szJsonPatch.to_stringcCstt|j|j��Sr?)rE�map�_get_operationr'r=rrrrF#szJsonPatch._opsFcCs(|st�|�}|jD]}|�|�}q|S)a/Applies the patch to given object.

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

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

        :return: Modified `obj`.
        )r2�deepcopyrFr%)r:�objr(�	operationrrrr%'s



zJsonPatch.applycCsTd|krtd��|d}t|t�s*td��||jkrBtd�|���|j|}||�S)N�opz&Operation does not contain 'op' memberzOperation must be a stringzUnknown operation {0!r})rr!r"r9�format)r:rZr[rNrrrrW<s


zJsonPatch._get_operationN)T)F)rrr
rr;r>rAZ__nonzero__rCrGrKrL�classmethodr$r*r<�propertyrFr%rWrrrrr#�s$-


r#c@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	dd
��Z
e	dd��Zejdd��ZdS)�PatchOperationz'A single operation inside a JSON Patch.cCsFt|dt�r&|dj|_|d|_n|d|_t|j�|_||_dS)N�path)r!rr`�location�pointerrZ)r:rZrrrr;Os
zPatchOperation.__init__cCstd��dS)zAAbstract method that applies patch operation to specified object.z!should implement patch operation.N)�NotImplementedError)r:rYrrrr%ZszPatchOperation.applycCstt|j����Sr?)rD�	frozensetrZrr=rrrrG^szPatchOperation.__hash__cCst|t�sdS|j|jkSrH)r!r_rZrIrrrrKas
zPatchOperation.__eq__cCs
||kSr?rrIrrrrLfszPatchOperation.__ne__cCsd�|jjdd��S)N�/���)�joinrb�partsr=rrrr`iszPatchOperation.pathcCs8zt|jjd�WStk
r2|jjdYSXdS)Nrf)�intrbrh�
ValueErrorr=rrrrmszPatchOperation.keycCs*t|�|jjd<|jj|_|j|jd<dS)Nrfr`)�strrbrhr`rarZ)r:rrrrrts
N)
rrr
rr;r%rGrKrLr^r`r�setterrrrrr_Ls

r_c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r3z/Removes an object property or an array element.c
CsX|j�|�\}}z
||=Wn8ttfk
rR}zd�|�}t|��W5d}~XYnX|S)Nz&can't remove non-existent object '{0}')rb�to_last�KeyError�
IndexErrorr\r)r:rY�subobj�part�ex�msgrrrr%~s

zRemoveOperation.applycCs0|j|kr,|j|kr$|jd7_n|d8}|S�Nr�r`r�r:r`rrrr�_on_undo_remove�s


zRemoveOperation._on_undo_removecCs0|j|kr,|j|kr$|jd8_n|d8}|Srtrurvrrr�_on_undo_add�s


zRemoveOperation._on_undo_addN�rrr
rr%rwrxrrrrr3{s
r3c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r4z,Adds an object property or an array element.c
Cs�z|jd}Wn*tk
r8}ztd��W5d}~XYnX|j�|�\}}t|t�r�|dkrh|�|�q�|t|�ks||dkr�t	d��q�|�
||�nPt|t�r�|dkr�|}q�|||<n.|dkr�td�
t|����nt	d�
|j|���|S)Nr�/The operation does not contain a 'value' member�-rzcan't insert outside of list�invalid document type {0}�2unable to fully resolve json pointer {0}, part {1})rZrnrrbrmr!rrrr�insertr�	TypeErrorr\�typera)r:rYrrrrprqrrrr%�s*�



zAddOperation.applycCs0|j|kr,|j|kr$|jd7_n|d7}|Srtrurvrrrrw�s


zAddOperation._on_undo_removecCs0|j|kr,|j|kr$|jd8_n|d7}|Srtrurvrrrrx�s


zAddOperation._on_undo_addNryrrrrr4�s r4c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r5z=Replaces an object property or an array element by new value.c
Cs�z|jd}Wn*tk
r8}ztd��W5d}~XYnX|j�|�\}}|dkrV|St|t�r~|t|�kst|dkr�td��nTt|t	�r�||kr�d�
|�}t|��n.|dkr�td�
t|����ntd�
|j
|���|||<|S)Nrrzrzcan't replace outside of listz'can't replace non-existent object '{0}'r|r})rZrnrrbrmr!rrrrr\rr�ra)r:rYrrrrprqrsrrrr%�s*�




zReplaceOperation.applycCs|Sr?rrvrrrrw�sz ReplaceOperation._on_undo_removecCs|Sr?rrvrrrrx�szReplaceOperation._on_undo_addNryrrrrr5�sr5c@sNeZdZdZdd�Zedd��Zedd��Zejdd��Zd	d
�Z	dd�Z
d
S)r6z=Moves an object property or an array element to new location.c
Cs
z.t|jdt�r|jd}nt|jd�}Wn*tk
rX}ztd��W5d}~XYnX|�|�\}}z||}Wn2ttfk
r�}ztt|���W5d}~XYnX|j	|kr�|St|t
�r�|j	�|�r�td��td|jdd���
|�}td|j|d���
|�}|S)N�from�.The operation does not contain a 'from' memberz(Cannot move values into its own childrenr.�r[r`r/�r[r`r)r!rZrrnrrmrorrkrbr�containsr3r%r4ra�r:rY�from_ptrrrrprqrrrrr%�sB�


�����zMoveOperation.applycCs"t|jd�}d�|jdd��S)Nr�rerf)rrZrgrh�r:r�rrr�	from_pathszMoveOperation.from_pathcCsBt|jd�}zt|jd�WStk
r<|jdYSXdS�Nr�rf)rrZrirhrr�rrr�from_key!s
zMoveOperation.from_keycCs,t|jd�}t|�|jd<|j|jd<dSr�)rrZrkrhr`)r:rr�rrrr�)scCs\|j|kr,|j|kr$|jd7_n|d8}|j|krX|j|krP|jd7_n|d7}|Srt�r�r�r`rrvrrrrw/s



zMoveOperation._on_undo_removecCs\|j|kr,|j|kr$|jd8_n|d8}|j|krX|j|krP|jd8_n|d7}|Srtr�rvrrrrx<s



zMoveOperation._on_undo_addN)rrr
rr%r^r�r�rlrwrxrrrrr6�s%



r6c@seZdZdZdd�ZdS)r7z!Test value by specified location.c
Cs�z0|j�|�\}}|dkr |}n|j�||�}Wn.tk
r^}ztt|���W5d}~XYnXz|jd}Wn*tk
r�}ztd��W5d}~XYnX||kr�d}t|�	|t
|�|t
|����|S)Nrrzz0{0} ({1}) is not equal to tested value {2} ({3}))rbrm�walkrrrkrZrnrr\r�)r:rYrprq�valrrrrsrrrr%Ms(��zTestOperation.applyN�rrr
rr%rrrrr7Jsr7c@seZdZdZdd�ZdS)r8zA Copies an object property or an array element to a new location c
Cs�zt|jd�}Wn*tk
r<}ztd��W5d}~XYnX|�|�\}}zt�||�}Wn2ttfk
r�}ztt	|���W5d}~XYnXt
d|j|d���|�}|S)Nr�r�r/r�)
rrZrnrrmr2rXrorrkr4rar%r�rrrr%hs&���zCopyOperation.applyNr�rrrrr8esr8c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)rPcCs4iig|_ggg|_g|_}||dg|dd�<dSr?)�
index_storage�index_storage2�_DiffBuilder__root)r:�rootrrrr;�s


zDiffBuilder.__init__cCshz:|j|}|�|�}|dkr*|g||<n||�|�Wn(tk
rb|j|�||f�YnXdSr?)r��getrrr�)r:r�index�st�storage�storedrrr�store_index�s

zDiffBuilder.store_indexcCs�z"|j|�|�}|r |��WSWn^tk
r�|j|}tt|�ddd�D]*}||d|krP|�|�dYSqPYnXdS)Nrrfr)r�r��poprr��ranger)r:rr�r�r��irrr�
take_index�s
zDiffBuilder.take_indexcCs,|j}|d}|||g|d<|d<|dS)Nrr�r�)r:r[r�Zlastrrrr~�szDiffBuilder.insertcCs*|\}}}||d<||d<g|dd�<dS)Nrrr)r:r�Z	link_prevZ	link_next�_rrrr.�s
zDiffBuilder.removeccs.|j}|d}||k	r*|dV|d}qdS�Nr�r�)r:�startr��currrrr�	iter_from�s

zDiffBuilder.iter_fromccs.|j}|d}||k	r*|dV|d}qdSr�r�)r:r�r�rrrrC�s

zDiffBuilder.__iter__ccs�|j}|d}||k	r�|d|k	r�|d|dd}}|j|jkr�t|�tkr�t|�tkr�td|j|jdd��jV|dd}q|djV|d}qdS)Nrr�r0rr�)r�rar�r3r4r5rZ)r:r�r�Zop_firstZ	op_secondrrrrR�s&
�
��zDiffBuilder.executec	Cs�|�|t�}|dk	r�|d}t|j�tkrL|�|�D]}|�|j|j�|_q4|�|�|j	t
||�kr�td|j	t
||�d��}|�|�n.t
dt
||�|d��}|�|�}|�||t�dS)Nr�r1�r[r�r`r/r�)r��
_ST_REMOVEr�rrir�rwr`r.ra�
_path_joinr6r~r4r��_ST_ADD)	r:r`r�itemr�r[�v�new_op�	new_indexrrr�_item_added�s*
��
zDiffBuilder._item_addedc	Cs�tdt||�d��}|�|t�}|�|�}|dk	r�|d}t|j�tkrj|�|�D]}|�	|j
|j�|_qR|�|�|j|jkr�t
d|j|jd��}||d<q�|�|�n|�||t�dS)Nr.r�r�r1r�)r3r�r�r�r~r�rrir�rxr`r.rar6r�r�)	r:r`rr�r�r�r�r[r�rrr�
_item_removed�s*�

�
zDiffBuilder._item_removedcCs |�tdt||�|d���dS)Nr0r�)r~r5r�)r:r`rr�rrr�_item_replaceds
�zDiffBuilder._item_replacedc	Cs�t|���}t|���}||}||}|D]}|�|t|�||�q,|D]}|�|t|�||�qL||@D]}|�||||||�qpdSr?)�set�keysr�rkr�rQ)	r:r`r+r,Zsrc_keysZdst_keysZ
added_keysZremoved_keysrrrr�_compare_dictsszDiffBuilder._compare_dictscCs�t|�t|�}}t||�}t||�}t|�D]�}||kr�||||}	}
|	|
krXq.q�t|	t�r�t|
t�r�|�t||�|	|
�q�t|	t�r�t|
t�r�|�	t||�|	|
�q�|�
|||	�|�|||
�q.||kr�|�
||||�q.|�||||�q.dSr?)r�max�minr�r!rr�r�r�_compare_listsr�r�)r:r`r+r,Zlen_srcZlen_dstZmax_lenZmin_lenr�old�newrrrr�s*


�
�zDiffBuilder._compare_listscCsr||krdSt|t�r6t|t�r6|�t||�||�n8t|t�r`t|t�r`|�t||�||�n|�|||�dSr?)r!rr�r�rr�r�)r:r`rr+r,rrrrQ3s
�
�zDiffBuilder._compare_valuesN)rrr
r;r�r�r~r.r�rCrRr�r�r�r�r�rQrrrrrP~srPcCs,|dkr|S|dt|��dd��dd�S)Nre�~z~0z~1)rkr0rurrrr�Csr�)F)1rZ
__future__rrr2�	functoolsrT�sysZjsonpointerrrr�r�Zcollections.abcrr�ImportErrorZunicoderk�
__author__�__version__Z__website__Z__license__�version_info�bytesr"�	Exceptionr	rr�AssertionErrorrr �partial�loadsrMr)r-�objectr#r_r3r4r5r6r7r8rPr�rrrr�<module>!sP

	
%&/4'VF

Zerion Mini Shell 1.0