PK!,C99jsonpointer_helpers/__init__.pyfrom typing import Any, Dict, Sequence, Union __all__ = ( "JSONPointerError", "build", "build_pointer", "parse_pointer", "escape_token", "unescape_token", ) RefTokens = Sequence[Union[int, str]] JSONPointer = str JSONPointers = Dict[JSONPointer, Any] class JSONPointerError(Exception): pass def build(obj: dict, *, initial_ref_tokens: RefTokens = None) -> JSONPointers: ref_tokens = initial_ref_tokens or [] result = {} def walk(obj): for key, value in obj.items(): ref_tokens.append(key) if isinstance(value, dict): walk(value) else: result[build_pointer(ref_tokens)] = value ref_tokens.pop() walk(obj) return result def build_pointer(ref_tokens: RefTokens) -> JSONPointer: if not ref_tokens: return "" pointer = "/".join(escape_token(str(ref_token)) for ref_token in ref_tokens) pointer = f"/{pointer}" return pointer def parse_pointer(pointer: JSONPointer) -> RefTokens: if pointer == "": return [] if not pointer.startswith("/"): raise JSONPointerError() return [unescape_token(ref_token) for ref_token in pointer[1:].split("/")] def escape_token(token: str) -> str: to_escape = (("~", "~0"), ("/", "~1")) for old, new in to_escape: token = token.replace(old, new) return token def unescape_token(token: str) -> str: to_unescape = (("~0", "~"), ("~1", "/")) for old, new in to_unescape: token = token.replace(old, new) return token PK!=-//+jsonpointer_helpers-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2018 Nikita Grishko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H_zTT)jsonpointer_helpers-0.2.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]n0H*J>mlcAPK!H HV,jsonpointer_helpers-0.2.0.dist-info/METADATAVQo6~ׯ$E k.lI^"X"9#oߑ$HtK,g6\՘BI.,J"Q4 fM]3&\w`dbi*qm٤Q&>w COlR+g?ыa𾱥 \% >jnʥ!֌W PSZZ)\U|ф-ANG'_^ӛUH}A$yv0wT ZB梀 &]&wuR|tbƛ'x®F+QXfys)B|@i, ?<aÛVє,ۘ\Z]^06`ي0^ODfUJʼn|[3CO/2c&W[nr/7R]8eyK|)gcۊZV,[nUx]DX)D^gNY NU Ob!uwZ ~):ma3pQ UܟqDXVU̹#~? x߹I/Ck%} ܩ!ܩ(u:x-%0J{(G&WOy0ZR_;.bvܧz%w} uu[*}kAn$]["|1oL2he3I+!@O]yJfdg|n dC"G Jֈ} 31Ntn{0SPs[ȘI΄ }Hvz4y אM7\\ zNN P1 3ha] @>\nO?ӝFEC>VrCyD MC\``,x~MPK!H?#*jsonpointer_helpers-0.2.0.dist-info/RECORDMr0@g HŸ,$@`J b% 8]M7^}3o#Fhu: n[ܶ? zt+\8VBx7"xqR4mu wMEvL _:z$-Q^58x6̺g7Y{\0)( _2>CB@}~foG߸k?дd-g@ l.vKo=7e](嵐i /(>אxYXPK!,C99jsonpointer_helpers/__init__.pyPK!=-//+vjsonpointer_helpers-0.2.0.dist-info/LICENSEPK!H_zTT) jsonpointer_helpers-0.2.0.dist-info/WHEELPK!H HV, jsonpointer_helpers-0.2.0.dist-info/METADATAPK!H?#*yjsonpointer_helpers-0.2.0.dist-info/RECORDPK