
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
¹1V˜$  ã               @   s  d dl mZ yd dlmZmZ W n$ ek
rD   d dlmZmZ Y nX dZdZdZ	dZ
y d dlmZ d dlmZ eZW n$ ek
rš   d dlmZ eZY nX d d	lmZ d d
lZd d
lZejdƒZG dd„ deƒZG dd„ deƒZeƒ Zefdd„Zddd„ZG dd„ deƒZdd„ Z d
S )é    )Úunicode_literals)ÚMappingÚSequenceu    Stefan KÃ¶gl <stefan@skoegl.net>z1.10z2https://github.com/stefankoegl/python-json-pointerzModified BSD License)Úunquote)Úizip)ÚteeNz0|[1-9][0-9]*$c               @   s   e Zd ZdS )ÚJsonPointerExceptionN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú!/usr/lib/python3.6/jsonpointer.pyr   B   s   r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	EndOfListz+ Result of accessing element "-" of a list c             C   s
   || _ d S )N)Úlist_)Úselfr   r   r   r   Ú__init__I   s    zEndOfList.__init__c             C   s   dj | jjt| jƒd�S )Nz{cls}({lst}))ÚclsZlst)ÚformatÚ	__class__r	   Úreprr   )r   r   r   r   Ú__repr__M   s    
zEndOfList.__repr__N)r	   r
   r   Ú__doc__r   r   r   r   r   r   r   F   s   r   c             C   s   t |ƒ}|j| |ƒS )an  
    Resolves pointer against doc and returns the referenced object

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

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

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

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

    >>> resolve_pointer(obj, '/foo/another%20prop/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

    )ÚJsonPointerÚresolve)ÚdocÚpointerÚdefaultr   r   r   Úresolve_pointerU   s    r   Tc             C   s   t |ƒ}|j| ||ƒS )aV  
    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%20another%20prop', 'added prop') ==     {'foo': {'another prop': {'baz': 'A string'}, 'yet another prop': 'added prop', 'anArray': [{'prop': 55}]}}
    True

    )r   Úset)r   r   ÚvalueÚinplacer   r   r   Úset_pointerr   s    r!   c               @   s‚   e Zd ZdZdd„ Zdd„ Zefdd„ZeZdd	d
„Z	dd„ Z
dd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Zedd„ ƒZdS )r   z= A JSON Pointer that can reference parts of an JSON document c             C   sP   |j dƒ}|jdƒdkr tdƒ‚tt|ƒ}dd„ |D ƒ}dd„ |D ƒ}|| _d S )Nú/r   Ú zlocation must starts with /c             S   s   g | ]}|j d dƒ‘qS )z~1r"   )Úreplace)Ú.0Úpartr   r   r   ú
<listcomp>’   s    z(JsonPointer.__init__.<locals>.<listcomp>c             S   s   g | ]}|j d dƒ‘qS )z~0ú~)r$   )r%   r&   r   r   r   r'   “   s    )ÚsplitÚpopr   Úmapr   Úparts)r   r   r,   r   r   r   r   Œ   s    

zJsonPointer.__init__c             C   sH   | j s|dfS x"| j dd… D ]}| j||ƒ}qW || j|| j d ƒfS )z@ Resolves ptr until the last step, returns (sub-doc, last-step) Né   éÿÿÿÿr.   )r,   ÚwalkÚget_part)r   r   r&   r   r   r   Úto_last—   s
    zJsonPointer.to_lastc             C   sJ   xD| j D ]:}y| j||ƒ}W q tk
r@   |tkr8‚ n|S Y qX qW |S )zBResolves the pointer against doc and returns the referenced object)r,   r/   r   Ú_nothing)r   r   r   r&   r   r   r   r   £   s    zJsonPointer.resolveTc             C   sF   t | jƒdkr|rtdƒ‚|S |s,tj|ƒ}| j|ƒ\}}|||< |S )zH Resolve the pointer against the doc and replace the target with value. r   zcannot set root in place)Úlenr,   r   ÚcopyÚdeepcopyr1   )r   r   r   r    Úparentr&   r   r   r   r   µ   s    
zJsonPointer.setc             C   sj   t |tƒr|S t |tƒrH|dkr$|S tjt|ƒƒs@td|f ƒ‚t|ƒS t|dƒrV|S tdt	|ƒ ƒ‚dS )z+ Returns the next step in the correct type ú-z'%s' is not a valid list indexÚ__getitem__zQDocument '%s' does not support indexing, must be dict/list or support __getitem__N)
Ú
isinstancer   r   ÚRE_ARRAY_INDEXÚmatchÚstrr   ÚintÚhasattrÚtype)r   r   r&   r   r   r   r0   Å   s    


