ó ĘŠ\Tc@sűdZdZdZdZdZy$ddlmZddlmZWn'e k rkddl mZe ZnXddlm Z dd l Z e jd ƒZd efd „ƒYZd efd„ƒYZeƒZed„Zdefd„ƒYZd„Zd S(s7 Identify specific nodes in a JSON document (RFC 6901) s Stefan KĂśgl s1.0s2https://github.com/stefankoegl/python-json-pointersModified BSD Licensei˙˙˙˙(tunquote(tizip(tteeNs0|[1-9][0-9]*$tJsonPointerExceptioncBseZRS((t__name__t __module__(((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyR9st EndOfListcBs eZdZd„Zd„ZRS(s+ Result of accessing element "-" of a list cCs ||_dS(N(tlist_(tselfR((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyt__init__@scCs%djd|jjdt|jƒƒS(Ns {cls}({lst})tclstlst(tformatt __class__RtreprR(R((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyt__repr__Ds(RRt__doc__R R(((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyR=s cCst|ƒ}|j||ƒS(sn 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((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pytresolve_pointerLs RcBsbeZdZd„Zed„Zed„ZeZd„Zd„Z d„Z d„Z d„Z RS( s= 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(Nt/itslocation must starts with /s~1s~0t~(tsplittpopRtmapRtreplacetparts(RRRtpart((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyR ms%%cCsZ|js|dfSx'|jd D]}|j||ƒ}q!W||j||jdƒfS(s@ Resolves ptr until the last step, returns (sub-doc, last-step) i˙˙˙˙N(RtNonetwalktget_part(RRRR((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pytto_lastxs   cCsXxQ|jD]F}y|j||ƒ}Wq tk rO|tkrH‚qP|Sq Xq W|S(sBResolves the pointer against doc and returns the referenced object(RR!Rt_nothing(RRRR((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyR„s   cCst|tƒr|St|tƒrg|dkr2|Stjt|ƒƒs]td|fƒ‚nt|ƒStd|jfƒ‚dS(s+ Returns the next step in the correct type t-s'%s' is not a valid list indexsUnknown document type '%s'N( t isinstancetdicttlisttRE_ARRAY_INDEXtmatchtstrRtintR (RRR((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyR"—s  cCsŇ|j||ƒ}t|tƒrZy ||SWqÎtk rVtd||fƒ‚qÎXntt|tƒrľ|dkrt|ƒSy ||SWqÎtk rątd|fƒ‚qÎXntd||jfƒ‚dS(s7 Walks one step in doc and returns the referenced part smember '%s' not found in %sR%sindex '%s' is out of boundss"can not go beyond '%s' (type '%s')N( R"R&R'tKeyErrorRR(Rt IndexErrorR (RRR((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyR!Ťs      cCs;t|jƒt|jƒko:|jt|jƒ |jkS(s." Returns True if self contains the given ptr (tlenR(Rtptr((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pytcontainsČscCs#t|tƒstS|j|jkS(s˙ 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((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyt__eq__ÎscCstt|jƒƒS(N(thashttupleR(R((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyt__hash__Űs( RRRR R$R#RtgetR"R!R1R4R7(((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyRjs     cCs1t|ƒ\}}x|D]}PqWt||ƒS(s$s -> (s0,s1), (s1,s2), (s2, s3), ...(RR(titerabletatbt_((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pytpairwiseßs (Rt __author__t __version__t __website__t __license__turllibRt itertoolsRt ImportErrort urllib.parsetzipRtretcompileR)t ExceptionRtobjectRR$RRR=(((s8/opt/freeware/lib/python2.7/site-packages/jsonpointer.pyt!s&     u