HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/__pycache__/jsonpatch.cpython-39.pyc
a

@1^3d�@s�dZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
dZdZzddl
mZmZWn&ey�ddlmZmZeZYn0dZdZd	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.25z0https://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 )�object_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�move�test�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�SrA)�iterr(r?rrr�__iter__�szJsonPatch.__iter__cCstt|j��SrA)�hash�tuple�_opsr?rrr�__hash__�szJsonPatch.__hash__cCst|t�sdS|j|jkS�NF)r"r$rH�r<�otherrrr�__eq__�s
zJsonPatch.__eq__cCs
||kSrArrKrrr�__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)rPr,r-�optimization�builder�opsrrrr+szJsonPatch.from_diffcCst�|j�S)z!Returns patch set as JSON string.)�json�dumpsr(r?rrrr>szJsonPatch.to_stringcCstt|j|j��SrA)rG�map�_get_operationr(r?rrrrH#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`.
        )r4�deepcopyrHr&)r<�objr)�	operationrrrr&'s



zJsonPatch.applycCsTd|vrtd��|d}t|t�s*td��||jvrBtd�|���|j|}||�S)N�opz&Operation does not contain 'op' memberzOperation must be a stringzUnknown operation {0!r})rr"r#r;�format)r<r^r_rPrrrr[<s


zJsonPatch._get_operationN)T)F)rrr
rr=r@rC�__nonzero__rErIrMrN�classmethodr%r+r>�propertyrHr&r[rrrrr$�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"rre�location�pointerr^)r<r^rrrr=Os
zPatchOperation.__init__cCstd��dS)zAAbstract method that applies patch operation to specified object.z!should implement patch operation.N)�NotImplementedError)r<r]rrrr&ZszPatchOperation.applycCstt|j����SrA)rF�	frozensetr^rr?rrrrI^szPatchOperation.__hash__cCst|t�sdS|j|jkSrJ)r"rdr^rKrrrrMas
zPatchOperation.__eq__cCs
||kSrArrKrrrrNfszPatchOperation.__ne__cCsd�|jjdd��S)N�/���)�joinrg�partsr?rrrreiszPatchOperation.pathcCs6zt|jjd�WSty0|jjdYS0dS)Nrk)�intrgrm�
ValueErrorr?rrrrmszPatchOperation.keycCs*t|�|jjd<|jj|_|j|jd<dS)Nrkre)�strrgrmrerfr^)r<rrrrrts
N)
rrr
rr=r&rIrMrNrcrer�setterrrrrrdLs

rdc@s(eZdZdZdd�Zdd�Zdd�ZdS)	r5z/Removes an object property or an array element.c
CsZ|j�|�\}}z
||=Wn:ttfyT}zd�|�}t|��WYd}~n
d}~00|S)Nz&can't remove non-existent object '{0}')rg�to_last�KeyError�
IndexErrorr`r)r<r]�subobj�part�ex�msgrrrr&~s

zRemoveOperation.applycCs0|j|kr,|j|kr$|jd7_n|d8}|S�Nr�rer�r<rerrrr�_on_undo_remove�s


zRemoveOperation._on_undo_removecCs0|j|kr,|j|kr$|jd8_n|d8}|Sryrzr{rrr�_on_undo_add�s


zRemoveOperation._on_undo_addN�rrr
rr&r|r}rrrrr5{s
r5c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r6z,Adds an object property or an array element.c
Cs�z|jd}Wn,ty:}ztd��WYd}~n
d}~00|j�|�\}}t|t�r�|dkrj|�|�q�|t|�ks~|dkr�t	d��q�|�
||�nPt|t�r�|dur�|}q�|||<n.|dur�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})r^rsrrgrrr"rrrr�insertr�	TypeErrorr`�typerf)r<r]rrwrurvrrrr&�s*�



