From 807513d9aa24dd292c77f5eca8e7fc61606246ed Mon Sep 17 00:00:00 2001 From: Simon Eggler Date: Thu, 22 Mar 2018 21:38:41 +0100 Subject: [PATCH 1/4] enabling python3 --- README.md | 19 ++++++++++--------- jsog.py | 11 +++++++---- setup.py | 14 +++++++------- test_jsog.py | 10 ++++++++++ 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index cbfd19e..7c0419b 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,37 @@ # JavaScript Object Graphs with Python -This Python module serializes and deserializes cyclic object graphs in the [JSOG format](https://github.com/jsog/jsog). +This Python module serializes and deserializes cyclic object graphs in the [JSOG format](https://github.com/simoneggler/jsog-python). ## Source code -The official repository is (https://github.com/jsog/jsog-python). +The official repository is (https://github.com/simoneggler/jsog-python). ## Download Jsog is available in PyPI: - $ pip install jsog + $ pip install jsog3 ## Usage This code mimics the standard *json* python package: - import jsog + import jsog33 - string = jsog.dumps(cyclicGraph); - cyclicGraph = jsog.loads(string); + string = jsog3.dumps(cyclicGraph); + cyclicGraph = jsog3.loads(string); It can be used to convert between object graphs directly: - import jsog + import jsog3 - jsogStructure = jsog.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles - cyclicGraph = jsog.decode(jsogStructure); + jsogStructure = jsog3.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles + cyclicGraph = jsog3.decode(jsogStructure); ## Author * Jeff Schnitzer (jeff@infohazard.org) +* Simon Eggler (simon.eggler@gmx.net) ## License diff --git a/jsog.py b/jsog.py index ead2a66..7ef0f71 100644 --- a/jsog.py +++ b/jsog.py @@ -39,7 +39,7 @@ def encodeObject(original): result = sofar[originalId] = { '@id': originalId } - for key, value in original.iteritems(): + for key, value in original.items(): result[key] = doEncode(value) return result @@ -78,7 +78,7 @@ def firstPassDecodeObject(encoded): if '@id' in encoded: found[encoded['@id']] = result - for key, value in encoded.iteritems(): + for key, value in encoded.items(): if key != '@id': result[key] = firstPassDecode(value) @@ -96,14 +96,17 @@ def firstPassDecodeArray(encoded): def deref(withRefs): if isinstance(withRefs, dict): - for key, value in withRefs.iteritems(): + for key, value in withRefs.items(): if isinstance(value, dict) and '@ref' in value: withRefs[key] = found[value['@ref']] else: deref(value) elif isinstance(withRefs, list): for value in withRefs: - deref(value) + if isinstance(value, dict) and '@ref' in value: + withRefs[withRefs.index(value)] = found[value['@ref']] + else: + deref(value) firstPass = firstPassDecode(encoded) deref(firstPass) diff --git a/setup.py b/setup.py index d450370..4fbbcf4 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,10 @@ from distutils.core import setup setup( - name='jsog', - version='1.0.1', - author='Jeff Schnitzer', - author_email='jeff@infohazard.org', - url='https://github.com/jsog/jsog-python', + name='jsog3', + version='2.0.0', + author='Simon Eggler', + author_email='simon.eggler@gmx.net', + url='https://github.com/simoneggler/jsog-python', description='JSOG serializer and deserializer', keywords='jsog json', license='MIT License', @@ -13,7 +13,7 @@ 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2' + 'Programming Language :: Python :: 3' ], - py_modules=['jsog'] + py_modules=['jsog3'] ) diff --git a/test_jsog.py b/test_jsog.py index a3ada1e..0e52b40 100644 --- a/test_jsog.py +++ b/test_jsog.py @@ -60,5 +60,15 @@ def test_decode_plain_json(self): decoded = jsog.decode(json) self.assertEqual(json, decoded) + def test_decode_list_reference(self): + JSOGIFIED = '{"@id":"1","foo":"foo","inner1":{"@id":"2","bar":"bar"},"inner2":[{"@ref":"2"}]}' + parsed = jsog.loads(JSOGIFIED) + + inner1 = parsed['inner1'] + inner2 = parsed['inner2'][0] + self.assertTrue(inner1 is inner2) + + + if __name__ == '__main__': unittest.main() \ No newline at end of file From d27e31371d9151edef1c53928d86618c637ecccb Mon Sep 17 00:00:00 2001 From: Simon Eggler Date: Thu, 22 Mar 2018 22:39:36 +0100 Subject: [PATCH 2/4] create a package --- .gitignore | 2 ++ README.md | 12 ++++++------ jsog3/__init__.py | 0 jsog.py => jsog3/jsog.py | 0 setup.cfg | 2 ++ setup.py | 23 ++++++++++++++++++++--- 6 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 jsog3/__init__.py rename jsog.py => jsog3/jsog.py (100%) create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 2bed549..d20408c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .settings/ dist/ MANIFEST +build/ +jsog3.egg-info/ diff --git a/README.md b/README.md index 7c0419b..a4947df 100644 --- a/README.md +++ b/README.md @@ -16,17 +16,17 @@ Jsog is available in PyPI: This code mimics the standard *json* python package: - import jsog33 + from jsog3 import jsog - string = jsog3.dumps(cyclicGraph); - cyclicGraph = jsog3.loads(string); + string = jsog.dumps(cyclicGraph); + cyclicGraph = jsog.loads(string); It can be used to convert between object graphs directly: - import jsog3 + import jsog - jsogStructure = jsog3.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles - cyclicGraph = jsog3.decode(jsogStructure); + jsogStructure = jsog.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles + cyclicGraph = jsog.decode(jsogStructure); ## Author diff --git a/jsog3/__init__.py b/jsog3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jsog.py b/jsog3/jsog.py similarity index 100% rename from jsog.py rename to jsog3/jsog.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..224a779 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py index 4fbbcf4..efce72d 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,10 @@ -from distutils.core import setup + + +from setuptools import setup, find_packages setup( name='jsog3', - version='2.0.0', + version='2.0.3', + packages=['jsog3'], author='Simon Eggler', author_email='simon.eggler@gmx.net', url='https://github.com/simoneggler/jsog-python', @@ -15,5 +18,19 @@ 'Operating System :: OS Independent', 'Programming Language :: Python :: 3' ], - py_modules=['jsog3'] + + package_data={ + # If any package contains *.txt or *.rst files, include them: + '': ['*.txt', '*.md'], + }, + + # metadata for upload to PyPI + project_urls={ + "Bug Tracker": "https://github.com/simoneggler/jsog-python/issuespython", + "Documentation": "https://github.com/simoneggler/jsog-python/wiki", + "Source Code": "https://github.com/simoneggler/jsog-python", + } + + # could also include long_description, download_url, classifiers, etc. + ) From da79ee4426e37381f51cca64e774bcf06b34fb70 Mon Sep 17 00:00:00 2001 From: Simon Eggler Date: Thu, 22 Mar 2018 22:44:39 +0100 Subject: [PATCH 3/4] update documenation --- README.md | 6 +++--- setup.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4947df..10a112f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This Python module serializes and deserializes cyclic object graphs in the [JSOG ## Source code -The official repository is (https://github.com/simoneggler/jsog-python). +The official repository is (https://github.com/simoneggler/jsog-python) which is a fork of (https://github.com/jsog/jsog-python). ## Download @@ -23,12 +23,12 @@ This code mimics the standard *json* python package: It can be used to convert between object graphs directly: - import jsog + from jsog3 import jsog jsogStructure = jsog.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles cyclicGraph = jsog.decode(jsogStructure); -## Author +## Authors * Jeff Schnitzer (jeff@infohazard.org) * Simon Eggler (simon.eggler@gmx.net) diff --git a/setup.py b/setup.py index efce72d..87ec9f1 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup( name='jsog3', - version='2.0.3', + version='2.0.4', packages=['jsog3'], author='Simon Eggler', author_email='simon.eggler@gmx.net', From 8c9b15b81e36d9824311ba7b93629da3d1d2ff2f Mon Sep 17 00:00:00 2001 From: Simon Eggler Date: Thu, 22 Mar 2018 22:50:33 +0100 Subject: [PATCH 4/4] adjust import --- test_jsog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_jsog.py b/test_jsog.py index 0e52b40..126085c 100644 --- a/test_jsog.py +++ b/test_jsog.py @@ -1,4 +1,4 @@ -import jsog +from jsog3 import jsog import unittest class TestJSOG(unittest.TestCase):