%PDF- %PDF-
Mini Shell

Mini Shell

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

U

�^ZD&�@sdZddlmZdZdZdZdZzddlmZe	Z
Wnek
rLeZYnXzddl
mZmZWn$ek
r�ddlmZmZYnXdd	lmZdd
lZdd
lZe�Zddd
�Zefdd�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�Zdd�Zd
S)z7 Identify specific nodes in a JSON document (RFC 6901) �)�unicode_literalsu Stefan Kögl <stefan@skoegl.net>z2.0z2https://github.com/stefankoegl/python-json-pointerzModified BSD License)�izip)�Mapping�Sequence)�teeNTcCst|�}|�|||�S)a�Resolves pointer against doc and sets the value of the target within doc.

    With inplace set to true, doc is modified as long as pointer is not the
    root.

    >>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}}

    >>> set_pointer(obj, '/foo/anArray/0/prop', 55) ==     {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}}
    True

    >>> set_pointer(obj, '/foo/yet another prop', 'added prop') ==     {'foo': {'another prop': {'baz': 'A string'}, 'yet another prop': 'added prop', 'anArray': [{'prop': 55}]}}
    True

    >>> obj = {'foo': {}}
    >>> set_pointer(obj, '/foo/a%20b', 'x') ==     {'foo': {'a%20b': 'x' }}
    True
    )�JsonPointer�set)�doc�pointer�value�inplace�r
�-/usr/lib/python3/dist-packages/jsonpointer.py�set_pointer?srcCst|�}|�||�S)aa Resolves pointer against doc and returns the referenced object

    >>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}, 'a%20b': 1, 'c d': 2}

    >>> resolve_pointer(obj, '') == obj
    True

    >>> resolve_pointer(obj, '/foo') == obj['foo']
    True

    >>> resolve_pointer(obj, '/foo/another prop') == obj['foo']['another prop']
    True

    >>> resolve_pointer(obj, '/foo/another prop/baz') == obj['foo']['another prop']['baz']
    True

    >>> resolve_pointer(obj, '/foo/anArray/0') == obj['foo']['anArray'][0]
    True

    >>> resolve_pointer(obj, '/some/path', None) == None
    True

    >>> resolve_pointer(obj, '/a b', None) == None
    True

    >>> resolve_pointer(obj, '/a%20b') == 1
    True

    >>> resolve_pointer(obj, '/c d') == 2
    True

    >>> resolve_pointer(obj, '/c%20d', None) == None
    True
    )r�resolve)r	r
�defaultr
r
r�resolve_pointerYs$rcCs$t|�\}}|D]}qqt||�S)z� Transforms a list to a list of tuples of adjacent items

    s -> (s0,s1), (s1,s2), (s2, s3), ...

    >>> list(pairwise([]))
    []

    >>> list(pairwise([1]))
    []

    >>> list(pairwise([1, 2, 3, 4]))
    [(1, 2), (2, 3), (3, 4)]
    )rr)�iterable�a�b�_r
