diff -Nru jsonref-0.1/debian/changelog jsonref-0.2/debian/changelog --- jsonref-0.1/debian/changelog 2018-08-17 19:00:00.000000000 +0000 +++ jsonref-0.2/debian/changelog 2022-11-02 12:00:00.000000000 +0000 @@ -1,3 +1,9 @@ +jsonref (0.2-0~jammy0) jammy; urgency=low + + * New upstream version. + + -- Angelos Tzotsos Wed, 02 Nov 2022 14:00:00 +0200 + jsonref (0.1-0~jammy0) jammy; urgency=low * Initial packaging. diff -Nru jsonref-0.1/jsonref.egg-info/dependency_links.txt jsonref-0.2/jsonref.egg-info/dependency_links.txt --- jsonref-0.1/jsonref.egg-info/dependency_links.txt 1970-01-01 00:00:00.000000000 +0000 +++ jsonref-0.2/jsonref.egg-info/dependency_links.txt 2018-10-07 19:13:40.000000000 +0000 @@ -0,0 +1 @@ + diff -Nru jsonref-0.1/jsonref.egg-info/PKG-INFO jsonref-0.2/jsonref.egg-info/PKG-INFO --- jsonref-0.1/jsonref.egg-info/PKG-INFO 1970-01-01 00:00:00.000000000 +0000 +++ jsonref-0.2/jsonref.egg-info/PKG-INFO 2018-10-07 19:13:40.000000000 +0000 @@ -0,0 +1,96 @@ +Metadata-Version: 1.1 +Name: jsonref +Version: 0.2 +Summary: An implementation of JSON Reference for Python +Home-page: https://github.com/gazpachoking/jsonref +Author: Chase Sterling +Author-email: chase.sterling@gmail.com +License: MIT +Description: jsonref + ======= + + + .. image:: https://readthedocs.org/projects/jsonref/badge/?version=latest + :target: https://jsonref.readthedocs.io/en/latest/ + + .. image:: https://travis-ci.org/gazpachoking/jsonref.png?branch=master + :target: https://travis-ci.org/gazpachoking/jsonref + + .. image:: https://coveralls.io/repos/gazpachoking/jsonref/badge.png?branch=master + :target: https://coveralls.io/r/gazpachoking/jsonref + + + ``jsonref`` is a library for automatic dereferencing of + `JSON Reference `_ + objects for Python (supporting Python 2.6+ and Python 3.3+). + + This library lets you use a data structure with JSON reference objects, as if + the references had been replaced with the referent data. + + + .. code-block:: python + + >>> from pprint import pprint + >>> import jsonref + + >>> # An example json document + >>> json_str = """{"real": [1, 2, 3, 4], "ref": {"$ref": "#/real"}}""" + >>> data = jsonref.loads(json_str) + >>> pprint(data) # Reference is not evaluated until here + {'real': [1, 2, 3, 4], 'ref': [1, 2, 3, 4]} + + + Features + -------- + + * References are evaluated lazily. Nothing is dereferenced until it is used. + + * Recursive references are supported, and create recursive python data + structures. + + + References objects are actually replaced by lazy lookup proxy objects which are + almost completely transparent. + + .. code-block:: python + + >>> data = jsonref.loads('{"real": [1, 2, 3, 4], "ref": {"$ref": "#/real"}}') + >>> # You can tell it is a proxy by using the type function + >>> type(data["real"]), type(data["ref"]) + (, ) + >>> # You have direct access to the referent data with the __subject__ + >>> # attribute + >>> type(data["ref"].__subject__) + + >>> # If you need to get at the reference object + >>> data["ref"].__reference__ + {'$ref': '#/real'} + >>> # Other than that you can use the proxy just like the underlying object + >>> ref = data["ref"] + >>> isinstance(ref, list) + True + >>> data["real"] == ref + True + >>> ref.append(5) + >>> del ref[0] + >>> # Actions on the reference affect the real data (if it is mutable) + >>> pprint(data) + {'real': [2, 3, 4, 5], 'ref': [2, 3, 4, 5]} + +Platform: UNKNOWN +Classifier: Development Status :: 1 - Planning +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.6 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: Implementation :: CPython +Classifier: Programming Language :: Python :: Implementation :: PyPy diff -Nru jsonref-0.1/jsonref.egg-info/SOURCES.txt jsonref-0.2/jsonref.egg-info/SOURCES.txt --- jsonref-0.1/jsonref.egg-info/SOURCES.txt 1970-01-01 00:00:00.000000000 +0000 +++ jsonref-0.2/jsonref.egg-info/SOURCES.txt 2018-10-07 19:13:40.000000000 +0000 @@ -0,0 +1,11 @@ +LICENSE +MANIFEST.in +README.rst +jsonref.py +proxytypes.py +setup.py +tests.py +jsonref.egg-info/PKG-INFO +jsonref.egg-info/SOURCES.txt +jsonref.egg-info/dependency_links.txt +jsonref.egg-info/top_level.txt \ No newline at end of file diff -Nru jsonref-0.1/jsonref.egg-info/top_level.txt jsonref-0.2/jsonref.egg-info/top_level.txt --- jsonref-0.1/jsonref.egg-info/top_level.txt 1970-01-01 00:00:00.000000000 +0000 +++ jsonref-0.2/jsonref.egg-info/top_level.txt 2018-10-07 19:13:40.000000000 +0000 @@ -0,0 +1,2 @@ +jsonref +proxytypes diff -Nru jsonref-0.1/jsonref.py jsonref-0.2/jsonref.py --- jsonref-0.1/jsonref.py 2013-05-17 21:14:41.000000000 +0000 +++ jsonref-0.2/jsonref.py 2018-10-07 19:13:36.000000000 +0000 @@ -1,13 +1,14 @@ import functools import json import operator +import re import sys import warnings try: - from collections import Mapping, MutableMapping, Sequence -except ImportError: from collections.abc import Mapping, MutableMapping, Sequence +except ImportError: + from collections import Mapping, MutableMapping, Sequence PY3 = sys.version_info[0] >= 3 @@ -15,6 +16,7 @@ from urllib import parse as urlparse from urllib.parse import unquote from urllib.request import urlopen + unicode = str basestring = str iteritems = operator.methodcaller("items") @@ -22,11 +24,13 @@ import urlparse from urllib import unquote from urllib2 import urlopen + iteritems = operator.methodcaller("iteritems") try: # If requests >=1.0 is available, we will use it import requests + if not callable(requests.Response.json): requests = None except ImportError: @@ -34,13 +38,11 @@ from proxytypes import LazyProxy, Proxy -__version__ = "0.1" +__version__ = "0.2" class JsonRefError(Exception): - def __init__( - self, message, reference, uri="", base_uri="", path=(), cause=None - ): + def __init__(self, message, reference, uri="", base_uri="", path=(), cause=None): self.message = message self.reference = reference self.uri = uri @@ -51,6 +53,9 @@ def __repr__(self): return "<%s: %r>" % (self.__class__.__name__, self.message) + def __str__(self): + return str(self.message) + class JsonRef(LazyProxy): """ @@ -112,20 +117,27 @@ path = list(kwargs.pop("_path", ())) if isinstance(obj, Mapping): obj = type(obj)( - (k, cls.replace_refs(v, _path=path+[k], **kwargs)) + (k, cls.replace_refs(v, _path=path + [k], **kwargs)) for k, v in iteritems(obj) ) elif isinstance(obj, Sequence) and not isinstance(obj, basestring): obj = type(obj)( - cls.replace_refs(v, _path=path+[i], **kwargs) for i, v in enumerate(obj) + cls.replace_refs(v, _path=path + [i], **kwargs) + for i, v in enumerate(obj) ) if store_uri is not None: store[store_uri] = obj return obj def __init__( - self, refobj, base_uri="", loader=None, jsonschema=False, - load_on_repr=True, _path=(), _store=None + self, + refobj, + base_uri="", + loader=None, + jsonschema=False, + load_on_repr=True, + _path=(), + _store=None, ): if not isinstance(refobj.get("$ref"), basestring): raise ValueError("Not a valid json reference object: %s" % refobj) @@ -142,9 +154,12 @@ @property def _ref_kwargs(self): return dict( - base_uri=self.base_uri, loader=self.loader, - jsonschema=self.jsonschema, load_on_repr=self.load_on_repr, - _path=self.path, _store=self.store + base_uri=self.base_uri, + loader=self.loader, + jsonschema=self.jsonschema, + load_on_repr=self.load_on_repr, + _path=self.path, + _store=self.store, ) @property @@ -181,10 +196,17 @@ :argument str pointer: a json pointer URI fragment to resolve within it """ - parts = unquote(pointer.lstrip("/")).split("/") if pointer else [] + # Do only split at single forward slashes which are not prefixed by a caret + parts = re.split(r"(?=1.2 required for custom kwargs to json.loads" - ) + warnings.warn("requests >=1.2 required for custom kwargs to json.loads") result = requests.get(uri).json() else: # Otherwise, pass off to urllib and assume utf-8 @@ -296,19 +317,17 @@ return result + jsonloader = JsonLoader() -def load( - fp, base_uri="", loader=None, jsonschema=False, load_on_repr=True, - **kwargs -): +def load(fp, base_uri="", loader=None, jsonschema=False, load_on_repr=True, **kwargs): """ Drop in replacement for :func:`json.load`, where JSON references are proxied to their referent data. :param fp: File-like object containing JSON document - :param **kwargs: This function takes any of the keyword arguments from + :param kwargs: This function takes any of the keyword arguments from :meth:`JsonRef.replace_refs`. Any other keyword arguments will be passed to :func:`json.load` @@ -322,20 +341,17 @@ base_uri=base_uri, loader=loader, jsonschema=jsonschema, - load_on_repr=load_on_repr + load_on_repr=load_on_repr, ) -def loads( - s, base_uri="", loader=None, jsonschema=False, load_on_repr=True, - **kwargs -): +def loads(s, base_uri="", loader=None, jsonschema=False, load_on_repr=True, **kwargs): """ Drop in replacement for :func:`json.loads`, where JSON references are proxied to their referent data. :param s: String containing JSON document - :param **kwargs: This function takes any of the keyword arguments from + :param kwargs: This function takes any of the keyword arguments from :meth:`JsonRef.replace_refs`. Any other keyword arguments will be passed to :func:`json.loads` @@ -349,19 +365,17 @@ base_uri=base_uri, loader=loader, jsonschema=jsonschema, - load_on_repr=load_on_repr + load_on_repr=load_on_repr, ) -def load_uri( - uri, base_uri=None, loader=None, jsonschema=False, load_on_repr=True -): +def load_uri(uri, base_uri=None, loader=None, jsonschema=False, load_on_repr=True): """ Load JSON data from ``uri`` with JSON references proxied to their referent data. :param uri: URI to fetch the JSON from - :param **kwargs: This function takes any of the keyword arguments from + :param kwargs: This function takes any of the keyword arguments from :meth:`JsonRef.replace_refs` """ @@ -376,7 +390,7 @@ base_uri=base_uri, loader=loader, jsonschema=jsonschema, - load_on_repr=load_on_repr + load_on_repr=load_on_repr, ) @@ -416,14 +430,17 @@ if hasattr(o, "__reference__"): return o.__reference__ return super(JSONRefEncoder, cls).default(o) + # Python 2.6 doesn't work with the default method def _iterencode(self, o, *args, **kwargs): if hasattr(o, "__reference__"): o = o.__reference__ return super(JSONRefEncoder, self)._iterencode(o, *args, **kwargs) + # Pypy doesn't work with either of the other methods def _encode(self, o, *args, **kwargs): if hasattr(o, "__reference__"): o = o.__reference__ return super(JSONRefEncoder, self)._encode(o, *args, **kwargs) + return JSONRefEncoder diff -Nru jsonref-0.1/MANIFEST.in jsonref-0.2/MANIFEST.in --- jsonref-0.1/MANIFEST.in 1970-01-01 00:00:00.000000000 +0000 +++ jsonref-0.2/MANIFEST.in 2018-10-07 18:32:24.000000000 +0000 @@ -0,0 +1,3 @@ +include *.rst +include LICENSE +include tests.py diff -Nru jsonref-0.1/PKG-INFO jsonref-0.2/PKG-INFO --- jsonref-0.1/PKG-INFO 2013-05-17 21:25:13.000000000 +0000 +++ jsonref-0.2/PKG-INFO 2018-10-07 19:13:40.000000000 +0000 @@ -1,14 +1,18 @@ Metadata-Version: 1.1 Name: jsonref -Version: 0.1 +Version: 0.2 Summary: An implementation of JSON Reference for Python -Home-page: http://github.com/gazpachoking/jsonref +Home-page: https://github.com/gazpachoking/jsonref Author: Chase Sterling Author-email: chase.sterling@gmail.com License: MIT Description: jsonref ======= + + .. image:: https://readthedocs.org/projects/jsonref/badge/?version=latest + :target: https://jsonref.readthedocs.io/en/latest/ + .. image:: https://travis-ci.org/gazpachoking/jsonref.png?branch=master :target: https://travis-ci.org/gazpachoking/jsonref @@ -17,8 +21,8 @@ ``jsonref`` is a library for automatic dereferencing of - `JSON Reference `_ - objects for Python (supporting 2.6+ including Python 3). + `JSON Reference `_ + objects for Python (supporting Python 2.6+ and Python 3.3+). This library lets you use a data structure with JSON reference objects, as if the references had been replaced with the referent data. @@ -83,8 +87,10 @@ Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.1 -Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy diff -Nru jsonref-0.1/proxytypes.py jsonref-0.2/proxytypes.py --- jsonref-0.1/proxytypes.py 2013-04-26 03:23:47.000000000 +0000 +++ jsonref-0.2/proxytypes.py 2018-10-07 19:10:18.000000000 +0000 @@ -12,22 +12,64 @@ OPERATORS = [ # Unary - "pos", "neg", "abs", "invert", + "pos", + "neg", + "abs", + "invert", # Comparison - "eq", "ne", "lt", "gt", "le", "ge", + "eq", + "ne", + "lt", + "gt", + "le", + "ge", # Container - "getitem", "setitem", "delitem", "contains", + "getitem", + "setitem", + "delitem", + "contains", # In-place operators - "iadd", "isub", "imul", "ifloordiv", "itruediv", "imod", "ipow", "ilshift", - "irshift", "iand", "ior", "ixor" + "iadd", + "isub", + "imul", + "ifloordiv", + "itruediv", + "imod", + "ipow", + "ilshift", + "irshift", + "iand", + "ior", + "ixor", ] REFLECTED_OPERATORS = [ - "add", "sub", "mul", "floordiv", "truediv", "mod", "pow", "and", "or", - "xor", "lshift", "rshift" + "add", + "sub", + "mul", + "floordiv", + "truediv", + "mod", + "pow", + "and", + "or", + "xor", + "lshift", + "rshift", ] # These functions all have magic methods named after them MAGIC_FUNCS = [ - divmod, round, repr, str, hash, len, abs, complex, bool, int, float, iter + divmod, + round, + repr, + str, + hash, + len, + abs, + complex, + bool, + int, + float, + iter, ] if PY3: @@ -83,6 +125,7 @@ during the method call. """ + @wraps(method) def wrapper(self, *args, **kwargs): notproxied = _oga(self, "__notproxied__") @@ -91,8 +134,10 @@ return method(self, *args, **kwargs) finally: _osa(self, "__notproxied__", notproxied) + return wrapper + # Since python 2 and 3 metaclass syntax aren't compatible, create an instance # of our metaclass which our Proxy class can inherit from _ProxyBase = ProxyMetaClass("_ProxyBase", (), {}) @@ -150,12 +195,14 @@ called with the proxied value inserted at `arg_pos` """ + @wraps(func) def proxied(self, *args, **kwargs): args = list(args) args.insert(arg_pos, self.__subject__) result = func(*args, **kwargs) return result + setattr(cls, name, proxied) @@ -168,9 +215,7 @@ # Reflected operators for op in REFLECTED_OPERATORS: - Proxy.add_proxy_meth( - "__r%s__" % op, getattr(operator, "__%s__" % op), arg_pos=1 - ) + Proxy.add_proxy_meth("__r%s__" % op, getattr(operator, "__%s__" % op), arg_pos=1) # One offs # Only non-operator that needs a reflected version diff -Nru jsonref-0.1/README.rst jsonref-0.2/README.rst --- jsonref-0.1/README.rst 2013-05-17 21:14:41.000000000 +0000 +++ jsonref-0.2/README.rst 2018-10-07 18:32:24.000000000 +0000 @@ -1,6 +1,10 @@ jsonref ======= + +.. image:: https://readthedocs.org/projects/jsonref/badge/?version=latest + :target: https://jsonref.readthedocs.io/en/latest/ + .. image:: https://travis-ci.org/gazpachoking/jsonref.png?branch=master :target: https://travis-ci.org/gazpachoking/jsonref @@ -9,8 +13,8 @@ ``jsonref`` is a library for automatic dereferencing of -`JSON Reference `_ -objects for Python (supporting 2.6+ including Python 3). +`JSON Reference `_ +objects for Python (supporting Python 2.6+ and Python 3.3+). This library lets you use a data structure with JSON reference objects, as if the references had been replaced with the referent data. diff -Nru jsonref-0.1/setup.cfg jsonref-0.2/setup.cfg --- jsonref-0.1/setup.cfg 1970-01-01 00:00:00.000000000 +0000 +++ jsonref-0.2/setup.cfg 2018-10-07 19:13:40.000000000 +0000 @@ -0,0 +1,4 @@ +[egg_info] +tag_build = +tag_date = 0 + diff -Nru jsonref-0.1/setup.py jsonref-0.2/setup.py --- jsonref-0.1/setup.py 2013-05-17 21:14:41.000000000 +0000 +++ jsonref-0.2/setup.py 2018-10-07 19:06:33.000000000 +0000 @@ -1,8 +1,23 @@ -from distutils.core import setup +import setuptools from jsonref import __version__ +class PyTest(setuptools.Command): + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + import subprocess + errno = subprocess.call(['py.test', 'tests.py']) + raise SystemExit(errno) + + with open("README.rst") as readme: long_description = readme.read() @@ -17,15 +32,17 @@ "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.1", - "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] -setup( +setuptools.setup( name="jsonref", version=__version__, py_modules=["jsonref", "proxytypes"], @@ -35,5 +52,8 @@ description="An implementation of JSON Reference for Python", license="MIT", long_description=long_description, - url="http://github.com/gazpachoking/jsonref", + url="https://github.com/gazpachoking/jsonref", + cmdclass={ + 'test': PyTest, + }, )