zAddOperation.applycCs0|j|kr,|j|kr$|jd7_n|d7}|Sryrzr{rrrr|�s


zAddOperation._on_undo_removecCs0|j|kr,|j|kr$|jd8_n|d7}|Sryrzr{rrrr}�s


zAddOperation._on_undo_addNr~rrrrr6�s r6c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r7z=Replaces an object property or an array element by new value.c
Cs�z|jd}Wn,ty:}ztd��WYd}~n
d}~00|j�|�\}}|durX|St|t�r�|t|�ksv|dkr�td��nTt|t	�r�||vr�d�
|�}t|��n.|dur�td�
t|����ntd�
|j
|���|||<|S)Nrrrzcan't replace outside of listz'can't replace non-existent object '{0}'r�r�)r^rsrrgrrr"rrrrr`r�r�rf)r<r]rrwrurvrxrrrr&�s*�




zReplaceOperation.applycCs|SrArr{rrrr|�sz ReplaceOperation._on_undo_removecCs|SrArr{rrrr}�szReplaceOperation._on_undo_addNr~rrrrr7�sr7c@sNeZdZdZdd�Zedd��Zedd��Zejdd��Zd	d
�Z	dd�Z
d
S)r8z=Moves an object property or an array element to new location.c
Csz.t|jdt�r|jd}nt|jd�}Wn,tyZ}ztd��WYd}~n
d}~00|�|�\}}z||}Wn4ttfy�}ztt|���WYd}~n
d}~00|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_rer0�r_rer)r"r^rrsrrrrtrrprgr�containsr5r&r6rf�r<r]�from_ptrrwrurvrrrrr&�sB�"


�����zMoveOperation.applycCs"t|jd�}d�|jdd��S)Nr�rjrk)rr^rlrm�r<r�rrr�	from_pathszMoveOperation.from_pathcCs@t|jd�}zt|jd�WSty:|jdYS0dS�Nr�rk)rr^rnrmr�r�rrr�from_key!s
zMoveOperation.from_keycCs,t|jd�}t|�|jd<|j|jd<dSr�)rr^rprmre)r<rr�rrrr�)scCs\|j|kr,|j|kr$|jd7_n|d8}|j|krX|j|krP|jd7_n|d7}|Sry�r�r�rerr{rrrr|/s



zMoveOperation._on_undo_removecCs\|j|kr,|j|kr$|jd8_n|d8}|j|krX|j|krP|jd8_n|d7}|Sryr�r{rrrr}<s



zMoveOperation._on_undo_addN)rrr
rr&rcr�r�rqr|r}rrrrr8�s%



r8c@seZdZdZdd�ZdS)r9z!Test value by specified location.c
Cs�z0|j�|�\}}|dur |}n|j�||�}Wn0ty`}ztt|���WYd}~n
d}~00z|jd}Wn,ty�}ztd��WYd}~n
d}~00||kr�d}t|�	|t
|�|t
|����|S)Nrrz0{0} ({1}) is not equal to tested value {2} ({3}))rgrr�walkrrrpr^rsrr`r�)r<r]rurv�valrwrrxrrrr&Ms&"��zTestOperation.applyN�rrr
rr&rrrrr9Jsr9c@seZdZdZdd�ZdS)r:zA Copies an object property or an array element to a new location c
Cs�zt|jd�}Wn,ty>}ztd��WYd}~n
d}~00|�|�\}}zt�||�}Wn4ttfy�}ztt	|���WYd}~n
d}~00t
d|j|d���|�}|S)Nr�r�r0r�)
rr^rsrrrr4r\rtrrpr6rfr&r�rrrr&hs&�"��zCopyOperation.applyNr�rrrrr:esr:c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)rRcCs4iig|_ggg|_g|_}||dg|dd�<dSrA)�
index_storage�index_storage2�_DiffBuilder__root)r<�rootrrrr=�s


