summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-04-11 06:12:05 +0000
committerCoprDistGit <infra@openeuler.org>2023-04-11 06:12:05 +0000
commit33de54c684ef749ca22ae346290c507b597b65a7 (patch)
tree358556407a983ea9599a1fafbcd2a85adae3911e
parent73132bce1e859b74284833a1d5a457beeeaee670 (diff)
automatic import of python-avro-json-serializer
-rw-r--r--.gitignore1
-rw-r--r--python-avro-json-serializer.spec315
-rw-r--r--sources1
3 files changed, 317 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..506b72b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/avro_json_serializer-1.0.4.tar.gz
diff --git a/python-avro-json-serializer.spec b/python-avro-json-serializer.spec
new file mode 100644
index 0000000..6e4efcf
--- /dev/null
+++ b/python-avro-json-serializer.spec
@@ -0,0 +1,315 @@
+%global _empty_manifest_terminate_build 0
+Name: python-avro-json-serializer
+Version: 1.0.4
+Release: 1
+Summary: Avro Json Serializer
+License: Apache 2.0
+URL: https://pypi.org/project/avro-json-serializer/
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/93/16/bbd5c74f8ca9ccbdd90b24d156105d587ae59554994fdb6c7868271b6971/avro_json_serializer-1.0.4.tar.gz
+BuildArch: noarch
+
+
+%description
+[![PyPI version](https://badge.fury.io/py/avro_json_serializer.png)](http://badge.fury.io/py/avro_json_serializer)
+[AvroJsonSerializer](avro_json_serializer/__init__.py#L28) serializes data into a JSON format using AVRO schema.
+Why do we need serializer instead of just dumping into JSON?
+* validation that your data matches the schema
+* serialization of unions (see [SimpleExample](#simple-example) below)
+* some Avro JSON deserializers expect fields in JSON in the same order as in the schema
+* serialization of `bytes` and `fixed` fields
+Binary distribution can be found on [pypi](https://pypi.python.org/pypi/avro_json_serializer/).
+## Simple example:
+```python
+schema_dict = {
+ "namespace": "example.avro",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ {"name": "name", "type": "string"},
+ {"name": "favorite_number", "type": ["int", "null"]},
+ {"name": "favorite_color", "type": ["string", "null"]}
+ ]
+}
+avro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())
+serializer = AvroJsonSerializer(avro_schema)
+self.assertEquals(serializer.to_json({"name": "Alyssa", "favorite_number": 256}),
+ """{"name":"Alyssa","favorite_number":{"int":256},"favorite_color":null}""")
+self.assertEquals(serializer.to_json({"name": "Ben", "favorite_number": 7, "favorite_color": "red"}),
+ """{"name":"Ben","favorite_number":{"int":7},"favorite_color":{"string":"red"}}""")
+self.assertEquals(serializer.to_json({"name": "Lion"}),
+ """{"name":"Lion","favorite_number":null,"favorite_color":null}""")
+```
+## Another example:
+```python
+# need to serialize this data
+data = {
+ "ffloat": 1.0,
+ "funion_null": None,
+ "flong": 1L,
+ "fdouble": 2.0,
+ "ffixed": "1234567890123456",
+ "fint": 1,
+ "fstring": "hi there",
+ "frec": {
+ "subfint": 2
+ }
+}
+# according to this schema:
+schema_dict = {
+ "fields": [{"name": "fint", "type": "int"},
+ {"name": "flong", "type": "long"},
+ {"name": "fstring", "type": "string"},
+ {"name": "ffixed",
+ "size": 16,
+ "type": {"name": "fixed_16", "size": 16, "type": "fixed"}},
+ {"name": "frec",
+ "type": {"fields": [{"name": "subfint", "type": "int"}],
+ "name": "Rec",
+ "type": "record"}},
+ {"name": "funion_null", "type": ["int", "null"]},
+ {"name": "ffloat", "type": "float"},
+ {"name": "fdouble", "type": "double"}],
+ "name": "all_field",
+ "namespace": "com.some.thing",
+ "type": "record"
+}
+avro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())
+serializer = AvroJsonSerializer(avro_schema)
+json_str = serializer.to_json(data)
+print json_str
+> {"fint":1,"flong":1,"fstring":"hi there","ffixed":"1234567890123456","frec":{"subfint":2},"funion_null":null,"ffloat":1.0,"fdouble":2.0}
+```
+See [tests](avro_json_serializer/test/test_avro_json_serializer.py) for more examples.
+## How to run tests
+```bash
+python-avro-json-serializer$ virtualenv venv
+python-avro-json-serializer$ source venv/bin/activate
+(venv)python-avro-json-serializer$ pip install tox
+(venv)python-avro-json-serializer$ tox
+GLOB sdist-make: /Users/bngo/python-avro-json-serializer/setup.py
+py27 create: /Users/bngo/python-avro-json-serializer/.tox/py27
+py27 installdeps: nose, -rrequirements.txt
+py27 inst: /Users/bngo/python-avro-json-serializer/.tox/dist/avro_json_serializer-0.4.1.zip
+py27 installed: avro==1.7.6,avro-json-serializer==0.4.1,nose==1.3.7,simplejson==3.8.2,six==1.10.0
+py27 runtests: PYTHONHASHSEED='107331485'
+
+%package -n python3-avro-json-serializer
+Summary: Avro Json Serializer
+Provides: python-avro-json-serializer
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-avro-json-serializer
+[![PyPI version](https://badge.fury.io/py/avro_json_serializer.png)](http://badge.fury.io/py/avro_json_serializer)
+[AvroJsonSerializer](avro_json_serializer/__init__.py#L28) serializes data into a JSON format using AVRO schema.
+Why do we need serializer instead of just dumping into JSON?
+* validation that your data matches the schema
+* serialization of unions (see [SimpleExample](#simple-example) below)
+* some Avro JSON deserializers expect fields in JSON in the same order as in the schema
+* serialization of `bytes` and `fixed` fields
+Binary distribution can be found on [pypi](https://pypi.python.org/pypi/avro_json_serializer/).
+## Simple example:
+```python
+schema_dict = {
+ "namespace": "example.avro",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ {"name": "name", "type": "string"},
+ {"name": "favorite_number", "type": ["int", "null"]},
+ {"name": "favorite_color", "type": ["string", "null"]}
+ ]
+}
+avro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())
+serializer = AvroJsonSerializer(avro_schema)
+self.assertEquals(serializer.to_json({"name": "Alyssa", "favorite_number": 256}),
+ """{"name":"Alyssa","favorite_number":{"int":256},"favorite_color":null}""")
+self.assertEquals(serializer.to_json({"name": "Ben", "favorite_number": 7, "favorite_color": "red"}),
+ """{"name":"Ben","favorite_number":{"int":7},"favorite_color":{"string":"red"}}""")
+self.assertEquals(serializer.to_json({"name": "Lion"}),
+ """{"name":"Lion","favorite_number":null,"favorite_color":null}""")
+```
+## Another example:
+```python
+# need to serialize this data
+data = {
+ "ffloat": 1.0,
+ "funion_null": None,
+ "flong": 1L,
+ "fdouble": 2.0,
+ "ffixed": "1234567890123456",
+ "fint": 1,
+ "fstring": "hi there",
+ "frec": {
+ "subfint": 2
+ }
+}
+# according to this schema:
+schema_dict = {
+ "fields": [{"name": "fint", "type": "int"},
+ {"name": "flong", "type": "long"},
+ {"name": "fstring", "type": "string"},
+ {"name": "ffixed",
+ "size": 16,
+ "type": {"name": "fixed_16", "size": 16, "type": "fixed"}},
+ {"name": "frec",
+ "type": {"fields": [{"name": "subfint", "type": "int"}],
+ "name": "Rec",
+ "type": "record"}},
+ {"name": "funion_null", "type": ["int", "null"]},
+ {"name": "ffloat", "type": "float"},
+ {"name": "fdouble", "type": "double"}],
+ "name": "all_field",
+ "namespace": "com.some.thing",
+ "type": "record"
+}
+avro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())
+serializer = AvroJsonSerializer(avro_schema)
+json_str = serializer.to_json(data)
+print json_str
+> {"fint":1,"flong":1,"fstring":"hi there","ffixed":"1234567890123456","frec":{"subfint":2},"funion_null":null,"ffloat":1.0,"fdouble":2.0}
+```
+See [tests](avro_json_serializer/test/test_avro_json_serializer.py) for more examples.
+## How to run tests
+```bash
+python-avro-json-serializer$ virtualenv venv
+python-avro-json-serializer$ source venv/bin/activate
+(venv)python-avro-json-serializer$ pip install tox
+(venv)python-avro-json-serializer$ tox
+GLOB sdist-make: /Users/bngo/python-avro-json-serializer/setup.py
+py27 create: /Users/bngo/python-avro-json-serializer/.tox/py27
+py27 installdeps: nose, -rrequirements.txt
+py27 inst: /Users/bngo/python-avro-json-serializer/.tox/dist/avro_json_serializer-0.4.1.zip
+py27 installed: avro==1.7.6,avro-json-serializer==0.4.1,nose==1.3.7,simplejson==3.8.2,six==1.10.0
+py27 runtests: PYTHONHASHSEED='107331485'
+
+%package help
+Summary: Development documents and examples for avro-json-serializer
+Provides: python3-avro-json-serializer-doc
+%description help
+[![PyPI version](https://badge.fury.io/py/avro_json_serializer.png)](http://badge.fury.io/py/avro_json_serializer)
+[AvroJsonSerializer](avro_json_serializer/__init__.py#L28) serializes data into a JSON format using AVRO schema.
+Why do we need serializer instead of just dumping into JSON?
+* validation that your data matches the schema
+* serialization of unions (see [SimpleExample](#simple-example) below)
+* some Avro JSON deserializers expect fields in JSON in the same order as in the schema
+* serialization of `bytes` and `fixed` fields
+Binary distribution can be found on [pypi](https://pypi.python.org/pypi/avro_json_serializer/).
+## Simple example:
+```python
+schema_dict = {
+ "namespace": "example.avro",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ {"name": "name", "type": "string"},
+ {"name": "favorite_number", "type": ["int", "null"]},
+ {"name": "favorite_color", "type": ["string", "null"]}
+ ]
+}
+avro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())
+serializer = AvroJsonSerializer(avro_schema)
+self.assertEquals(serializer.to_json({"name": "Alyssa", "favorite_number": 256}),
+ """{"name":"Alyssa","favorite_number":{"int":256},"favorite_color":null}""")
+self.assertEquals(serializer.to_json({"name": "Ben", "favorite_number": 7, "favorite_color": "red"}),
+ """{"name":"Ben","favorite_number":{"int":7},"favorite_color":{"string":"red"}}""")
+self.assertEquals(serializer.to_json({"name": "Lion"}),
+ """{"name":"Lion","favorite_number":null,"favorite_color":null}""")
+```
+## Another example:
+```python
+# need to serialize this data
+data = {
+ "ffloat": 1.0,
+ "funion_null": None,
+ "flong": 1L,
+ "fdouble": 2.0,
+ "ffixed": "1234567890123456",
+ "fint": 1,
+ "fstring": "hi there",
+ "frec": {
+ "subfint": 2
+ }
+}
+# according to this schema:
+schema_dict = {
+ "fields": [{"name": "fint", "type": "int"},
+ {"name": "flong", "type": "long"},
+ {"name": "fstring", "type": "string"},
+ {"name": "ffixed",
+ "size": 16,
+ "type": {"name": "fixed_16", "size": 16, "type": "fixed"}},
+ {"name": "frec",
+ "type": {"fields": [{"name": "subfint", "type": "int"}],
+ "name": "Rec",
+ "type": "record"}},
+ {"name": "funion_null", "type": ["int", "null"]},
+ {"name": "ffloat", "type": "float"},
+ {"name": "fdouble", "type": "double"}],
+ "name": "all_field",
+ "namespace": "com.some.thing",
+ "type": "record"
+}
+avro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())
+serializer = AvroJsonSerializer(avro_schema)
+json_str = serializer.to_json(data)
+print json_str
+> {"fint":1,"flong":1,"fstring":"hi there","ffixed":"1234567890123456","frec":{"subfint":2},"funion_null":null,"ffloat":1.0,"fdouble":2.0}
+```
+See [tests](avro_json_serializer/test/test_avro_json_serializer.py) for more examples.
+## How to run tests
+```bash
+python-avro-json-serializer$ virtualenv venv
+python-avro-json-serializer$ source venv/bin/activate
+(venv)python-avro-json-serializer$ pip install tox
+(venv)python-avro-json-serializer$ tox
+GLOB sdist-make: /Users/bngo/python-avro-json-serializer/setup.py
+py27 create: /Users/bngo/python-avro-json-serializer/.tox/py27
+py27 installdeps: nose, -rrequirements.txt
+py27 inst: /Users/bngo/python-avro-json-serializer/.tox/dist/avro_json_serializer-0.4.1.zip
+py27 installed: avro==1.7.6,avro-json-serializer==0.4.1,nose==1.3.7,simplejson==3.8.2,six==1.10.0
+py27 runtests: PYTHONHASHSEED='107331485'
+
+%prep
+%autosetup -n avro-json-serializer-1.0.4
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-avro-json-serializer -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 1.0.4-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..c144150
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+bc81e0f8f10033cb14e22b451446335c avro_json_serializer-1.0.4.tar.gz