r
r�pairwise�src@seZdZdS)�JsonPointerExceptionN)�__name__�
__module__�__qualname__r
r
r
rr�src@s eZdZdZdd�Zdd�ZdS)�	EndOfListz)Result of accessing element "-" of a listcCs
||_dS�N)�list_)�selfrr
r
r�__init__�szEndOfList.__init__cCsdj|jjt|j�d�S)Nz{cls}({lst}))�clsZlst)�format�	__class__r�reprr�rr
r
r�__repr__�s
�zEndOfList.__repr__N)rrr�__doc__r r&r
r
r
rr�src@s�eZdZdZe�d�Ze�d�Zdd�Zdd�Z	e
fdd	�ZeZddd�Z
d
d�Zdd�Zdd�Zdd�Zedd��Zdd�Zdd�Zedd��ZdS)rz;A JSON Pointer that can reference parts of an JSON documentz0|[1-9][0-9]*$z(~[^01]|~$)cCsZ|j�|�}|r"td�|�����|�d�}|�d�dkrBtd��dd�|D�}||_dS)NzFound invalid escape {}�/r�zlocation must starts with /cSsg|]}t|��qSr
)�unescape��.0�partr
r
r�
<listcomp>�sz(JsonPointer.__init__.<locals>.<listcomp>)�_RE_INVALID_ESCAPE�searchrr"�group�split�pop�parts)rr
Zinvalid_escaper4r
r
rr �s�
zJsonPointer.__init__cCsD|js|dfS|jdd�D]}|�||�}q||�||jd�fS)z>Resolves ptr until the last step, returns (sub-doc, last-step)N���)r4�walk�get_part�rr	r-r
r
r�to_last�s
zJsonPointer.to_lastc	CsN|jD]B}z|�||�}Wqtk
rF|tkr6�n|YSYqXq|S)zBResolves the pointer against doc and returns the referenced object)r4r6r�_nothing)rr	rr-r
r
rr�s
zJsonPointer.resolveTcCsFt|j�dkr|rtd��|S|s,t�|�}|�|�\}}|||<|S)zFResolve the pointer against the doc and replace the target with value.rzcannot set root in place)�lenr4r�copy�deepcopyr9)rr	rr�parentr-r
r
rr�s
zJsonPointer.setcCsjt|t�r|St|t�rH|dkr$|S|j�t|��s@td|��t|�St|d�rV|Stdt	|���dS)z)Returns the next step in the correct type�-z"'%s' is not a valid sequence index�__getitem__zXDocument '%s' does not support indexing, must be mapping/sequence or support __getitem__N)
�
isinstancerr�_RE_ARRAY_INDEX�match�strr�int�hasattr�typer8r
r
rr7�s


�zJsonPointer.get_partcCs�|�||�}t|d�s(tdt|�f��t|t�rp|dkrBt|�Sz
||WStk
rntd|f��YnXz
||WSt	k
r�td||f��YnXdS)z7 Walks one step in doc and returns the referenced part r@zinvalid document type %sr?zindex '%s' is out of boundszmember '%s' not found in %sN)
r7rF�AssertionErrorrGrArr�
IndexErrorr�KeyErrorr8r
r
rr6s


zJsonPointer.walkcCs|jdt|j��|jkS)�- Returns True if self contains the given ptr N)r4r;)r�ptrr
r
r�containsszJsonPointer.containscCs
|�|�S)rK)rM)r�itemr
r
r�__contains__szJsonPointer.__contains__cCs$dd�|jD�}d�dd�|D��S)zwReturns the string representation of the pointer

        >>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1'
        cSsg|]}t|��qSr
)�escaper+r
r
rr.(sz$JsonPointer.path.<locals>.<listcomp>r)css|]}d|VqdS�r(Nr
r+r
r
r�	<genexpr>)sz#JsonPointer.path.<locals>.<genexpr>)r4�join)rr4r
r
r�path"szJsonPointer.pathcCst|t�sdS|j|jkS)aCompares a pointer to another object

        Pointers can be compared by comparing their strings (or splitted
        strings), because no two different parts can point to the same
        structure in an object (eg no different number representations)
        F)rArr4)r�otherr
r
r�__eq__+s
zJsonPointer.__eq__cCstt|j��Sr)�hash�tupler4r%r
r
r�__hash__8szJsonPointer.__hash__cCs*dd�|D�}|d�dd�|D���}|S)z�Constructs a JsonPointer from a list of (unescaped) paths

        >>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0'
        True
        cSsg|]}tt|���qSr
)rPrDr+r
r
rr.Bsz*JsonPointer.from_parts.<locals>.<listcomp>r)css|]}d|VqdSrQr
r+r
r
rrRCsz)JsonPointer.from_parts.<locals>.<genexpr>)rS)r!r4rLr
r
r�
from_parts;szJsonPointer.from_partsN)T)rrrr'�re�compilerBr/r r9r:r�getrr7r6rMrO�propertyrTrVrY�classmethodrZr
r
r
rr�s$




rcCs|�dd��dd�S)N�~�~0r(�~1��replace��sr
r
rrPGsrPcCs|�dd��dd�S)Nrbr(rar`rcrer
r
rr*Jsr*)T)r'Z
__future__r�
__author__�__version__Z__website__Z__license__�	itertoolsrZunicoderD�ImportError�zipZcollections.abcrr�collectionsrr[r<�objectr:rrr�	ExceptionrrrrPr*r
r
r
r�<module>!s6

($

Zerion Mini Shell 1.0