Current File : //proc/self/root/lib/python2.7/site-packages/jsonpointer.pyo
�
 �KUc@sgddlmZyddlmZmZWn'ek
rSddlmZmZnXdZdZdZ	dZ
y*ddlmZddl
mZeZWn'ek
r�ddlmZeZnXdd	l
mZdd
lZdd
lZejd�Zdefd
��YZdefd��YZe�Zed�Zed�Zdefd��YZ d�Z!d
S(i����(tunicode_literals(tMappingtSequenceu Stefan Kögl <stefan@skoegl.net>u1.9u2https://github.com/stefankoegl/python-json-pointeruModified BSD License(tunquote(tizip(tteeNu0|[1-9][0-9]*$tJsonPointerExceptioncBseZRS((t__name__t
__module__(((s//usr/lib/python2.7/site-packages/jsonpointer.pyRBst	EndOfListcBs eZdZd�Zd�ZRS(u+ Result of accessing element "-" of a list cCs
||_dS(N(tlist_(tselfR
((s//usr/lib/python2.7/site-packages/jsonpointer.pyt__init__IscCs%djd|jjdt|j��S(Nu{cls}({lst})tclstlst(tformatt	__class__RtreprR
(R((s//usr/lib/python2.7/site-packages/jsonpointer.pyt__repr__Ms(RRt__doc__RR(((s//usr/lib/python2.7/site-packages/jsonpointer.pyR	Fs	cCst|�}|j||�S(un
    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

    (tJsonPointertresolve(tdoctpointertdefault((s//usr/lib/python2.7/site-packages/jsonpointer.pytresolve_pointerUscCst|�}|j|||�S(uV
    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

    (Rtset(RRtvaluetinplace((s//usr/lib/python2.7/site-packages/jsonpointer.pytset_pointerrsRcBs�eZdZd�Zd�Zed�ZeZed�Z	d�Z
d�Zd�Zd�Z
ed	��Zd
�Zd�Zed��ZRS(
u= A JSON Pointer that can reference parts of an JSON document cCs�|jd�}|jd�dkr3td��ntt|�}g|D]}|jdd�^qI}g|D]}|jdd�^qn}||_dS(Nu/iuulocation must starts with /u~1u~0u~(tsplittpopRtmapRtreplacetparts(RRR"tpart((s//usr/lib/python2.7/site-packages/jsonpointer.pyR�s%%cCsZ|js|dfSx'|jd D]}|j||�}q!W||j||jd�fS(u@ Resolves ptr until the last step, returns (sub-doc, last-step) i����N(R"tNonetwalktget_part(RRR#((s//usr/lib/python2.7/site-packages/jsonpointer.pytto_last�s
	
cCsXxQ|jD]F}y|j||�}Wq
tk
rO|tkrH�qP|Sq
Xq
W|S(uBResolves the pointer against doc and returns the referenced object(R"R%Rt_nothing(RRRR#((s//usr/lib/python2.7/site-packages/jsonpointer.pyR�s
cCsit|j�dkr.|r*td��n|S|sFtj|�}n|j|�\}}|||<|S(uH Resolve the pointer against the doc and replace the target with value. iucannot set root in place(tlenR"RtcopytdeepcopyR'(RRRRtparentR#((s//usr/lib/python2.7/site-packages/jsonpointer.pyR�s
cCs�t|t�r|St|t�rg|dkr2|Stjt|��s]td|f��nt|�St|d�rz|Stdt	|���dS(u+ Returns the next step in the correct type u-u'%s' is not a valid list indexu__getitem__uQDocument '%s' does not support indexing, must be dict/list or support __getitem__N(
t
isinstanceRRtRE_ARRAY_INDEXtmatchtstrRtintthasattrttype(RRR#((s//usr/lib/python2.7/site-packages/jsonpointer.pyR&�s
cCs�|j||�}t|t�rZy||SWq�tk
rVtd||f��q�Xnct|t�r�|dkrt|�Sy||SWq�tk
r�td|f��q�Xn||SdS(u7 Walks one step in doc and returns the referenced part umember '%s' not found in %su-uindex '%s' is out of boundsN(R&R-RtKeyErrorRRR	t
IndexError(RRR#((s//usr/lib/python2.7/site-packages/jsonpointer.pyR%�s


cCs|jt|j� |jkS(u+Returns True if self contains the given ptr(R"R)(Rtptr((s//usr/lib/python2.7/site-packages/jsonpointer.pytcontains�scCs
|j|�S(u+Returns True if self contains the given ptr(R7(Rtitem((s//usr/lib/python2.7/site-packages/jsonpointer.pyt__contains__�scCsdg|jD]}|jdd�^q
}g|D]}|jdd�^q/}djd�|D��S(ux Returns the string representation of the pointer

        >>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1'
        u~u~0u/u~1ucss|]}d|VqdS(u/N((t.0R#((s//usr/lib/python2.7/site-packages/jsonpointer.pys	<genexpr>s(R"R!tjoin(RR#R"((s//usr/lib/python2.7/site-packages/jsonpointer.pytpaths(%cCs#t|t�stS|j|jkS(u� 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) (R-RtFalseR"(Rtother((s//usr/lib/python2.7/site-packages/jsonpointer.pyt__eq__
scCstt|j��S(N(thashttupleR"(R((s//usr/lib/python2.7/site-packages/jsonpointer.pyt__hash__scCs�g|D]}t|�^q}g|D]}|jdd�^q&}g|D]}|jdd�^qK}|djd�|D���}|S(u� Constructs a JsonPointer from a list of (unescaped) paths

        >>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0'
        True
        u~u~0u/u~1ucss|]}d|VqdS(u/N((R:R#((s//usr/lib/python2.7/site-packages/jsonpointer.pys	<genexpr>'s(R0R!R;(R
R"R#R6((s//usr/lib/python2.7/site-packages/jsonpointer.pyt
from_partss
%%(RRRRR'R(RtgettTrueRR&R%R7R9tpropertyR<R?RBtclassmethodRC(((s//usr/lib/python2.7/site-packages/jsonpointer.pyR�s						
	
	cCs1t|�\}}x|D]}PqWt||�S(u� 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(titerabletatbt_((s//usr/lib/python2.7/site-packages/jsonpointer.pytpairwise,s
("t
__future__Rtcollections.abcRRtImportErrortcollectionst
__author__t__version__t__website__t__license__turllibRt	itertoolsRtunicodeR0turllib.parsetzipRtreR*tcompileR.t	ExceptionRtobjectR	R(RRERRRL(((s//usr/lib/python2.7/site-packages/jsonpointer.pyt<module>!s4



	