zDiffBuilder.__init__cCsfz:|j|}|�|�}|dur*|g||<n||�|�Wn&ty`|j|�||f�Yn0dSrA)r��getrr�r�)r<r�index�st�storage�storedrrr�store_index�s

zDiffBuilder.store_indexcCs�z"|j|�|�}|r |��WSWn\ty~|j|}tt|�ddd�D]*}||d|krN|�|�dYSqNYn0dS)Nrrkr)r�r��popr�r��ranger)r<rr�r�r��irrr�
take_index�s
zDiffBuilder.take_indexcCs,|j}|d}|||g|d<|d<|dS)Nrr�r�)r<r_r��lastrrrr��szDiffBuilder.insertcCs*|\}}}||d<||d<g|dd�<dS)Nrrr)r<r�Z	link_prevZ	link_next�_rrrr/�s
zDiffBuilder.removeccs.|j}|d}||ur*|dV|d}qdS�Nr�r�)r<�startr��currrrr�	iter_from�s

zDiffBuilder.iter_fromccs.|j}|d}||ur*|dV|d}qdSr�r�)r<r�r�rrrrE�s

zDiffBuilder.__iter__ccs�|j}|d}||ur�|d|ur�|d|dd}}|j|jkr�t|�tkr�t|�tkr�td|j|jdd��jV|dd}q|djV|d}qdS)Nrr�r1rr�)r�rfr�r5r6r7r^)r<r�r�Zop_firstZ	op_secondrrrrT�s&
�
��zDiffBuilder.executec	Cs�|�|t�}|dur�|d}t|j�tkrXt|�tkrX|�|�D]}|�|j|j�|_q@|�|�|j	t
||�kr�td|j	t
||�d��}|�|�n.t
dt
||�|d��}|�|�}|�||t�dS)Nr�r2�r_r�rer0r�)r��
_ST_REMOVEr�rrnr�r|rer/rf�
_path_joinr8r�r6r��_ST_ADD)	r<rer�itemr�r_�v�new_op�	new_indexrrr�_item_added�s*
��
zDiffBuilder._item_addedc	Cs�tdt||�d��}|�|t�}|�|�}|dur�|d}t|j�tkrj|�|�D]}|�	|j
|j�|_qR|�|�|j|jkr�t
d|j|jd��}||d<q�|�|�n|�||t�dS)Nr/r�r�r2r�)r5r�r�r�r�r�rrnr�r}rer/rfr8r�r�)	r<rerr�r�r�r�r_r�rrr�
_item_removed�s*�

�
zDiffBuilder._item_removedcCs |�tdt||�|d���dS)Nr1r�)r�r7r�)r<rerr�rrr�_item_replaceds
�zDiffBuilder._item_replacedc	Cs�t|���}t|���}||}||}|D]}|�|t|�||�q,|D]}|�|t|�||�qL||@D]}|�||||||�qpdSrA)�set�keysr�rpr�rS)	r<rer,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.dSrA)r�max�minr�r"rr�r�r�_compare_listsr�r�)r<rer,r-Zlen_srcZlen_dst�max_lenZmin_lenr�old�newrrrr�s*


�
�zDiffBuilder._compare_listscCs~t|t�r*t|t�r*|�t||�||�nPt|t�rTt|t�rT|�t||�||�n&t�|�t�|�krldS|�|||�dSrA)	r"rr�r�rr�rXrYr�)r<rerr,r-rrrrS3s
�
�	zDiffBuilder._compare_valuesN)rrr
r=r�r�r�r/r�rErTr�r�r�r�r�rSrrrrrR~srRcCs,|dur|S|dt|��dd��dd�S)Nrj�~z~0z~1)rpr1rzrrrr�Jsr�)F)1r�
__future__rrr4�	functoolsrX�sysZjsonpointerrrr�r��collections.abcrr�ImportError�unicoderp�
__author__�__version__Z__website__�__license__�version_info�bytesr#�	Exceptionr	rr�AssertionErrorrr �partial�loadsrOr*r.�objectr$rdr5r6r7r8r9r:rRr�rrrr�<module>!sP

	
%&/4'VM