zJsonPointer.get_partc             C   sÆ   | j ||ƒ}t|ƒttfks8t|dƒs8tdt|ƒf ƒ‚t|tƒrry|| S  tk
rn   t	d||f ƒ‚Y qÂX nPt|t
ƒrº|dkrŒt|ƒS y|| S  tk
r¶   t	d|f ƒ‚Y qÂX n|| S dS )z7 Walks one step in doc and returns the referenced part r8   zinvalid document type %szmember '%s' not found in %sr7   zindex '%s' is out of boundsN)r0   r?   ÚdictÚlistr>   ÚAssertionErrorr9   r   ÚKeyErrorr   r   r   Ú
IndexError)r   r   r&   r   r   r   r/   Þ   s    ,

zJsonPointer.walkc             C   s   | j dt|j ƒ… |j kS )z+Returns True if self contains the given ptrN)r,   r3   )r   Úptrr   r   r   Úcontainsû   s    zJsonPointer.containsc             C   s
   | j |ƒS )z+Returns True if self contains the given ptr)rF   )r   Úitemr   r   r   Ú__contains__ÿ   s    zJsonPointer.__contains__c             C   s2   dd„ | j D ƒ}dd„ |D ƒ}djdd„ |D ƒƒS )zx Returns the string representation of the pointer

        >>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1'
        c             S   s   g | ]}|j d dƒ‘qS )r(   z~0)r$   )r%   r&   r   r   r   r'   	  s    z$JsonPointer.path.<locals>.<listcomp>c             S   s   g | ]}|j d dƒ‘qS )r"   z~1)r$   )r%   r&   r   r   r   r'   
  s    r#   c             s   s   | ]}d | V  qdS )r"   Nr   )r%   r&   r   r   r   ú	<genexpr>  s    z#JsonPointer.path.<locals>.<genexpr>)r,   Újoin)r   r,   r   r   r   Úpath  s    zJsonPointer.pathc             C   s   t |tƒsdS | j|jkS )zÿ compares 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)r9   r   r,   )r   Úotherr   r   r   Ú__eq__  s    
zJsonPointer.__eq__c             C   s   t t| jƒƒS )N)ÚhashÚtupler,   )r   r   r   r   Ú__hash__  s    zJsonPointer.__hash__c             C   sF   dd„ |D ƒ}dd„ |D ƒ}dd„ |D ƒ}| dj dd„ |D ƒƒƒ}|S )z� Constructs a JsonPointer from a list of (unescaped) paths

        >>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0'
        True
        c             S   s   g | ]}t |ƒ‘qS r   )r<   )r%   r&   r   r   r   r'   $  s    z*JsonPointer.from_parts.<locals>.<listcomp>c             S   s   g | ]}|j d dƒ‘qS )r(   z~0)r$   )r%   r&   r   r   r   r'   %  s    c             S   s   g | ]}|j d dƒ‘qS )r"   z~1)r$   )r%   r&   r   r   r   r'   &  s    r#   c             s   s   | ]}d | V  qdS )r"   Nr   )r%   r&   r   r   r   rI   '  s    z)JsonPointer.from_parts.<locals>.<genexpr>)rJ   )r   r,   rE   r   r   r   Ú
from_parts  s
    zJsonPointer.from_partsN)T)r	   r
   r   r   r   r1   r2   r   Úgetr   r0   r/   rF   rH   ÚpropertyrK   rM   rP   ÚclassmethodrQ   r   r   r   r   r   ‰   s   

r   c             C   s&   t | ƒ\}}x|D ]}P qW t||ƒS )z´ s -> (s0,s1), (s1,s2), (s2, s3), ...

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

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

    >>> list(pairwise([1, 2, 3, 4]))
    [(1, 2), (2, 3), (3, 4)]
    )r   r   )ÚiterableÚaÚbÚ_r   r   r   Úpairwise,  s    
rY   )T)!Z
__future__r   Úcollections.abcr   r   ÚImportErrorÚcollectionsÚ
__author__Ú__version__Z__website__Z__license__Zurllibr   Ú	itertoolsr   Zunicoder<   Zurllib.parseÚzipr   Úrer4   Úcompiler:   Ú	Exceptionr   Úobjectr   r2   r   r!   r   rY   r   r   r   r   Ú<module>!   s6   


 $