KUc@sgddlmZyddlmZmZWn'ek rSddlmZmZnXdZdZdZ dZ y*ddl m Z ddl mZeZWn'ek rddlm Z eZnXdd l mZdd lZdd lZejd Zd efd YZdefdYZeZedZedZdefdYZ dZ!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 eZdZdZdZRS(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|jS(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 RcBseZdZdZdZedZeZedZ dZ dZ dZ dZ ed Zd Zd Zed ZRS( u= A JSON Pointer that can reference parts of an JSON document cCs|jd}|jddkr3tdntt|}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||jdfS(u@ Resolves ptr until the last step, returns (sub-doc, last-step) iN(R"tNonetwalktget_part(R RR#((s//usr/lib/python2.7/site-packages/jsonpointer.pytto_lasts   cCsXxQ|jD]F}y|j||}Wq tk rO|tkrHqP|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.pyRs   cCsit|jdkr.|r*tdn|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.pyRs cCst|tr|St|trg|dkr2|Stjt|s]td|fnt|St|drz|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|ttfksRt|dsRtdt|ft|try ||SWqtk rt d||fqXnct|t r|dkrt |Sy ||SWqt k rt d|fqXn||SdS(u7 Walks one step in doc and returns the referenced part u __getitem__uinvalid document type %sumember '%s' not found in %su-uindex '%s' is out of boundsN( R&R3tdicttlistR2tAssertionErrorR-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.pytcontainsscCs |j|S(u+Returns True if self contains the given ptr(R:(R titem((s//usr/lib/python2.7/site-packages/jsonpointer.pyt __contains__scCsdg|jD]}|jdd^q }g|D]}|jdd^q/}djd|DS(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|tstS|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|jS(N(thashttupleR"(R ((s//usr/lib/python2.7/site-packages/jsonpointer.pyt__hash__scCsg|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#R9((s//usr/lib/python2.7/site-packages/jsonpointer.pyt from_partss %%(RRRR R'R(RtgettTrueRR&R%R:R<tpropertyR?RBREt classmethodRF(((s//usr/lib/python2.7/site-packages/jsonpointer.pyRs       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(RRHRRRO(((s//usr/lib/python2.7/site-packages/jsonpointer.pyt!s4