ó ŒKUc@sgddlmZyddlmZmZWn'ek rSddlmZmZnXdZdZdZ dZ y*ddl m 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 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 (t JsonPointertresolve(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.pyt set_pointerrs RcBs’eZdZd„Zd„Zed„ZeZed„Z d„Z d„Z d„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(R RR"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(R RR#((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(R RRR#((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'(R RRRtparentR#((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(R RR#((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(R RR#((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)(R tptr((s//usr/lib/python2.7/site-packages/jsonpointer.pytcontainsûscCs |j|ƒS(u+Returns True if self contains the given ptr(R7(R titem((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 s(R"R!tjoin(R R#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"(R tother((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 '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?RBt classmethodRC(((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.abcRRt ImportErrort collectionst __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!s4         £