From d4a20f1c0096f7e54308c53628c57d2bdc668503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Wed, 26 May 2021 17:43:51 +0200 Subject: [PATCH] forgot about bools, v1.7 --- CHANGELOG.md | 1 + docs/conf.py | 2 +- docs/specification.rst | 2 ++ minijson/routines.pyx | 13 ++++++++++++- setup.py | 2 +- tests/test_minijson.py | 4 ++++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8733a44..6713db6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,4 @@ here's only the changelog for the version in development # v1.7 +* I totally forgot about booleans! diff --git a/docs/conf.py b/docs/conf.py index fb6fa39..429e388 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ copyright = '2021 Dronehub Group sp. z o. o.' author = 'Piotr MaĹlanka' # The full version, including alpha/beta/rc tags -release = '1.3' +release = '1.7' # -- General configuration --------------------------------------------------- diff --git a/docs/specification.rst b/docs/specification.rst index a64aebe..5fc538d 100644 --- a/docs/specification.rst +++ b/docs/specification.rst @@ -61,3 +61,5 @@ Type Value consists of: and then follow that many pairs of Values (key: value) * If value is 21, then next data is an unsigned short, and then follow that many pairs of Values (key: value) +* If value is 22, then it's True +* If value is 23, then it's False diff --git a/minijson/routines.pyx b/minijson/routines.pyx index 4447b04..bce59de 100644 --- a/minijson/routines.pyx +++ b/minijson/routines.pyx @@ -255,7 +255,12 @@ cpdef tuple parse(bytes data, int starting_position): elements, = STRUCT_H.unpack(data[starting_position+1:starting_position+3]) offset, e_dict = parse_sdict(data, elements, starting_position+3) return offset+3, e_dict - raise DecodingError('Unknown sequence type %s!' % (value_type, )) + elif value_type == 22: + return 1, True + elif value_type == 23: + return 1, False + else: + raise DecodingError('Unknown sequence type %s!' % (value_type, )) except (IndexError, struct.error) as e: raise DecodingError('String too short!') from e @@ -285,6 +290,12 @@ cpdef int dump(object data, cio: io.BytesIO) except -1: if data is None: cio.write(b'\x08') return 1 + elif data is True: + cio.write(b'\x16') + return 1 + elif data is False: + cio.write(b'\x17') + return 1 elif isinstance(data, str): length = len(data) if length < 128: diff --git a/setup.py b/setup.py index bc8e610..e3b1326 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ if 'DEBUG' in os.environ: directives['embedsignature'] = True -setup(version='1.7a1', +setup(version='1.7', packages=find_packages(include=['minijson', 'minijson.*']), ext_modules=build([Multibuild('minijson', find_pyx('minijson'), dont_snakehouse=dont_snakehouse), ], diff --git a/tests/test_minijson.py b/tests/test_minijson.py index 55dd3ea..522349e 100644 --- a/tests/test_minijson.py +++ b/tests/test_minijson.py @@ -26,6 +26,10 @@ class TestMiniJSON(unittest.TestCase): a[i] = i self.assertSameAfterDumpsAndLoads(a) + def test_booleans(self): + self.assertSameAfterDumpsAndLoads({'test': True, + 'test2': False}) + def test_string(self): a = 'test' b = 't'*128 -- GitLab