├── VERSION ├── tests ├── __init__.py ├── box │ ├── __init__.py │ └── test_box.py ├── kv │ ├── __init__.py │ └── test_kv.py ├── misc │ ├── __init__.py │ └── test_misc.py ├── io_bin │ ├── __init__.py │ └── test_io_bin.py ├── io_text │ ├── __init__.py │ └── test_io_text.py ├── serializer │ ├── __init__.py │ └── test_funcs.py ├── streaming │ ├── __init__.py │ ├── test_bin_streaming.py │ └── test_txt_streaming.py ├── validator │ └── __init__.py ├── deserializer │ ├── __init__.py │ ├── test_funcs.py │ ├── test_buffered_text_stream.py │ └── test_scanner.py ├── __main__.py └── test_imports.py ├── MANIFEST.in ├── docs └── api │ ├── MIKEDOC │ ├── modules │ └── paradict │ │ ├── __init__ │ │ ├── fields.md │ │ ├── class-Datatype.md │ │ ├── class-Validator.md │ │ ├── class-TypeRef.md │ │ ├── class-Packer.md │ │ └── class-Encoder.md │ │ ├── const │ │ └── __init__ │ │ │ ├── fields.md │ │ │ ├── README.md │ │ │ └── class-Datatype.md │ │ ├── validator │ │ └── __init__ │ │ │ ├── fields.md │ │ │ ├── class-Spec.md │ │ │ ├── funcs.md │ │ │ ├── README.md │ │ │ └── class-Validator.md │ │ ├── misc │ │ └── __init__ │ │ │ ├── README.md │ │ │ └── funcs.md │ │ ├── io_bin │ │ └── __init__ │ │ │ ├── README.md │ │ │ └── funcs.md │ │ ├── io_text │ │ └── __init__ │ │ │ ├── README.md │ │ │ └── funcs.md │ │ ├── serializer │ │ ├── __init__ │ │ │ ├── README.md │ │ │ └── funcs.md │ │ ├── encoder │ │ │ ├── fields.md │ │ │ ├── class-Context.md │ │ │ ├── funcs.md │ │ │ ├── README.md │ │ │ └── class-Encoder.md │ │ └── packer │ │ │ ├── README.md │ │ │ └── class-Packer.md │ │ ├── deserializer │ │ ├── __init__ │ │ │ ├── README.md │ │ │ └── funcs.md │ │ ├── buffered_text_stream │ │ │ ├── README.md │ │ │ └── class-BufferedTextStream.md │ │ ├── scanner │ │ │ ├── fields.md │ │ │ ├── README.md │ │ │ └── funcs.md │ │ ├── buffered_bin_stream │ │ │ ├── README.md │ │ │ └── class-BufferedBinStream.md │ │ ├── unpacker │ │ │ └── README.md │ │ └── decoder │ │ │ └── README.md │ │ ├── errors │ │ └── __init__ │ │ │ ├── class-Error.md │ │ │ ├── class-IndentError.md │ │ │ ├── class-ValidationError.md │ │ │ └── README.md │ │ ├── kv │ │ └── __init__ │ │ │ ├── README.md │ │ │ ├── funcs.md │ │ │ └── class-Info.md │ │ ├── xtypes │ │ └── __init__ │ │ │ ├── class-BinInt.md │ │ │ ├── class-OctInt.md │ │ │ ├── class-HexInt.md │ │ │ ├── class-Obj.md │ │ │ └── class-Grid.md │ │ ├── tags │ │ └── mappings │ │ │ ├── README.md │ │ │ └── fields.md │ │ └── typeref │ │ └── __init__ │ │ ├── README.md │ │ └── class-TypeRef.md │ └── README.md ├── setup.py ├── .pyrustic └── buildver │ └── build_report ├── .gitignore ├── src └── paradict │ ├── errors │ └── __init__.py │ ├── const │ └── __init__.py │ ├── __init__.py │ ├── io_bin │ └── __init__.py │ ├── serializer │ └── __init__.py │ ├── deserializer │ ├── buffered_text_stream.py │ ├── __init__.py │ └── scanner.py │ ├── __main__.py │ ├── xtypes │ └── __init__.py │ ├── kv │ └── __init__.py │ ├── io_text │ └── __init__.py │ └── tags │ └── mappings.py ├── mikedoc.kvf ├── pyproject.toml ├── LICENSE └── setup.cfg /VERSION: -------------------------------------------------------------------------------- 1 | 0.0.15 -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/box/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/kv/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/misc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/io_bin/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/io_text/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/serializer/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/streaming/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/validator/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/deserializer/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include VERSION 2 | recursive-include src * 3 | global-exclude *.py[cod] 4 | 5 | -------------------------------------------------------------------------------- /docs/api/MIKEDOC: -------------------------------------------------------------------------------- 1 | API Reference generated with [MikeDoc](https://github.com/pyrustic/mikedoc). 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # File generated by Setupinit 2 | import setuptools 3 | 4 | 5 | if __name__ == "__main__": 6 | setuptools.setup() 7 | -------------------------------------------------------------------------------- /.pyrustic/buildver/build_report: -------------------------------------------------------------------------------- 1 | 0.0.14 1733863703 2 | 0.0.13 1732907356 3 | 0.0.12 1732710709 4 | 0.0.11 1732574444 5 | 0.0.10 1732572803 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Python 2 | __pycache__/ 3 | *.py[cod] 4 | build/ 5 | dist/ 6 | *.egg-info/ 7 | 8 | # Environments 9 | venv/ 10 | env/ 11 | 12 | # PyCharm 13 | .idea/ 14 | 15 | -------------------------------------------------------------------------------- /src/paradict/errors/__init__.py: -------------------------------------------------------------------------------- 1 | class Error(Exception): 2 | pass 3 | 4 | 5 | class IndentError(Error): 6 | pass 7 | 8 | 9 | class ValidationError(Error): 10 | pass 11 | -------------------------------------------------------------------------------- /mikedoc.kvf: -------------------------------------------------------------------------------- 1 | # project name 2 | project_name = 'Paradict' 3 | 4 | # project's website or README 5 | project_url = '/README.md' 6 | 7 | # package directory (relative path) 8 | pkg_dir = 'src/paradict' 9 | 10 | # API directory (relative path) 11 | api_dir = 'docs/api' 12 | -------------------------------------------------------------------------------- /tests/__main__.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | def run_tests(): 5 | test_loader = unittest.defaultTestLoader 6 | test_suite = test_loader.discover("tests", pattern="test_*.py") 7 | test_runner = unittest.TextTestRunner(verbosity=1) 8 | test_runner.run(test_suite) 9 | 10 | 11 | if __name__ == "__main__": 12 | run_tests() 13 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # https://stackoverflow.com/q/76248637 (this is why setup.cfg/setup.py are still relevant !) 2 | # https://packaging.python.org/en/latest/guides/writing-pyproject-toml 3 | # https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html 4 | # https://setuptools.pypa.io/en/latest/userguide/datafiles.html 5 | 6 | [build-system] 7 | requires = ["setuptools"] 8 | build-backend = "setuptools.build_meta" 9 | -------------------------------------------------------------------------------- /tests/serializer/test_funcs.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestPackFunc(unittest.TestCase): 5 | """The 'pack' function is already heavily 6 | used in the 'packer' test module""" 7 | def test(self): 8 | self.assertTrue(True) 9 | 10 | 11 | class TestEncodeFunc(unittest.TestCase): 12 | """The 'encode' function is already heavily 13 | used in the 'encoder' test module""" 14 | def test(self): 15 | self.assertTrue(True) 16 | 17 | 18 | if __name__ == "__main__": 19 | unittest.main() 20 | -------------------------------------------------------------------------------- /tests/deserializer/test_funcs.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestDecodeFunc(unittest.TestCase): 5 | """The 'decode' function is already heavily 6 | used in the 'decoder' test module""" 7 | def test(self): 8 | self.assertTrue(True) 9 | 10 | 11 | class TestUnpackFunc(unittest.TestCase): 12 | """The 'unpack' function is already heavily 13 | used in the 'unpacker' test module""" 14 | def test(self): 15 | self.assertTrue(True) 16 | 17 | 18 | 19 | if __name__ == "__main__": 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/__init__/fields.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/__init__/README.md) | [Source](/src/paradict/__init__.py) 3 | 4 | # Fields within module 5 | > Module: [paradict.\_\_init\_\_](/docs/api/modules/paradict/__init__/README.md) 6 | 7 | Here are fields exposed in the module: 8 | 9 | | Field | Value | 10 | | --- | --- | 11 | | CONFIG\_MODE | `'c'` | 12 | | DATA\_MODE | `'d'` | 13 | 14 |

Back to top

15 | -------------------------------------------------------------------------------- /src/paradict/const/__init__.py: -------------------------------------------------------------------------------- 1 | # general constants 2 | from enum import unique, Enum 3 | 4 | 5 | @unique 6 | class Datatype(Enum): 7 | DICT = 1 8 | LIST = 2 9 | SET = 3 10 | OBJ = 4 11 | GRID = 5 12 | BOOL = 6 13 | STR = 7 14 | BIN = 8 15 | INT = 9 16 | FLOAT = 10 17 | COMPLEX = 11 18 | DATE = 12 19 | TIME = 13 20 | DATETIME = 14 21 | 22 | 23 | # Indent 24 | INDENT_WIDTH = 4 # Four spaces 25 | INDENT_STR = " " * INDENT_WIDTH 26 | 27 | # Paradict Epoch: 2020-01-01T00:00:00Z 28 | COVID_YEAR = 2020 29 | 30 | # modes for Textual Paradict 31 | DATA_MODE = "d" 32 | CONFIG_MODE = "c" 33 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/const/__init__/fields.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/const/__init__/README.md) | [Source](/src/paradict/const/__init__.py) 3 | 4 | # Fields within module 5 | > Module: [paradict.const.\_\_init\_\_](/docs/api/modules/paradict/const/__init__/README.md) 6 | 7 | Here are fields exposed in the module: 8 | 9 | | Field | Value | 10 | | --- | --- | 11 | | CONFIG\_MODE | `'c'` | 12 | | COVID\_YEAR | `2020` | 13 | | DATA\_MODE | `'d'` | 14 | | INDENT\_STR | `' '` | 15 | | INDENT\_WIDTH | `4` | 16 | 17 |

Back to top

18 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/validator/__init__/fields.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/validator/__init__/README.md) | [Source](/src/paradict/validator/__init__.py) 3 | 4 | # Fields within module 5 | > Module: [paradict.validator.\_\_init\_\_](/docs/api/modules/paradict/validator/__init__/README.md) 6 | 7 | Here are fields exposed in the module: 8 | 9 | | Field | Value | 10 | | --- | --- | 11 | | VALID\_DATATYPES | `('dict', 'list', 'set', 'obj', 'bin', 'bool', 'complex', 'date', 'datetime', 'float', 'grid', 'int', 'str', 'time')` | 12 | 13 |

Back to top

14 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/misc/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/misc/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.misc.\_\_init\_\_** 6 | 7 | Private miscellaneous functions and classes. 8 | 9 | ## Functions 10 | - [**All functions**](/docs/api/modules/paradict/misc/__init__/funcs.md) 11 | - [forge\_bin](/docs/api/modules/paradict/misc/__init__/funcs.md#forge_bin): items are int, bytes, bytearrays, or Nones, returns a bytearray 12 | - [stringify\_bin](/docs/api/modules/paradict/misc/__init__/funcs.md#stringify_bin): Good for debug. Stringify some binary data 13 | 14 |

Back to top

15 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/io_bin/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/io_bin/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.io\_bin.\_\_init\_\_** 6 | 7 | Load and dump binary Paradict from/to file 8 | 9 | ## Functions 10 | - [**All functions**](/docs/api/modules/paradict/io_bin/__init__/funcs.md) 11 | - [pack\_into](/docs/api/modules/paradict/io_bin/__init__/funcs.md#pack_into): Serialize a Python data object with the Paradict binary format then dump it in a file 12 | - [unpack\_from](/docs/api/modules/paradict/io_bin/__init__/funcs.md#unpack_from): Open a binary Paradict file then unpack its contents into Python dict 13 | 14 |

Back to top

15 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/io_text/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/io_text/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.io\_text.\_\_init\_\_** 6 | 7 | Load and dump text Paradict from/to file 8 | 9 | ## Functions 10 | - [**All functions**](/docs/api/modules/paradict/io_text/__init__/funcs.md) 11 | - [decode\_from](/docs/api/modules/paradict/io_text/__init__/funcs.md#decode_from): Open a textual Paradict file then read its contents into Python dict 12 | - [encode\_into](/docs/api/modules/paradict/io_text/__init__/funcs.md#encode_into): Serialize a Python dict object with the Paradict text format then write it to a file 13 | 14 |

Back to top

15 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/serializer/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.serializer.\_\_init\_\_** 6 | 7 | High-level functions to serialize Python dict in Paradict binary/text format 8 | 9 | ## Functions 10 | - [**All functions**](/docs/api/modules/paradict/serializer/__init__/funcs.md) 11 | - [encode](/docs/api/modules/paradict/serializer/__init__/funcs.md#encode): Serialize a Python dict object with the Paradict binary format 12 | - [pack](/docs/api/modules/paradict/serializer/__init__/funcs.md#pack): Serialize a Python dict object with the Paradict binary format 13 | 14 |

Back to top

15 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/deserializer/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.deserializer.\_\_init\_\_** 6 | 7 | High-level functions to deserialize Paradict binary/text data into a Python dict 8 | 9 | ## Functions 10 | - [**All functions**](/docs/api/modules/paradict/deserializer/__init__/funcs.md) 11 | - [decode](/docs/api/modules/paradict/deserializer/__init__/funcs.md#decode): Convert some textual Paradict data into a Python dictionary 12 | - [unpack](/docs/api/modules/paradict/deserializer/__init__/funcs.md#unpack): Convert some binary Paradict data into a Python dictionary 13 | 14 |

Back to top

15 | -------------------------------------------------------------------------------- /tests/deserializer/test_buffered_text_stream.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from paradict.deserializer.buffered_text_stream import BufferedTextStream 3 | 4 | 5 | class TestQueue(unittest.TestCase): 6 | 7 | def test_with_complete_data(self): 8 | s = "first line\nsecond line\n" 9 | queue = BufferedTextStream() 10 | r = put_and_get(queue, s) 11 | self.assertEqual(s, r) 12 | self.assertTrue(queue.is_empty()) 13 | 14 | def test_with_incomplete_data(self): 15 | s = "first line\nsecond lin" 16 | queue = BufferedTextStream() 17 | r = put_and_get(queue, s) 18 | self.assertEqual("first line\n", r) 19 | self.assertFalse(queue.is_empty()) 20 | 21 | 22 | def put_and_get(queue, s): 23 | queue.put(s) 24 | buffer = list() 25 | for s in queue.get_all(): 26 | buffer.append(s) 27 | return "".join(buffer) 28 | 29 | 30 | if __name__ == "__main__": 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/errors/__init__/class-Error.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/errors/__init__/README.md) | [Source](/src/paradict/errors/__init__.py) 3 | 4 | # Class Error 5 | > Module: [paradict.errors.\_\_init\_\_](/docs/api/modules/paradict/errors/__init__/README.md) 6 | > 7 | > Class: **Error** 8 | > 9 | > Inheritance: `Exception` 10 | 11 | Common base class for all non-exit exceptions. 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Value | 17 | | --- | --- | 18 | | \_\_init\_\_ | `` | 19 | | add\_note | `` | 20 | | args | `` | 21 | | with\_traceback | `` | 22 | 23 |

Back to top

24 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/misc/__init__/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/misc/__init__/README.md) | [Source](/src/paradict/misc/__init__.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.misc.\_\_init\_\_](/docs/api/modules/paradict/misc/__init__/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [forge\_bin](#forge_bin) 9 | - [stringify\_bin](#stringify_bin) 10 | 11 | ## forge\_bin 12 | items are int, bytes, bytearrays, or Nones, returns a bytearray 13 | 14 | ```python 15 | def forge_bin(*items): 16 | ... 17 | ``` 18 | 19 |

Back to top

20 | 21 | ## stringify\_bin 22 | Good for debug. Stringify some binary data 23 | 24 | ```python 25 | def stringify_bin(b, offset=0, width=None, spaced=False): 26 | ... 27 | ``` 28 | 29 |

Back to top

30 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/errors/__init__/class-IndentError.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/errors/__init__/README.md) | [Source](/src/paradict/errors/__init__.py) 3 | 4 | # Class IndentError 5 | > Module: [paradict.errors.\_\_init\_\_](/docs/api/modules/paradict/errors/__init__/README.md) 6 | > 7 | > Class: **IndentError** 8 | > 9 | > Inheritance: [paradict.errors.Error](/docs/api/modules/paradict/errors/__init__/class-Error.md) 10 | 11 | Common base class for all non-exit exceptions. 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Value | 17 | | --- | --- | 18 | | \_\_init\_\_ | `` | 19 | | add\_note | `` | 20 | | args | `` | 21 | | with\_traceback | `` | 22 | 23 |

Back to top

24 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/errors/__init__/class-ValidationError.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/errors/__init__/README.md) | [Source](/src/paradict/errors/__init__.py) 3 | 4 | # Class ValidationError 5 | > Module: [paradict.errors.\_\_init\_\_](/docs/api/modules/paradict/errors/__init__/README.md) 6 | > 7 | > Class: **ValidationError** 8 | > 9 | > Inheritance: [paradict.errors.Error](/docs/api/modules/paradict/errors/__init__/class-Error.md) 10 | 11 | Common base class for all non-exit exceptions. 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Value | 17 | | --- | --- | 18 | | \_\_init\_\_ | `` | 19 | | add\_note | `` | 20 | | args | `` | 21 | | with\_traceback | `` | 22 | 23 |

Back to top

24 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/kv/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/kv/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.kv.\_\_init\_\_** 6 | 7 | This module exposes the split function that will parse a valid key-value string 8 | 9 | ## Functions 10 | - [**All functions**](/docs/api/modules/paradict/kv/__init__/funcs.md) 11 | - [split](/docs/api/modules/paradict/kv/__init__/funcs.md#split): Split a non-empty string into key val. The string should follow one of these format: - data_mode format: key: value - config_mod... 12 | 13 |

Back to top

14 | 15 | ## Classes 16 | - [**Info**](/docs/api/modules/paradict/kv/__init__/class-Info.md): Info(key, val, sep, mode) 17 | - key: Alias for field number 0 18 | - val: Alias for field number 1 19 | - sep: Alias for field number 2 20 | - mode: Alias for field number 3 21 | 22 |

Back to top

23 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/const/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/const/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.const.\_\_init\_\_** 6 | 7 | No docstring. 8 | 9 | ## Fields 10 | - [**All fields**](/docs/api/modules/paradict/const/__init__/fields.md) 11 | - CONFIG\_MODE = `'c'` 12 | - COVID\_YEAR = `2020` 13 | - DATA\_MODE = `'d'` 14 | - INDENT\_STR = `' '` 15 | - INDENT\_WIDTH = `4` 16 | 17 |

Back to top

18 | 19 | ## Classes 20 | - [**Datatype**](/docs/api/modules/paradict/const/__init__/class-Datatype.md): Create a collection of name/value pairs. 21 | - DICT = `1` 22 | - LIST = `2` 23 | - SET = `3` 24 | - OBJ = `4` 25 | - GRID = `5` 26 | - BOOL = `6` 27 | - STR = `7` 28 | - BIN = `8` 29 | - INT = `9` 30 | - FLOAT = `10` 31 | - COMPLEX = `11` 32 | - DATE = `12` 33 | - TIME = `13` 34 | - DATETIME = `14` 35 | 36 |

Back to top

37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023, 2024 Pyrustic Architect 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/kv/__init__/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/kv/__init__/README.md) | [Source](/src/paradict/kv/__init__.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.kv.\_\_init\_\_](/docs/api/modules/paradict/kv/__init__/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [split](#split) 9 | 10 | ## split 11 | Split a non-empty string into key val. 12 | The string should follow one of these format: 13 | - data_mode format: key: value 14 | - config_mode format: key = value 15 | 16 | ```python 17 | def split(val): 18 | ... 19 | ``` 20 | 21 | | Parameter | Description | 22 | | --- | --- | 23 | | val | non-empty string | 24 | 25 | ### Value to return 26 | Return an Info namedtuple made of: key, val, sep, and mode attributes. 27 | The key and val are strings. The sep is either ":" or "=". 28 | The mode is either paradict.const.DATA_MODE or paradict.const.CONFIG_MODE. 29 | Note that if the sep is a colon, it means that the mode is DATA_MODE. 30 | 31 |

Back to top

32 | -------------------------------------------------------------------------------- /src/paradict/__init__.py: -------------------------------------------------------------------------------- 1 | from paradict.serializer import encode, pack 2 | from paradict.serializer.encoder import Encoder 3 | from paradict.serializer.packer import Packer 4 | from paradict.deserializer import decode, unpack 5 | from paradict.deserializer.scanner import scan 6 | from paradict.deserializer.decoder import Decoder 7 | from paradict.deserializer.unpacker import Unpacker 8 | from paradict.io_text import encode_into, decode_from 9 | from paradict.io_bin import pack_into, unpack_from 10 | from paradict.typeref import TypeRef 11 | from paradict.validator import is_valid, Validator 12 | from paradict.kv import split as split_kv 13 | from paradict.misc import forge_bin, stringify_bin 14 | from paradict.const import CONFIG_MODE, DATA_MODE, Datatype 15 | 16 | 17 | __all__ = ["encode", "decode", 18 | "encode_into", "decode_from", 19 | "pack", "unpack", "scan", 20 | "pack_into", "unpack_from", 21 | "is_valid", "split_kv", 22 | "forge_bin", "stringify_bin", 23 | "Encoder", "Decoder", 24 | "Packer", "Unpacker", "Datatype", 25 | "TypeRef", "Validator", "CONFIG_MODE", "DATA_MODE"] 26 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/encoder/fields.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/serializer/encoder/README.md) | [Source](/src/paradict/serializer/encoder.py) 3 | 4 | # Fields within module 5 | > Module: [paradict.serializer.encoder](/docs/api/modules/paradict/serializer/encoder/README.md) 6 | 7 | Here are fields exposed in the module: 8 | 9 | | Field | Value | 10 | | --- | --- | 11 | | base64 | `` | 12 | | const | `` | 13 | | errors | `` | 14 | | misc | `` | 15 | | os | `` | 16 | | re | `` | 17 | | xtypes | `` | 18 | 19 |

Back to top

20 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = paradict 3 | version = file: VERSION 4 | url = https://github.com/pyrustic/paradict 5 | author = Pyrustic Architect 6 | author_email = rusticalex@yahoo.com 7 | maintainer = Pyrustic Architect 8 | maintainer_email = rusticalex@yahoo.com 9 | description = Streamable multi-format serialization 10 | long_description = file: README.md 11 | long_description_content_type = text/markdown 12 | license = MIT 13 | keywords = 14 | pyrustic 15 | # https://pypi.org/classifiers/ 16 | # Development Status :: 3 - Alpha 17 | # Development Status :: 4 - Beta 18 | # Development Status :: 5 - Production/Stable 19 | classifiers = 20 | Programming Language :: Python 21 | Programming Language :: Python :: 3 22 | License :: OSI Approved :: MIT License 23 | Operating System :: OS Independent 24 | Intended Audience :: Developers 25 | Development Status :: 4 - Beta 26 | 27 | [options] 28 | python_requires = >=3.5 29 | package_dir = 30 | = src 31 | packages = find: 32 | include_package_data = true 33 | zip_safe = false 34 | install_requires = 35 | 36 | [options.packages.find] 37 | where = src 38 | 39 | [options.entry_points] 40 | console_scripts = 41 | paradict = paradict.__main__:main 42 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/xtypes/__init__/class-BinInt.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/xtypes/__init__/README.md) | [Source](/src/paradict/xtypes/__init__.py) 3 | 4 | # Class BinInt 5 | > Module: [paradict.xtypes.\_\_init\_\_](/docs/api/modules/paradict/xtypes/__init__/README.md) 6 | > 7 | > Class: **BinInt** 8 | > 9 | > Inheritance: `int` 10 | 11 | Box to hold binary integer 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Value | 17 | | --- | --- | 18 | | as\_integer\_ratio | `` | 19 | | bit\_count | `` | 20 | | bit\_length | `` | 21 | | conjugate | `` | 22 | | denominator | `` | 23 | | from\_bytes | `` | 24 | | imag | `` | 25 | | is\_integer | `` | 26 | | numerator | `` | 27 | | real | `` | 28 | | to\_bytes | `` | 29 | 30 |

Back to top

31 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/xtypes/__init__/class-OctInt.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/xtypes/__init__/README.md) | [Source](/src/paradict/xtypes/__init__.py) 3 | 4 | # Class OctInt 5 | > Module: [paradict.xtypes.\_\_init\_\_](/docs/api/modules/paradict/xtypes/__init__/README.md) 6 | > 7 | > Class: **OctInt** 8 | > 9 | > Inheritance: `int` 10 | 11 | Box to hold octal integer 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Value | 17 | | --- | --- | 18 | | as\_integer\_ratio | `` | 19 | | bit\_count | `` | 20 | | bit\_length | `` | 21 | | conjugate | `` | 22 | | denominator | `` | 23 | | from\_bytes | `` | 24 | | imag | `` | 25 | | is\_integer | `` | 26 | | numerator | `` | 27 | | real | `` | 28 | | to\_bytes | `` | 29 | 30 |

Back to top

31 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/xtypes/__init__/class-HexInt.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/xtypes/__init__/README.md) | [Source](/src/paradict/xtypes/__init__.py) 3 | 4 | # Class HexInt 5 | > Module: [paradict.xtypes.\_\_init\_\_](/docs/api/modules/paradict/xtypes/__init__/README.md) 6 | > 7 | > Class: **HexInt** 8 | > 9 | > Inheritance: `int` 10 | 11 | Box to hold hexadecimal integer 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Value | 17 | | --- | --- | 18 | | as\_integer\_ratio | `` | 19 | | bit\_count | `` | 20 | | bit\_length | `` | 21 | | conjugate | `` | 22 | | denominator | `` | 23 | | from\_bytes | `` | 24 | | imag | `` | 25 | | is\_integer | `` | 26 | | numerator | `` | 27 | | real | `` | 28 | | to\_bytes | `` | 29 | 30 |

Back to top

31 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/buffered_text_stream/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/deserializer/buffered_text_stream.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.deserializer.buffered\_text\_stream** 6 | 7 | A FIFO queue for processing textual Paradict data 8 | 9 | ## Classes 10 | - [**BufferedTextStream**](/docs/api/modules/paradict/deserializer/buffered_text_stream/class-BufferedTextStream.md): A FIFO queue for processing textual Paradict data 11 | - [get](/docs/api/modules/paradict/deserializer/buffered_text_stream/class-BufferedTextStream.md#get): No docstring. 12 | - [get\_all](/docs/api/modules/paradict/deserializer/buffered_text_stream/class-BufferedTextStream.md#get_all): Generator for iteratively getting each line composing the textual data stored in the buffer. Note that lines yie... 13 | - [is\_empty](/docs/api/modules/paradict/deserializer/buffered_text_stream/class-BufferedTextStream.md#is_empty): No docstring. 14 | - [put](/docs/api/modules/paradict/deserializer/buffered_text_stream/class-BufferedTextStream.md#put): Store textual data in the buffer. This data will then be iteratively extracted by the 'get' method, line by line. ... 15 | 16 |

Back to top

17 | -------------------------------------------------------------------------------- /tests/test_imports.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestImports(unittest.TestCase): 5 | 6 | def test_import_funcs(self): 7 | try: 8 | # import functions 9 | from paradict import encode 10 | from paradict import decode 11 | from paradict import encode_into 12 | from paradict import decode_from 13 | from paradict import pack 14 | from paradict import unpack 15 | from paradict import pack_into 16 | from paradict import unpack_from 17 | from paradict import scan 18 | from paradict import forge_bin 19 | from paradict import stringify_bin 20 | from paradict import is_valid 21 | from paradict import split_kv 22 | except ImportError: 23 | self.assertTrue(False) 24 | 25 | def test_import_classes(self): 26 | try: 27 | # import classes 28 | from paradict import Encoder 29 | from paradict import Decoder 30 | from paradict import Packer 31 | from paradict import Unpacker 32 | from paradict import TypeRef 33 | from paradict import Validator 34 | from paradict import Datatype 35 | except ImportError: 36 | self.assertTrue(False) 37 | 38 | 39 | if __name__ == "__main__": 40 | unittest.main() 41 | -------------------------------------------------------------------------------- /tests/io_bin/test_io_bin.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import pathlib 3 | import tempfile 4 | from paradict import pack 5 | from paradict.io_bin import unpack_from, pack_into 6 | 7 | 8 | class TestUnpackFromFunc(unittest.TestCase): 9 | 10 | def setUp(self): 11 | file = tempfile.NamedTemporaryFile(delete=False) 12 | file.close() 13 | self._path = file.name 14 | 15 | def tearDown(self): 16 | pathlib.Path(self._path).unlink() 17 | 18 | def test(self): 19 | data = {0: "hello world", "pi": 3.14} 20 | with open(self._path, "wb") as file: 21 | pack_into(data, file) 22 | with open(self._path, "rb") as file: 23 | r = unpack_from(file) 24 | expected = data 25 | self.assertEqual(expected, r) 26 | 27 | 28 | class TestPackIntoFunc(unittest.TestCase): 29 | 30 | def setUp(self): 31 | file = tempfile.NamedTemporaryFile(delete=False) 32 | file.close() 33 | self._path = file.name 34 | 35 | def tearDown(self): 36 | pathlib.Path(self._path).unlink() 37 | 38 | def test(self): 39 | data = {0: "hello world", "pi": 3.14} 40 | with open(self._path, "wb") as file: 41 | pack_into(data, file) 42 | with open(self._path, "rb") as file: 43 | r = file.read() 44 | expected = pack(data) 45 | self.assertEqual(expected, r) 46 | 47 | 48 | if __name__ == "__main__": 49 | unittest.main() 50 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/scanner/fields.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/deserializer/scanner/README.md) | [Source](/src/paradict/deserializer/scanner.py) 3 | 4 | # Fields within module 5 | > Module: [paradict.deserializer.scanner](/docs/api/modules/paradict/deserializer/scanner/README.md) 6 | 7 | Here are fields exposed in the module: 8 | 9 | | Field | Value | 10 | | --- | --- | 11 | | BIN\_TO\_SIZE | `{b'(': 1, b')': 2, b'*': 3, b'+': 4, b',': 5}` | 12 | | NINT\_TO\_SIZE | `{b'7': 1, b'8': 2, b'9': 3, b':': 4, b';': 5, b'<': 6, b'=': 7, b'>': 8}` | 13 | | PINT\_TO\_SIZE | `{b'-': 1, b'.': 2, b'/': 3, b'0': 4, b'1': 5, b'2': 6, b'3': 7, b'4': 8}` | 14 | | STR\_TO\_SIZE | `{b'A': 1, b'B': 2, b'C': 3, b'D': 4, b'E': 5, b'F': 6, b'G': 7, b'H': 8, b'I': 9, b'J': 10, b'K': 11, b'L': 12, b'M': 13, b'N': 14, b'O': 15, b'P': 16, b'Q': 17, b'R': 18, b'S': 19, b'T': 20, b'U': 21, b'V': 22, b'W': 23, b'X': 24, b'Y': 25, b'Z': 26, b'[': 27, b'\\': 28, b']': 29, b'^': 30, b'_': 31, b'`': 32}` | 15 | | VARSTR\_TO\_SIZE | `{b'b': 1, b'c': 2, b'd': 3, b'e': 4, b'f': 5}` | 16 | | os | `` | 17 | | paradict | `` | 18 | | tags | `` | 19 | 20 |

Back to top

21 | -------------------------------------------------------------------------------- /tests/io_text/test_io_text.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import pathlib 3 | import tempfile 4 | from paradict import encode 5 | from paradict.io_text import decode_from, encode_into 6 | 7 | 8 | class TestDecodeFromFunc(unittest.TestCase): 9 | 10 | def setUp(self): 11 | file = tempfile.NamedTemporaryFile(delete=False) 12 | file.close() 13 | self._path = file.name 14 | 15 | def tearDown(self): 16 | pathlib.Path(self._path).unlink() 17 | 18 | def test(self): 19 | data = {0: "hello world", "pi": 3.14} 20 | with open(self._path, "w", encoding="utf-8") as file: 21 | encode_into(data, file) 22 | with open(self._path, "r", encoding="utf-8") as file: 23 | r = decode_from(file) 24 | expected = data 25 | self.assertEqual(expected, r) 26 | 27 | 28 | class TestEncodeIntoFunc(unittest.TestCase): 29 | 30 | def setUp(self): 31 | file = tempfile.NamedTemporaryFile(delete=False) 32 | file.close() 33 | self._path = file.name 34 | 35 | def tearDown(self): 36 | pathlib.Path(self._path).unlink() 37 | 38 | def test(self): 39 | data = {0: "hello world", "pi": 3.14} 40 | with open(self._path, "w", encoding="utf-8") as file: 41 | encode_into(data, file) 42 | with open(self._path, "r", encoding="utf-8") as file: 43 | r = file.read() 44 | expected = encode(data) + "\n" 45 | self.assertEqual(expected, r) 46 | 47 | 48 | if __name__ == "__main__": 49 | unittest.main() 50 | -------------------------------------------------------------------------------- /tests/streaming/test_bin_streaming.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from paradict.serializer.packer import Packer 3 | from paradict.deserializer.unpacker import Unpacker 4 | 5 | 6 | class TestBinStreaming(unittest.TestCase): 7 | 8 | def test(self): 9 | # This stream is made of messages 10 | # Each message is a dictionary that serves as envelope 11 | stream = [{0: "a"}, {0: "b"}, {0: "c"}] 12 | # Result will hold the unpacked messages 13 | result = list() 14 | # instantiate packer and unpacker 15 | packer = Packer() 16 | # the receiver takes as argument the reference to the unpacker 17 | unpacker = Unpacker(receiver=lambda ref: result.append(ref.data)) 18 | # iterate over the stream to pack each message into datums 19 | # that will feed the unpacker which will call the receiver 20 | # after each complete unpacking of a message. 21 | # The unpacker holds a reference to the latest 22 | # unpacked message via the "unpacker.data" property 23 | for i, msg in enumerate(stream): 24 | for datum in packer.pack(msg): 25 | unpacker.feed(datum) 26 | # check if datum is well unpacked 27 | with self.subTest("Message At Index: {}".format(i)): 28 | # unpacker.data holds unpacked data 29 | self.assertEqual(msg, unpacker.data) 30 | # check if the original stream contents is mirrored in 31 | # the result variable 32 | self.assertEqual(stream, result) 33 | 34 | 35 | if __name__ == "__main__": 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /tests/streaming/test_txt_streaming.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from paradict.serializer.encoder import Encoder 3 | from paradict.deserializer.decoder import Decoder 4 | 5 | 6 | class TestTxtStreaming(unittest.TestCase): 7 | 8 | def test(self): 9 | # This stream is made of messages 10 | # Each message is a dictionary that serves as envelope 11 | stream = [{0: "a"}, {0: "b"}, {0: "c"}] 12 | # Result will hold the unpacked messages 13 | result = list() 14 | # instantiate encoder and decoder 15 | encoder = Encoder() 16 | # the receiver takes as argument the reference to the decoder 17 | decoder = Decoder(receiver=lambda ref: result.append(ref.data)) 18 | # iterate over the stream to pack each message into datums 19 | # that will feed the decoder which will call the receiver 20 | # after each complete unpacking of a message. 21 | # The decoder holds a reference to the latest 22 | # unpacked message via the "decoder.data" property 23 | for i, msg in enumerate(stream): 24 | for line in encoder.encode(msg): 25 | decoder.feed(line + "\n") 26 | decoder.feed("===\n") 27 | # check if datum is well unpacked 28 | with self.subTest("Message At Index: {}".format(i)): 29 | # decoder.data holds unpacked data 30 | self.assertEqual(msg, decoder.data) 31 | # check if the original stream contents is mirrored in 32 | # the result variable 33 | self.assertEqual(stream, result) 34 | 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/kv/__init__/class-Info.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/kv/__init__/README.md) | [Source](/src/paradict/kv/__init__.py) 3 | 4 | # Class Info 5 | > Module: [paradict.kv.\_\_init\_\_](/docs/api/modules/paradict/kv/__init__/README.md) 6 | > 7 | > Class: **Info** 8 | > 9 | > Inheritance: `tuple` 10 | 11 | Info(key, val, sep, mode) 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Description | 17 | | --- | --- | 18 | | key | Alias for field number 0 | 19 | | val | Alias for field number 1 | 20 | | sep | Alias for field number 2 | 21 | | mode | Alias for field number 3 | 22 | 23 |

Back to top

24 | 25 | # Methods within class 26 | Here are methods exposed in the class: 27 | - [\_asdict](#_asdict) 28 | - [\_make](#_make) 29 | - [\_replace](#_replace) 30 | 31 | ## \_asdict 32 | Return a new dict which maps field names to their values. 33 | 34 | ```python 35 | def _asdict(self): 36 | ... 37 | ``` 38 | 39 |

Back to top

40 | 41 | ## \_make 42 | Make a new Info object from a sequence or iterable 43 | 44 | ```python 45 | @classmethod 46 | def _make(iterable): 47 | ... 48 | ``` 49 | 50 |

Back to top

51 | 52 | ## \_replace 53 | Return a new Info object replacing specified fields with new values 54 | 55 | ```python 56 | def _replace(self, /, **kwds): 57 | ... 58 | ``` 59 | 60 |

Back to top

61 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/encoder/class-Context.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/serializer/encoder/README.md) | [Source](/src/paradict/serializer/encoder.py) 3 | 4 | # Class Context 5 | > Module: [paradict.serializer.encoder](/docs/api/modules/paradict/serializer/encoder/README.md) 6 | > 7 | > Class: **Context** 8 | > 9 | > Inheritance: `tuple` 10 | 11 | Context(name, collection, indents) 12 | 13 | ## Fields table 14 | Here are fields exposed in the class: 15 | 16 | | Field | Description | 17 | | --- | --- | 18 | | name | Alias for field number 0 | 19 | | collection | Alias for field number 1 | 20 | | indents | Alias for field number 2 | 21 | 22 |

Back to top

23 | 24 | # Methods within class 25 | Here are methods exposed in the class: 26 | - [\_asdict](#_asdict) 27 | - [\_make](#_make) 28 | - [\_replace](#_replace) 29 | 30 | ## \_asdict 31 | Return a new dict which maps field names to their values. 32 | 33 | ```python 34 | def _asdict(self): 35 | ... 36 | ``` 37 | 38 |

Back to top

39 | 40 | ## \_make 41 | Make a new Context object from a sequence or iterable 42 | 43 | ```python 44 | @classmethod 45 | def _make(iterable): 46 | ... 47 | ``` 48 | 49 |

Back to top

50 | 51 | ## \_replace 52 | Return a new Context object replacing specified fields with new values 53 | 54 | ```python 55 | def _replace(self, /, **kwds): 56 | ... 57 | ``` 58 | 59 |

Back to top

60 | -------------------------------------------------------------------------------- /src/paradict/io_bin/__init__.py: -------------------------------------------------------------------------------- 1 | """Load and dump binary Paradict from/to file""" 2 | from paradict.serializer.packer import Packer 3 | from paradict.deserializer.unpacker import Unpacker 4 | 5 | 6 | __all__ = ["unpack_from", "pack_into"] 7 | 8 | 9 | def unpack_from(file, type_ref=None, receiver=None, 10 | obj_builder=None): 11 | """ 12 | Open a binary Paradict file then unpack its contents into Python dict 13 | 14 | [param] 15 | - file: bin file object 16 | - type_ref: optional TypeRef object 17 | - receiver: callback function that will be called at the end of conversion. 18 | This callback function accepts the Decoder instance as argument 19 | - obj_builder: function that accepts a paradict.xtypes.Obj container and 20 | returns a fresh new Python object 21 | 22 | [return] 23 | Return the newly built Python object 24 | """ 25 | unpacker = Unpacker(type_ref=type_ref, 26 | receiver=receiver, 27 | obj_builder=obj_builder) 28 | chunk_size = 1024 29 | while True: 30 | r = file.read(chunk_size) 31 | if not r: 32 | break 33 | unpacker.feed(r) 34 | return unpacker.data 35 | 36 | 37 | def pack_into(data, file, *, type_ref=None): 38 | """ 39 | Serialize a Python data object with the Paradict binary format 40 | then dump it in a file 41 | 42 | [param] 43 | - data: Python data object 44 | - file: binary file object 45 | - type_ref: optional TypeRef object 46 | - dict_only: boolean to enforce dict as root 47 | """ 48 | packer = Packer(type_ref=type_ref) 49 | for r in packer.pack(data): 50 | file.write(r) 51 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/io_bin/__init__/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/io_bin/__init__/README.md) | [Source](/src/paradict/io_bin/__init__.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.io\_bin.\_\_init\_\_](/docs/api/modules/paradict/io_bin/__init__/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [pack\_into](#pack_into) 9 | - [unpack\_from](#unpack_from) 10 | 11 | ## pack\_into 12 | Serialize a Python data object with the Paradict binary format 13 | then dump it in a file 14 | 15 | ```python 16 | def pack_into(data, file, *, type_ref=None): 17 | ... 18 | ``` 19 | 20 | | Parameter | Description | 21 | | --- | --- | 22 | | data | Python data object | 23 | | file | binary file object | 24 | | type\_ref | optional TypeRef object | 25 | | dict\_only | boolean to enforce dict as root | 26 | 27 |

Back to top

28 | 29 | ## unpack\_from 30 | Open a binary Paradict file then unpack its contents into Python dict 31 | 32 | ```python 33 | def unpack_from(file, type_ref=None, receiver=None, obj_builder=None): 34 | ... 35 | ``` 36 | 37 | | Parameter | Description | 38 | | --- | --- | 39 | | file | bin file object | 40 | | type\_ref | optional TypeRef object | 41 | | receiver | callback function that will be called at the end of conversion. This callback function accepts the Decoder instance as argument | 42 | | obj\_builder | function that accepts a paradict.xtypes.Obj container and returns a fresh new Python object | 43 | 44 | ### Value to return 45 | Return the newly built Python object 46 | 47 |

Back to top

48 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/validator/__init__/class-Spec.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/validator/__init__/README.md) | [Source](/src/paradict/validator/__init__.py) 3 | 4 | # Class Spec 5 | > Module: [paradict.validator.\_\_init\_\_](/docs/api/modules/paradict/validator/__init__/README.md) 6 | > 7 | > Class: **Spec** 8 | > 9 | > Inheritance: `object` 10 | 11 | A Spec can be used to form a schema along with string-types. 12 | The particularity of a Spec is that it can carry a checker that 13 | is a function to serve as an extra programmatic validation 14 | 15 | ## Properties table 16 | Here are properties exposed in the class: 17 | 18 | | Property | Methods | Description | 19 | | --- | --- | --- | 20 | | checker | _getter_ | No docstring. | 21 | | datatype | _getter_ | No docstring. | 22 | 23 |

Back to top

24 | 25 | # Methods within class 26 | Here are methods exposed in the class: 27 | - [\_\_init\_\_](#__init__) 28 | 29 | ## \_\_init\_\_ 30 | Init 31 | 32 | ```python 33 | def __init__(self, datatype, checker=None): 34 | ... 35 | ``` 36 | 37 | | Parameter | Description | 38 | | --- | --- | 39 | | datatype | a string representing a valid datatype. Check the VALID_DATATYPES variable to discover valid types. | 40 | | checker | an optional function that will be called with passed as argument, the specific data it should check. This function should return a boolean to validate this piece of data | 41 | 42 | ### Exceptions table 43 | The table below outlines exceptions that may occur. 44 | 45 | | Exception | Circumstance | 46 | | --- | --- | 47 | | ValidationError | raised if the datatype isn't a valid one | 48 | 49 |

Back to top

50 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/__init__/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/serializer/__init__/README.md) | [Source](/src/paradict/serializer/__init__.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.serializer.\_\_init\_\_](/docs/api/modules/paradict/serializer/__init__/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [encode](#encode) 9 | - [pack](#pack) 10 | 11 | ## encode 12 | Serialize a Python dict object with the Paradict binary format 13 | 14 | ```python 15 | def encode(data, *, mode='d', type_ref=None, bin_to_text=True, root_dir=None, attachments_dir='attachments'): 16 | ... 17 | ``` 18 | 19 | | Parameter | Description | 20 | | --- | --- | 21 | | data | Python dict | 22 | | mode | either const.DATA_MODE or const.CONFIG_MODE. Defaults to DATA_MODE. | 23 | | type\_ref | optional TypeRef object | 24 | | bin\_to\_text | boolean to tell whether bin data should be converted into text or not | 25 | | root\_dir | root directory in which the attachments dir is supposed to be | 26 | | attachments\_dir | attachments directory. This is a path that is relative to the root dir. Note that relative paths should use a slash as separator. | 27 | 28 | ### Value to return 29 | Return a string in the Paradict text format 30 | 31 |

Back to top

32 | 33 | ## pack 34 | Serialize a Python dict object with the Paradict binary format 35 | 36 | ```python 37 | def pack(data, *, type_ref=None, dict_only=False): 38 | ... 39 | ``` 40 | 41 | | Parameter | Description | 42 | | --- | --- | 43 | | data | Python data object | 44 | | type\_ref | optional TypeRef object | 45 | | dict\_only | boolean to enforce dict as root | 46 | 47 | ### Value to return 48 | Return a Python bytes object packed in the Paradict binary format 49 | 50 |

Back to top

51 | -------------------------------------------------------------------------------- /src/paradict/serializer/__init__.py: -------------------------------------------------------------------------------- 1 | """High-level functions to serialize Python dict in Paradict binary/text format""" 2 | from paradict.serializer.encoder import Encoder 3 | from paradict.serializer.packer import Packer 4 | from paradict import const 5 | 6 | 7 | __all__ = ["encode", "pack"] 8 | 9 | 10 | def encode(data, *, mode=const.DATA_MODE, type_ref=None, 11 | bin_to_text=True, root_dir=None, attachments_dir="attachments"): 12 | """ 13 | Serialize a Python dict object with the Paradict binary format 14 | 15 | [param] 16 | - data: Python dict 17 | - mode: either const.DATA_MODE or const.CONFIG_MODE. Defaults to DATA_MODE. 18 | - type_ref: optional TypeRef object 19 | - bin_to_text: boolean to tell whether bin data should be converted into text or not 20 | - root_dir: root directory in which the attachments dir is supposed to be 21 | - attachments_dir: attachments directory. This is a path that is relative to the root dir. 22 | Note that relative paths should use a slash as separator. 23 | 24 | [return] 25 | Return a string in the Paradict text format 26 | """ 27 | encoder = Encoder(mode=mode, type_ref=type_ref, 28 | bin_to_text=bin_to_text, root_dir=root_dir, 29 | attachments_dir=attachments_dir) 30 | lines = list() 31 | for r in encoder.encode(data): 32 | lines.append(r) 33 | return "\n".join(lines) 34 | 35 | 36 | def pack(data, *, type_ref=None, dict_only=False): 37 | """ 38 | Serialize a Python dict object with the Paradict binary format 39 | 40 | [param] 41 | - data: Python data object 42 | - type_ref: optional TypeRef object 43 | - dict_only: boolean to enforce dict as root 44 | 45 | [return] 46 | Return a Python bytes object packed in the Paradict binary format 47 | """ 48 | packer = Packer(type_ref=type_ref, dict_only=dict_only) 49 | buffer = bytearray() 50 | for r in packer.pack(data): 51 | buffer.extend(r) 52 | return bytes(buffer) 53 | -------------------------------------------------------------------------------- /src/paradict/deserializer/buffered_text_stream.py: -------------------------------------------------------------------------------- 1 | """A FIFO queue for processing textual Paradict data""" 2 | from collections import namedtuple 3 | 4 | 5 | __all__ = ["BufferedTextStream"] 6 | 7 | 8 | class BufferedTextStream: 9 | """A FIFO queue for processing textual Paradict data""" 10 | def __init__(self): 11 | self._buffer = list() 12 | self._partial_s = "" 13 | 14 | def is_empty(self): 15 | if not self._buffer and not self._partial_s: 16 | return True 17 | return False 18 | 19 | def put(self, s): 20 | """Store textual data in the buffer. This data will then be iteratively 21 | extracted by the 'get' method, line by line. 22 | Note: make sure that each line is ended with a newline '\n' character""" 23 | if not s: 24 | return 25 | # split lines and store first and last 26 | lines = s.splitlines(keepends=True) 27 | first = lines.pop(0) 28 | try: 29 | last = lines.pop() 30 | except IndexError as e: 31 | last = "" 32 | # handle self._partial_s 33 | if self._partial_s: 34 | self._buffer.append(self._partial_s + first) 35 | self._partial_s = "" 36 | else: 37 | self._buffer.append(first) 38 | # update buffer with splitted lines 39 | self._buffer.extend(lines) 40 | # update buffer/partial_s with the value of last 41 | if last: 42 | if last.endswith("\n"): 43 | self._buffer.append(last) 44 | else: 45 | self._partial_s = last 46 | 47 | def get(self): 48 | if self._buffer: 49 | return self._buffer.pop(0) 50 | 51 | def get_all(self): 52 | """Generator for iteratively getting each line composing the 53 | textual data stored in the buffer. 54 | Note that lines yielded won't end with a newline '\n' character""" 55 | while self._buffer: 56 | yield self._buffer.pop(0) 57 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/errors/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/errors/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.errors.\_\_init\_\_** 6 | 7 | No docstring. 8 | 9 | ## Classes 10 | - [**Error**](/docs/api/modules/paradict/errors/__init__/class-Error.md): Common base class for all non-exit exceptions. 11 | - [add\_note](/docs/api/modules/paradict/errors/__init__/class-Error.md#fields-table) = `` 12 | - [args](/docs/api/modules/paradict/errors/__init__/class-Error.md#fields-table) = `` 13 | - [with\_traceback](/docs/api/modules/paradict/errors/__init__/class-Error.md#fields-table) = `` 14 | - [**IndentError**](/docs/api/modules/paradict/errors/__init__/class-IndentError.md): Common base class for all non-exit exceptions. 15 | - [add\_note](/docs/api/modules/paradict/errors/__init__/class-IndentError.md#fields-table) = `` 16 | - [args](/docs/api/modules/paradict/errors/__init__/class-IndentError.md#fields-table) = `` 17 | - [with\_traceback](/docs/api/modules/paradict/errors/__init__/class-IndentError.md#fields-table) = `` 18 | - [**ValidationError**](/docs/api/modules/paradict/errors/__init__/class-ValidationError.md): Common base class for all non-exit exceptions. 19 | - [add\_note](/docs/api/modules/paradict/errors/__init__/class-ValidationError.md#fields-table) = `` 20 | - [args](/docs/api/modules/paradict/errors/__init__/class-ValidationError.md#fields-table) = `` 21 | - [with\_traceback](/docs/api/modules/paradict/errors/__init__/class-ValidationError.md#fields-table) = `` 22 | 23 |

Back to top

24 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/buffered_text_stream/class-BufferedTextStream.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/deserializer/buffered_text_stream/README.md) | [Source](/src/paradict/deserializer/buffered_text_stream.py) 3 | 4 | # Class BufferedTextStream 5 | > Module: [paradict.deserializer.buffered\_text\_stream](/docs/api/modules/paradict/deserializer/buffered_text_stream/README.md) 6 | > 7 | > Class: **BufferedTextStream** 8 | > 9 | > Inheritance: `object` 10 | 11 | A FIFO queue for processing textual Paradict data 12 | 13 | # Methods within class 14 | Here are methods exposed in the class: 15 | - [\_\_init\_\_](#__init__) 16 | - [get](#get) 17 | - [get\_all](#get_all) 18 | - [is\_empty](#is_empty) 19 | - [put](#put) 20 | 21 | ## \_\_init\_\_ 22 | Initialize self. See help(type(self)) for accurate signature. 23 | 24 | ```python 25 | def __init__(self): 26 | ... 27 | ``` 28 | 29 |

Back to top

30 | 31 | ## get 32 | No docstring 33 | 34 | ```python 35 | def get(self): 36 | ... 37 | ``` 38 | 39 |

Back to top

40 | 41 | ## get\_all 42 | Generator for iteratively getting each line composing the 43 | textual data stored in the buffer. 44 | Note that lines yielded won't end with a newline ' 45 | ' character 46 | 47 | ```python 48 | def get_all(self): 49 | ... 50 | ``` 51 | 52 |

Back to top

53 | 54 | ## is\_empty 55 | No docstring 56 | 57 | ```python 58 | def is_empty(self): 59 | ... 60 | ``` 61 | 62 |

Back to top

63 | 64 | ## put 65 | Store textual data in the buffer. This data will then be iteratively 66 | extracted by the 'get' method, line by line. 67 | Note: make sure that each line is ended with a newline ' 68 | ' character 69 | 70 | ```python 71 | def put(self, s): 72 | ... 73 | ``` 74 | 75 |

Back to top

76 | -------------------------------------------------------------------------------- /src/paradict/__main__.py: -------------------------------------------------------------------------------- 1 | # File generated by Setupinit 2 | import sys 3 | import paradict 4 | 5 | __all__ = [] 6 | 7 | import paradict.io_bin 8 | 9 | import paradict.io_text 10 | 11 | TEXT = """\ 12 | Paradict - Streamable multi-format serialization 13 | https://github.com/pyrustic/paradict 14 | 15 | COMMANDS: 16 | t2b []: Text-to-binary serialization. 17 | b2t []: Binary-to-text serialization. 18 | 19 | NOTES: 20 | - Serialization is done from a src file to a dst file. 21 | - is an existing filename. 22 | - is an optional filename (that exists or not). 23 | 24 | To show this help message, type '-h' or '--help'. 25 | """ 26 | 27 | 28 | def main(): 29 | all_args = sys.argv[1:] 30 | try: 31 | command = all_args[0] 32 | except IndexError as e: 33 | print(TEXT) 34 | return 35 | args = all_args[1:] 36 | if command in ("-h", "--help"): 37 | print(TEXT) 38 | return 39 | handler = HANDLERS.get(command) 40 | if handler is None: 41 | print("Invalid command. Type -h for help.") 42 | else: 43 | handler(args) 44 | 45 | 46 | def t2b(args): 47 | args = ensure_args(args) 48 | if not args: 49 | return 50 | src, dst = args 51 | data = paradict.io_text.read(src) 52 | if dst: 53 | paradict.io_bin.pack_into(data, dst) 54 | else: 55 | print(paradict.pack(data)) 56 | 57 | 58 | def b2t(args): 59 | args = ensure_args(args) 60 | if not args: 61 | return 62 | src, dst = args 63 | data = paradict.io_bin.unpack_from(src) 64 | if dst: 65 | paradict.io_text.write(data, dst) 66 | else: 67 | print(paradict.encode(data)) 68 | 69 | 70 | def ensure_args(args): 71 | if not args: 72 | print("Error: The 'src' argument is required but was not provided.") 73 | elif len(args) == 1: 74 | return args[0], None 75 | elif len(args) == 2: 76 | return args 77 | else: 78 | print("Error: Too many arguments.") 79 | 80 | 81 | HANDLERS = {"t2b": t2b, "b2t": b2t} 82 | 83 | 84 | if __name__ == "__main__": 85 | main() 86 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/buffered_bin_stream/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/deserializer/buffered_bin_stream.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.deserializer.buffered\_bin\_stream** 6 | 7 | A FIFO queue for processing binary Paradict data 8 | 9 | ## Classes 10 | - [**BufferedBinStream**](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md): A FIFO queue for processing binary Paradict data 11 | - [buffer](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#properties-table); _getter_ 12 | - [get](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#get): No docstring. 13 | - [get\_all](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#get_all): Generator for iteratively getting each tag-payload tuple composing the raw data stored in the buffer 14 | - [is\_empty](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#is_empty): No docstring. 15 | - [put](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#put): Store binary data in the buffer. This data will then be iteratively extracted by the 'get' method 16 | - [\_clear\_status](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#_clear_status): No docstring. 17 | - [\_read](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#_read): No docstring. 18 | - [\_read\_buffer](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#_read_buffer): No docstring. 19 | - [\_update\_expected\_width\_var](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#_update_expected_width_var): No docstring. 20 | - [\_update\_tag\_var](/docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md#_update_tag_var): No docstring. 21 | 22 |

Back to top

23 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/__init__/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/deserializer/__init__/README.md) | [Source](/src/paradict/deserializer/__init__.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.deserializer.\_\_init\_\_](/docs/api/modules/paradict/deserializer/__init__/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [decode](#decode) 9 | - [unpack](#unpack) 10 | 11 | ## decode 12 | Convert some textual Paradict data into a Python dictionary 13 | 14 | ```python 15 | def decode(text, type_ref=None, receiver=None, obj_builder=None, root_dir=None): 16 | ... 17 | ``` 18 | 19 | | Parameter | Description | 20 | | --- | --- | 21 | | text | string to convert into a Python dict | 22 | | type\_ref | optional TypeRef object | 23 | | receiver | callback function that will be called at the end of conversion. This callback function accepts the Decoder instance as argument | 24 | | obj\_builder | function that accepts a paradict.xtypes.Obj container and returns a fresh new Python object | 25 | | root\_dir | root directory in which the attachments dir is supposed to be | 26 | 27 | ### Value to return 28 | Return the newly built Python object 29 | 30 |

Back to top

31 | 32 | ## unpack 33 | Convert some binary Paradict data into a Python dictionary 34 | 35 | ```python 36 | def unpack(raw, type_ref=None, receiver=None, obj_builder=None): 37 | ... 38 | ``` 39 | 40 | | Parameter | Description | 41 | | --- | --- | 42 | | raw | raw data previously packed with Paradict | 43 | | type\_ref | optional TypeRef object | 44 | | receiver | callback function that will be called at the end of conversion. This callback function accepts the Decoder instance as argument | 45 | | obj\_builder | function that accepts a paradict.xtypes.Obj container and returns a fresh new Python object | 46 | | dict\_only | boolean to enforce dict as root | 47 | 48 | ### Value to return 49 | Return the newly built Python object 50 | 51 |

Back to top

52 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/validator/__init__/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/validator/__init__/README.md) | [Source](/src/paradict/validator/__init__.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.validator.\_\_init\_\_](/docs/api/modules/paradict/validator/__init__/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [is\_valid](#is_valid) 9 | - [validate](#validate) 10 | 11 | ## is\_valid 12 | This function returns True if the given data 13 | successfully validates against the given schema 14 | 15 | ```python 16 | def is_valid(data, schema, type_ref=None): 17 | ... 18 | ``` 19 | 20 | | Parameter | Description | 21 | | --- | --- | 22 | | data | some Python object (like a dict, a list, ...) that is part or include datatypes defined in VALID_DATATYPES. | 23 | | schema | a valid schema. It might be a collection containing Spec instances and/or type-strings. The benefit of using Spec is that you can add a checker function that will serve as an extra programmatic validation. | 24 | | type\_ref | optional TypeRef object | 25 | 26 | ### Value to return 27 | Returns True or False 28 | 29 |

Back to top

30 | 31 | ## validate 32 | This function validate some data against a schema. 33 | Might raise a ValidationError. 34 | 35 | ```python 36 | def validate(data, schema, type_ref=None): 37 | ... 38 | ``` 39 | 40 | | Parameter | Description | 41 | | --- | --- | 42 | | data | some Python object (like a dict, a list, ...) that is part or include datatypes defined in VALID_DATATYPES. | 43 | | schema | a valid schema. It might be a collection containing Spec instances and/or type-strings. The benefit of using Spec is that you can add a checker function that will serve as an extra programmatic validation. | 44 | | type\_ref | optional TypeRef object | 45 | 46 | ### Exceptions table 47 | The table below outlines exceptions that may occur. 48 | 49 | | Exception | Circumstance | 50 | | --- | --- | 51 | | ValidationError | Raised when an issue is encountered while validating the data | 52 | 53 |

Back to top

54 | -------------------------------------------------------------------------------- /src/paradict/deserializer/__init__.py: -------------------------------------------------------------------------------- 1 | """High-level functions to deserialize Paradict binary/text data into a Python dict""" 2 | from paradict.deserializer.decoder import Decoder 3 | from paradict.deserializer.unpacker import Unpacker 4 | 5 | 6 | __all__ = ["decode", "unpack"] 7 | 8 | 9 | def decode(text, type_ref=None, receiver=None, obj_builder=None, 10 | root_dir=None): 11 | """ 12 | Convert some textual Paradict data into a Python dictionary 13 | 14 | [param] 15 | - text: string to convert into a Python dict 16 | - type_ref: optional TypeRef object 17 | - receiver: callback function that will be called at the end of conversion. 18 | This callback function accepts the Decoder instance as argument 19 | - obj_builder: function that accepts a paradict.xtypes.Obj container and 20 | returns a fresh new Python object 21 | - root_dir: root directory in which the attachments dir is supposed to be 22 | 23 | [return] 24 | Return the newly built Python object 25 | """ 26 | decoder = Decoder(type_ref=type_ref, receiver=receiver, 27 | obj_builder=obj_builder, 28 | root_dir=root_dir) 29 | decoder.feed(text) 30 | if not decoder.queue.is_empty(): 31 | decoder.feed("\n") 32 | decoder.feed("===\n") # it's important to send an explicit end of stream 33 | return decoder.data 34 | 35 | 36 | def unpack(raw, type_ref=None, receiver=None, obj_builder=None): 37 | """ 38 | Convert some binary Paradict data into a Python dictionary 39 | 40 | [param] 41 | - raw: raw data previously packed with Paradict 42 | - type_ref: optional TypeRef object 43 | - receiver: callback function that will be called at the end of conversion. 44 | This callback function accepts the Decoder instance as argument 45 | - obj_builder: function that accepts a paradict.xtypes.Obj container and 46 | returns a fresh new Python object 47 | - dict_only: boolean to enforce dict as root 48 | 49 | [return] 50 | Return the newly built Python object 51 | """ 52 | unpacker = Unpacker(type_ref=type_ref, 53 | receiver=receiver, 54 | obj_builder=obj_builder) 55 | unpacker.feed(raw) 56 | return unpacker.data 57 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/io_text/__init__/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/io_text/__init__/README.md) | [Source](/src/paradict/io_text/__init__.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.io\_text.\_\_init\_\_](/docs/api/modules/paradict/io_text/__init__/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [decode\_from](#decode_from) 9 | - [encode\_into](#encode_into) 10 | 11 | ## decode\_from 12 | Open a textual Paradict file then read its contents into Python dict 13 | 14 | ```python 15 | def decode_from(file, type_ref=None, receiver=None, obj_builder=None, root_dir=None): 16 | ... 17 | ``` 18 | 19 | | Parameter | Description | 20 | | --- | --- | 21 | | file | text file object | 22 | | type\_ref | optional TypeRef object | 23 | | receiver | callback function that will be called at the end of conversion. This callback function accepts the Decoder instance as argument | 24 | | obj\_builder | function that accepts a paradict.xtypes.Obj container and returns a fresh new Python object | 25 | | root\_dir | The root_dir should be set only when the file object doesn't have a '.name' property. The root_dir will help to load attachments. | 26 | 27 | ### Value to return 28 | Return the newly built Python object 29 | 30 |

Back to top

31 | 32 | ## encode\_into 33 | Serialize a Python dict object with the Paradict text format then write it to a file 34 | 35 | ```python 36 | def encode_into(data, file, *, mode='d', type_ref=None, bin_to_text=False, root_dir=None, attachments_dir='attachments'): 37 | ... 38 | ``` 39 | 40 | | Parameter | Description | 41 | | --- | --- | 42 | | data | Python dict object | 43 | | file | text file object | 44 | | mode | either const.DATA_MODE or const.CONFIG_MODE. Defaults to DATA_MODE. | 45 | | type\_ref | optional TypeRef object | 46 | | bin\_to\_text | boolean to tell whether bin data should be converted into text or not | 47 | | root\_dir | the root_dir inside which attachments_dir is supposed to be. Set this only when bin_to_text is False and when the file object doesn't have a '.name' property that is basically the filename. | 48 | | attachments\_dir | path to attachments directory. Relative paths should use a slash as separator | 49 | 50 |

Back to top

51 | -------------------------------------------------------------------------------- /tests/deserializer/test_scanner.py: -------------------------------------------------------------------------------- 1 | import io 2 | import unittest 3 | from datetime import datetime 4 | from datetime import timezone 5 | from paradict import scan, pack 6 | 7 | 8 | utc_datetime = datetime(2024, 7, 25, 9 | 14, 30, 59, 10 | tzinfo=timezone.utc) 11 | 12 | 13 | DATA = {"id": 42, "name": "alex", "pi": 3.14, 14 | "created_at": utc_datetime, "weight": None, 15 | "photo": b'avatar.png', "music": {}, 16 | "books": {"thriller": ["book 1", "book 2"], 17 | "sci-fi": {"book 3", "book 4"}}} 18 | 19 | 20 | class TestScanFunction(unittest.TestCase): 21 | 22 | def test_with_integer(self): 23 | data = pack(42) 24 | with io.BytesIO(data) as file: 25 | buffer = bytearray() 26 | i = 0 27 | for tag, slice_obj in scan(file): 28 | buffer.extend(data[slice_obj]) 29 | i += 1 30 | self.assertEqual(1, i) 31 | self.assertEqual(bytes(buffer), data) 32 | 33 | def test_with_string(self): 34 | data = pack("alex") 35 | with io.BytesIO(data) as file: 36 | buffer = bytearray() 37 | i = 0 38 | for tag, slice_obj in scan(file): 39 | buffer.extend(data[slice_obj]) 40 | i += 1 41 | self.assertEqual(1, i) 42 | self.assertEqual(bytes(buffer), data) 43 | 44 | def test_with_none_value(self): 45 | data = pack(None) 46 | with io.BytesIO(data) as file: 47 | buffer = bytearray() 48 | i = 0 49 | for tag, slice_obj in scan(file): 50 | buffer.extend(data[slice_obj]) 51 | i += 1 52 | self.assertEqual(1, i) 53 | self.assertEqual(bytes(buffer), data) 54 | 55 | def test_with_long_str(self): 56 | data = pack("A"*50000) 57 | with io.BytesIO(data) as file: 58 | buffer = bytearray() 59 | i = 0 60 | for tag, slice_obj in scan(file): 61 | buffer.extend(data[slice_obj]) 62 | i += 1 63 | self.assertEqual(1, i) 64 | self.assertEqual(bytes(buffer), data) 65 | 66 | def test_with_complex_data(self): 67 | data = pack(DATA) 68 | with io.BytesIO(data) as file: 69 | buffer = bytearray() 70 | i = 0 71 | for tag, slice_obj in scan(file): 72 | buffer.extend(data[slice_obj]) 73 | i += 1 74 | self.assertEqual(35, i) 75 | self.assertEqual(bytes(buffer), data) 76 | 77 | 78 | if __name__ == "__main__": 79 | unittest.main() 80 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/__init__/class-Datatype.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/__init__/README.md) | [Source](/src/paradict/__init__.py) 3 | 4 | # Class Datatype 5 | > Module: [paradict.\_\_init\_\_](/docs/api/modules/paradict/__init__/README.md) 6 | > 7 | > Class: **Datatype** 8 | > 9 | > Inheritance: `enum.Enum` 10 | 11 | Create a collection of name/value pairs. 12 | 13 | Example enumeration: 14 | 15 | >>> class Color(Enum): 16 | ... RED = 1 17 | ... BLUE = 2 18 | ... GREEN = 3 19 | 20 | Access them by: 21 | 22 | - attribute access: 23 | 24 | >>> Color.RED 25 | 26 | 27 | - value lookup: 28 | 29 | >>> Color(1) 30 | 31 | 32 | - name lookup: 33 | 34 | >>> Color['RED'] 35 | 36 | 37 | Enumerations can be iterated over, and know how many members they have: 38 | 39 | >>> len(Color) 40 | 3 41 | 42 | >>> list(Color) 43 | 44 | ## Fields table 45 | Here are fields exposed in the class: 46 | 47 | | Field | Value | 48 | | --- | --- | 49 | | DICT | `1` | 50 | | LIST | `2` | 51 | | SET | `3` | 52 | | OBJ | `4` | 53 | | GRID | `5` | 54 | | BOOL | `6` | 55 | | STR | `7` | 56 | | BIN | `8` | 57 | | INT | `9` | 58 | | FLOAT | `10` | 59 | | COMPLEX | `11` | 60 | | DATE | `12` | 61 | | TIME | `13` | 62 | | DATETIME | `14` | 63 | 64 |

Back to top

65 | 66 | # Methods within class 67 | Here are methods exposed in the class: 68 | - [\_\_init\_\_](#__init__) 69 | - [\_generate\_next\_value\_](#_generate_next_value_) 70 | - [\_missing\_](#_missing_) 71 | 72 | ## \_\_init\_\_ 73 | Initialize self. See help(type(self)) for accurate signature. 74 | 75 | ```python 76 | def __init__(self, *args, **kwds): 77 | ... 78 | ``` 79 | 80 |

Back to top

81 | 82 | ## \_generate\_next\_value\_ 83 | Generate the next value when not given. 84 | 85 | name: the name of the member 86 | start: the initial start value or None 87 | count: the number of existing members 88 | last_values: the list of values assigned 89 | 90 | ```python 91 | @staticmethod 92 | def _generate_next_value_(name, start, count, last_values): 93 | ... 94 | ``` 95 | 96 |

Back to top

97 | 98 | ## \_missing\_ 99 | No docstring 100 | 101 | ```python 102 | @classmethod 103 | def _missing_(value): 104 | ... 105 | ``` 106 | 107 |

Back to top

108 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/const/__init__/class-Datatype.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/const/__init__/README.md) | [Source](/src/paradict/const/__init__.py) 3 | 4 | # Class Datatype 5 | > Module: [paradict.const.\_\_init\_\_](/docs/api/modules/paradict/const/__init__/README.md) 6 | > 7 | > Class: **Datatype** 8 | > 9 | > Inheritance: `enum.Enum` 10 | 11 | Create a collection of name/value pairs. 12 | 13 | Example enumeration: 14 | 15 | >>> class Color(Enum): 16 | ... RED = 1 17 | ... BLUE = 2 18 | ... GREEN = 3 19 | 20 | Access them by: 21 | 22 | - attribute access: 23 | 24 | >>> Color.RED 25 | 26 | 27 | - value lookup: 28 | 29 | >>> Color(1) 30 | 31 | 32 | - name lookup: 33 | 34 | >>> Color['RED'] 35 | 36 | 37 | Enumerations can be iterated over, and know how many members they have: 38 | 39 | >>> len(Color) 40 | 3 41 | 42 | >>> list(Color) 43 | 44 | ## Fields table 45 | Here are fields exposed in the class: 46 | 47 | | Field | Value | 48 | | --- | --- | 49 | | DICT | `1` | 50 | | LIST | `2` | 51 | | SET | `3` | 52 | | OBJ | `4` | 53 | | GRID | `5` | 54 | | BOOL | `6` | 55 | | STR | `7` | 56 | | BIN | `8` | 57 | | INT | `9` | 58 | | FLOAT | `10` | 59 | | COMPLEX | `11` | 60 | | DATE | `12` | 61 | | TIME | `13` | 62 | | DATETIME | `14` | 63 | 64 |

Back to top

65 | 66 | # Methods within class 67 | Here are methods exposed in the class: 68 | - [\_\_init\_\_](#__init__) 69 | - [\_generate\_next\_value\_](#_generate_next_value_) 70 | - [\_missing\_](#_missing_) 71 | 72 | ## \_\_init\_\_ 73 | Initialize self. See help(type(self)) for accurate signature. 74 | 75 | ```python 76 | def __init__(self, *args, **kwds): 77 | ... 78 | ``` 79 | 80 |

Back to top

81 | 82 | ## \_generate\_next\_value\_ 83 | Generate the next value when not given. 84 | 85 | name: the name of the member 86 | start: the initial start value or None 87 | count: the number of existing members 88 | last_values: the list of values assigned 89 | 90 | ```python 91 | @staticmethod 92 | def _generate_next_value_(name, start, count, last_values): 93 | ... 94 | ``` 95 | 96 |

Back to top

97 | 98 | ## \_missing\_ 99 | No docstring 100 | 101 | ```python 102 | @classmethod 103 | def _missing_(value): 104 | ... 105 | ``` 106 | 107 |

Back to top

108 | -------------------------------------------------------------------------------- /src/paradict/xtypes/__init__.py: -------------------------------------------------------------------------------- 1 | """Boxes to hold grids, hexadecimal integers, et cetera""" 2 | from collections import UserList, UserDict 3 | from paradict import misc 4 | 5 | 6 | __all__ = ["Grid", "Obj", "HexInt", "OctInt", "BinInt"] 7 | 8 | 9 | class Grid(UserList): 10 | """ 11 | Box to hold a grid. A grid is made of numbers and should 12 | be consistent (rows should be of same size) 13 | 14 | Example: 15 | ``` 16 | # a grid with 2 rows and 3 columns 17 | my_grid = Grid([(0, 1, 0), 18 | (1, 0, 1)]) 19 | ``` 20 | """ 21 | pass 22 | 23 | 24 | class Obj(UserDict): 25 | """ 26 | Box to hold an Extension Object. Such objects behave like a dictionary. 27 | An object builder is passed as argument to the right functions, thus, 28 | the object is consumed/used to build a new valid data value 29 | """ 30 | pass 31 | 32 | 33 | class HexInt(int): 34 | """Box to hold hexadecimal integer""" 35 | 36 | def __new__(cls, x): 37 | width = 0 38 | if isinstance(x, str): 39 | parts = misc.split_int(x) 40 | if parts.prefix == "0x": 41 | width = len(parts.leading_zeros) + len(parts.val) 42 | instance = super().__new__(cls, str(x), base=misc.get_int_base(x)) 43 | x = hex(instance) 44 | x = misc.left_pad_int(x, width) if width else x 45 | instance.__x = misc.tidy_up_int(x, width=4) 46 | return instance 47 | 48 | def __str__(self): 49 | return self.__x 50 | 51 | 52 | class OctInt(int): 53 | """Box to hold octal integer""" 54 | 55 | def __new__(cls, x): 56 | width = 0 57 | if isinstance(x, str): 58 | parts = misc.split_int(x) 59 | if parts.prefix == "0o": 60 | width = len(parts.leading_zeros) + len(parts.val) 61 | instance = super().__new__(cls, str(x), base=misc.get_int_base(x)) 62 | x = oct(instance) 63 | x = misc.left_pad_int(x, width) if width else x 64 | instance.__x = misc.tidy_up_int(x, width=3) 65 | return instance 66 | 67 | def __str__(self): 68 | return self.__x 69 | 70 | 71 | class BinInt(int): 72 | """Box to hold binary integer""" 73 | 74 | def __new__(cls, x): 75 | width = 0 76 | if isinstance(x, str): 77 | parts = misc.split_int(x) 78 | if parts.prefix == "0b": 79 | width = len(parts.leading_zeros) + len(parts.val) 80 | instance = super().__new__(cls, str(x), base=misc.get_int_base(x)) 81 | x = bin(instance) 82 | x = misc.left_pad_int(x, width) if width else x 83 | instance.__x = misc.tidy_up_int(x, width=4) 84 | return instance 85 | 86 | def __str__(self): 87 | return self.__x 88 | -------------------------------------------------------------------------------- /tests/misc/test_misc.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from paradict import misc, xtypes 3 | 4 | 5 | class TestPrettifyGridFunc(unittest.TestCase): 6 | 7 | def test(self): 8 | grid = xtypes.Grid([[10, 1, 0], 9 | [0, 100, 0], 10 | [0, 1, 10000]]) 11 | r = misc.prettify_grid(grid) 12 | expected = [("10", "1 ", "0 "), 13 | ("0 ", "100", "0 "), 14 | ("0 ", "1 ", "10000")] 15 | self.assertEqual(expected, r) 16 | 17 | 18 | class TestAddLeadingZerosFunc(unittest.TestCase): 19 | 20 | def test_with_int(self): 21 | for key, val in {0: "0000000", 22 | 100: "0000100", 23 | 1000: "0001000", 24 | 1000000: "1000000", 25 | -100: "-0000100", 26 | -1000: "-0001000", 27 | -1000000: "-1000000"}.items(): 28 | with self.subTest("Key: '{}'".format(key)): 29 | r = misc.left_pad_int(key, width=7) 30 | self.assertEqual(val, r) 31 | 32 | def test_with_hex(self): 33 | for key, val in {"0x0": "0x0000000", 34 | "0x100": "0x0000100", 35 | "0x1000": "0x0001000", 36 | "0x1000000": "0x1000000", 37 | "-0x100": "-0x0000100", 38 | "-0x1000": "-0x0001000", 39 | "-0x1000000": "-0x1000000"}.items(): 40 | with self.subTest("Key: '{}'".format(key)): 41 | r = misc.left_pad_int(key, width=7) 42 | self.assertEqual(val, r) 43 | 44 | def test_with_oct(self): 45 | for key, val in {"0o0": "0o0000000", 46 | "0o100": "0o0000100", 47 | "0o1000": "0o0001000", 48 | "0o1000000": "0o1000000", 49 | "-0o100": "-0o0000100", 50 | "-0o1000": "-0o0001000", 51 | "-0o1000000": "-0o1000000"}.items(): 52 | with self.subTest("Key: '{}'".format(key)): 53 | r = misc.left_pad_int(key, width=7) 54 | self.assertEqual(val, r) 55 | 56 | def test_with_bin(self): 57 | for key, val in {"0b0": "0b0000000", 58 | "0b100": "0b0000100", 59 | "0b1000": "0b0001000", 60 | "0b1000000": "0b1000000", 61 | "-0b100": "-0b0000100", 62 | "-0b1000": "-0b0001000", 63 | "-0b1000000": "-0b1000000"}.items(): 64 | with self.subTest("Key: '{}'".format(key)): 65 | r = misc.left_pad_int(key, width=7) 66 | self.assertEqual(val, r) 67 | 68 | 69 | if __name__ == '__main__': 70 | unittest.main() 71 | -------------------------------------------------------------------------------- /src/paradict/kv/__init__.py: -------------------------------------------------------------------------------- 1 | """This module exposes the split function that will parse a valid key-value string""" 2 | import re 3 | from paradict import errors, const 4 | from collections import namedtuple 5 | 6 | 7 | __all__ = ["Info", "split"] 8 | 9 | 10 | Info = namedtuple("Info", ["key", "val", "sep", "mode"]) 11 | 12 | 13 | def split(val): 14 | """ 15 | Split a non-empty string into key val. 16 | The string should follow one of these format: 17 | - data_mode format: key: value 18 | - config_mode format: key = value 19 | 20 | [param] 21 | - val: non-empty string 22 | 23 | [return] 24 | Return an Info namedtuple made of: key, val, sep, and mode attributes. 25 | The key and val are strings. The sep is either ":" or "=". 26 | The mode is either paradict.const.DATA_MODE or paradict.const.CONFIG_MODE. 27 | Note that if the sep is a colon, it means that the mode is DATA_MODE. 28 | """ 29 | if not val or not isinstance(val, str): 30 | msg = "Only non-empty strings can be split" 31 | raise errors.Error(msg) 32 | r = _parse(val) 33 | if not r or len(r) != 3: 34 | raise errors.Error("Parsing error") 35 | left, sep, right = r 36 | key = left.strip().replace(r"\'", "'").replace(r'\"', '"') 37 | val = right.strip() 38 | if sep == "=": 39 | mode = const.CONFIG_MODE 40 | elif sep == ":": 41 | mode = const.DATA_MODE 42 | else: 43 | raise errors.Error("Missing separator character") 44 | return Info(key, val, sep, mode) 45 | 46 | 47 | def _parse(val): 48 | """regex parse""" 49 | match_obj = re.fullmatch(KEY_VAL_PATTERN, val) 50 | groups_list = list() 51 | if not match_obj: 52 | return groups_list 53 | for group in match_obj.groups(): 54 | if group is not None: 55 | groups_list.append(group) 56 | return groups_list 57 | 58 | 59 | # double-quoted key pattern (left side of colon sign) 60 | KEY_PATTERN_1 = r'''^(? Module: **paradict.validator.\_\_init\_\_** 6 | 7 | Data validation module 8 | 9 | ## Fields 10 | - [**All fields**](/docs/api/modules/paradict/validator/__init__/fields.md) 11 | - VALID\_DATATYPES = `('dict', 'list', 'set', 'obj', 'bin', 'bool', 'complex', 'date', 'datetime', 'float', 'grid', 'int', 'str', 'time')` 12 | 13 |

Back to top

14 | 15 | ## Functions 16 | - [**All functions**](/docs/api/modules/paradict/validator/__init__/funcs.md) 17 | - [is\_valid](/docs/api/modules/paradict/validator/__init__/funcs.md#is_valid): This function returns True if the given data successfully validates against the given schema 18 | - [validate](/docs/api/modules/paradict/validator/__init__/funcs.md#validate): This function validate some data against a schema. Might raise a ValidationError. 19 | 20 |

Back to top

21 | 22 | ## Classes 23 | - [**Spec**](/docs/api/modules/paradict/validator/__init__/class-Spec.md): A Spec can be used to form a schema along with string-types. The particularity of a Spec is that it can carry a checker that is ... 24 | - [checker](/docs/api/modules/paradict/validator/__init__/class-Spec.md#properties-table); _getter_ 25 | - [datatype](/docs/api/modules/paradict/validator/__init__/class-Spec.md#properties-table); _getter_ 26 | - [**Validator**](/docs/api/modules/paradict/validator/__init__/class-Validator.md): Class to validate data against a schema 27 | - [schema](/docs/api/modules/paradict/validator/__init__/class-Validator.md#properties-table); _getter_ 28 | - [type\_ref](/docs/api/modules/paradict/validator/__init__/class-Validator.md#properties-table); _getter_ 29 | - [validate](/docs/api/modules/paradict/validator/__init__/class-Validator.md#validate): Validate data. Might raise a validation error 30 | - [\_ensure\_spec](/docs/api/modules/paradict/validator/__init__/class-Validator.md#_ensure_spec): No docstring. 31 | - [\_validate](/docs/api/modules/paradict/validator/__init__/class-Validator.md#_validate): No docstring. 32 | - [\_validate\_datatype](/docs/api/modules/paradict/validator/__init__/class-Validator.md#_validate_datatype): No docstring. 33 | - [\_validate\_dict](/docs/api/modules/paradict/validator/__init__/class-Validator.md#_validate_dict): No docstring. 34 | - [\_validate\_list](/docs/api/modules/paradict/validator/__init__/class-Validator.md#_validate_list): Schema SHOULD be a list 35 | - [\_validate\_obj](/docs/api/modules/paradict/validator/__init__/class-Validator.md#_validate_obj): No docstring. 36 | - [\_validate\_set](/docs/api/modules/paradict/validator/__init__/class-Validator.md#_validate_set): Schema SHOULD be a set 37 | 38 |

Back to top

39 | -------------------------------------------------------------------------------- /tests/kv/test_kv.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from paradict import kv, const 3 | 4 | 5 | class TestSplitFuncInDataMode(unittest.TestCase): 6 | 7 | def test_with_single_quote_and_compact_string(self): 8 | key = "'this_is_the_key'" 9 | val = "this_is_the_val" 10 | sep = ":" 11 | d = "{key}{sep} {val}".format(key=key, sep=sep, val=val) 12 | r = kv.split(d) 13 | expected = kv.Info(key, val, sep, const.DATA_MODE) 14 | self.assertEqual(expected, r) 15 | 16 | def test_with_single_quote_and_spaced_string(self): 17 | key = "'this is the key'" 18 | val = "this is the val" 19 | sep = ":" 20 | d = "{key}{sep} {val}".format(key=key, sep=sep, val=val) 21 | r = kv.split(d) 22 | expected = kv.Info(key, val, sep, const.DATA_MODE) 23 | self.assertEqual(expected, r) 24 | 25 | def test_with_double_quote_and_compact_string(self): 26 | key = '"this_is_the key"' 27 | val = "this_is_the_val" 28 | sep = ":" 29 | d = '{key}{sep} {val}'.format(key=key, sep=sep, val=val) 30 | r = kv.split(d) 31 | expected = kv.Info(key, val, sep, const.DATA_MODE) 32 | self.assertEqual(expected, r) 33 | 34 | def test_with_double_quote_and_spaced_string(self): 35 | key = '"this is the key"' 36 | val = "this is the val" 37 | sep = ":" 38 | d = '{key}{sep} {val}'.format(key=key, sep=sep, val=val) 39 | r = kv.split(d) 40 | expected = kv.Info(key, val, sep, const.DATA_MODE) 41 | self.assertEqual(expected, r) 42 | 43 | def test_with_escaped_single_quote(self): 44 | key = r"'this \' is the key'" 45 | key_bis = r"'this ' is the key'" 46 | val = "this is the val" 47 | sep = ":" 48 | d = "{key}{sep} {val}".format(key=key, sep=sep, val=val) 49 | r = kv.split(d) 50 | expected = kv.Info(key_bis, val, sep, const.DATA_MODE) 51 | self.assertEqual(expected, r) 52 | 53 | def test_with_escaped_double_quote(self): 54 | key = r'"this \" is the key"' 55 | key_bis = r'"this " is the key"' 56 | val = "this is the val" 57 | sep = ":" 58 | d = '{key}{sep} {val}'.format(key=key, sep=sep, val=val) 59 | r = kv.split(d) 60 | expected = kv.Info(key_bis, val, sep, const.DATA_MODE) 61 | self.assertEqual(expected, r) 62 | 63 | def test_with_backslash(self): 64 | key = r'"this \ is the key"' 65 | val = "this is the val" 66 | sep = ":" 67 | d = '{key}{sep} {val}'.format(key=key, sep=sep, val=val) 68 | r = kv.split(d) 69 | expected = kv.Info(key, val, sep, const.DATA_MODE) 70 | self.assertEqual(expected, r) 71 | 72 | def test_with_double_backslash(self): 73 | key = r'"this \\ is the key"' 74 | val = "this is the val" 75 | sep = ":" 76 | d = '{key}{sep} {val}'.format(key=key, sep=sep, val=val) 77 | r = kv.split(d) 78 | expected = kv.Info(key, val, sep, const.DATA_MODE) 79 | self.assertEqual(expected, r) 80 | 81 | 82 | if __name__ == '__main__': 83 | unittest.main() 84 | -------------------------------------------------------------------------------- /src/paradict/io_text/__init__.py: -------------------------------------------------------------------------------- 1 | """Load and dump text Paradict from/to file""" 2 | import os 3 | from paradict import const 4 | from paradict.serializer.encoder import Encoder 5 | from paradict.deserializer.decoder import Decoder 6 | 7 | 8 | __all__ = ["decode_from", "encode_into"] 9 | 10 | 11 | def decode_from(file, type_ref=None, receiver=None, obj_builder=None, 12 | root_dir=None): 13 | """ 14 | Open a textual Paradict file then read its contents into Python dict 15 | 16 | [param] 17 | - file: text file object 18 | - type_ref: optional TypeRef object 19 | - receiver: callback function that will be called at the end of conversion. 20 | This callback function accepts the Decoder instance as argument 21 | - obj_builder: function that accepts a paradict.xtypes.Obj container and 22 | returns a fresh new Python object 23 | - root_dir: The root_dir should be set only when the file object doesn't have 24 | a '.name' property. The root_dir will help to load attachments. 25 | [return] 26 | Return the newly built Python object 27 | """ 28 | if root_dir is None: 29 | try: 30 | root_dir = os.path.dirname(os.path.abspath(file.name)) 31 | except AttributeError as e: 32 | root_dir = None 33 | decoder = Decoder(type_ref=type_ref, receiver=receiver, 34 | obj_builder=obj_builder, 35 | root_dir=root_dir) 36 | while True: 37 | line = file.readline() 38 | if not line: 39 | break 40 | decoder.feed(line) 41 | if not decoder.queue.is_empty(): 42 | decoder.feed("\n") 43 | decoder.feed("===\n") 44 | return decoder.data 45 | 46 | 47 | def encode_into(data, file, *, mode=const.DATA_MODE, type_ref=None, 48 | bin_to_text=False, root_dir=None, attachments_dir="attachments"): 49 | """ 50 | Serialize a Python dict object with the Paradict text format then write it to a file 51 | 52 | [param] 53 | - data: Python dict object 54 | - file: text file object 55 | - mode: either const.DATA_MODE or const.CONFIG_MODE. Defaults to DATA_MODE. 56 | - type_ref: optional TypeRef object 57 | - bin_to_text: boolean to tell whether bin data should be converted into text or not 58 | - root_dir: the root_dir inside which attachments_dir is supposed to be. 59 | Set this only when bin_to_text is False and when the file object doesn't have a '.name' 60 | property that is basically the filename. 61 | - attachments_dir: path to attachments directory. Relative paths should use 62 | a slash as separator 63 | """ 64 | if bin_to_text: 65 | root_dir = None 66 | else: 67 | if root_dir is None: 68 | try: 69 | root_dir = os.path.dirname(os.path.abspath(file.name)) 70 | except AttributeError as e: 71 | root_dir = None 72 | encoder = Encoder(mode=mode, type_ref=type_ref, 73 | bin_to_text=bin_to_text, root_dir=root_dir, 74 | attachments_dir=attachments_dir) 75 | for r in encoder.encode(data): 76 | file.write(r+"\n") 77 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/packer/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/serializer/packer.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.serializer.packer** 6 | 7 | No docstring. 8 | 9 | ## Classes 10 | - [**Packer**](/docs/api/modules/paradict/serializer/packer/class-Packer.md): Class to convert some binary Python dict into Paradict binary format 11 | - [auto\_index](/docs/api/modules/paradict/serializer/packer/class-Packer.md#properties-table); _getter_ 12 | - [dict\_only](/docs/api/modules/paradict/serializer/packer/class-Packer.md#properties-table); _getter_ 13 | - [index\_dict](/docs/api/modules/paradict/serializer/packer/class-Packer.md#properties-table); _getter_ 14 | - [type\_ref](/docs/api/modules/paradict/serializer/packer/class-Packer.md#properties-table); _getter, setter_ 15 | - [pack](/docs/api/modules/paradict/serializer/packer/class-Packer.md#pack): Generator for iteratively packing data by yielding bytes datum forged in Paradict binary format 16 | - [\_pack](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack): No docstring. 17 | - [\_pack\_bin](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_bin): No docstring. 18 | - [\_pack\_bin\_int](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_bin_int): No docstring. 19 | - [\_pack\_bool](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_bool): No docstring. 20 | - [\_pack\_complex](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_complex): No docstring. 21 | - [\_pack\_date](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_date): No docstring. 22 | - [\_pack\_datetime](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_datetime): No docstring. 23 | - [\_pack\_dict](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_dict): No docstring. 24 | - [\_pack\_float](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_float): No docstring. 25 | - [\_pack\_grid](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_grid): No docstring. 26 | - [\_pack\_hex\_int](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_hex_int): No docstring. 27 | - [\_pack\_int](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_int): No docstring. 28 | - [\_pack\_list](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_list): No docstring. 29 | - [\_pack\_null](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_null): No docstring. 30 | - [\_pack\_obj](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_obj): No docstring. 31 | - [\_pack\_oct\_int](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_oct_int): No docstring. 32 | - [\_pack\_set](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_set): No docstring. 33 | - [\_pack\_str](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_str): No docstring. 34 | - [\_pack\_time](/docs/api/modules/paradict/serializer/packer/class-Packer.md#_pack_time): No docstring. 35 | 36 |

Back to top

37 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/tags/mappings/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/tags/mappings.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.tags.mappings** 6 | 7 | Private miscellaneous module for the Paradict binary format 8 | 9 | ## Fields 10 | - [**All fields**](/docs/api/modules/paradict/tags/mappings/fields.md) 11 | - BIN\_TO\_SIZE = `{b'(': 1, b')': 2, b'*': 3, b'+': 4, b',': 5}` 12 | - LETTER\_TO\_TAG = `{'a': b'g', 'b': b'h', 'c': b'i', 'd': b'j', 'e': b'k', 'f': b'l', 'g': b'm', 'h': b'n', 'i': b'o', 'j': b'p', 'k': b'q', 'l': b'r', 'm': b's', 'n': b't', 'o': b'u', 'p': b'v', 'q': b'w', 'r': b'x', 's': b'y', 't': b'z', 'u': b'{', 'v': b'|', 'w': b'}', 'x': b'~', 'y': b'\x7f', 'z': b'\x80', 'A': b'\x81', 'B': b'\x82', 'C': b'\x83', 'D': b'\x84', 'E': b'\x85', 'F': b'\x86', 'G': b'\x87', 'H': b'\x88', 'I': b'\x89', 'J': b'\x8a', 'K': b'\x8b', 'L': b'\x8c', 'M': b'\x8d', 'N': b'\x8e', 'O': b'\x8f', 'P': b'\x90', 'Q': b'\x91', 'R': b'\x92', 'S': b'\x93', 'T': b'\x94', 'U': b'\x95', 'V': b'\x96', 'W': b'\x97', 'X': b'\x98', 'Y': b'\x99', 'Z': b'\x9a'}` 13 | - NINT\_TO\_SIZE = `{b'7': 1, b'8': 2, b'9': 3, b':': 4, b';': 5, b'<': 6, b'=': 7, b'>': 8}` 14 | - PINT\_TO\_SIZE = `{b'-': 1, b'.': 2, b'/': 3, b'0': 4, b'1': 5, b'2': 6, b'3': 7, b'4': 8}` 15 | - SIZE\_TO\_BIN = `{1: b'(', 2: b')', 3: b'*', 4: b'+', 5: b','}` 16 | - SIZE\_TO\_NINT = `{1: b'7', 2: b'8', 3: b'9', 4: b':', 5: b';', 6: b'<', 7: b'=', 8: b'>'}` 17 | - SIZE\_TO\_PINT = `{1: b'-', 2: b'.', 3: b'/', 4: b'0', 5: b'1', 6: b'2', 7: b'3', 8: b'4'}` 18 | - SIZE\_TO\_STR = `{1: b'A', 2: b'B', 3: b'C', 4: b'D', 5: b'E', 6: b'F', 7: b'G', 8: b'H', 9: b'I', 10: b'J', 11: b'K', 12: b'L', 13: b'M', 14: b'N', 15: b'O', 16: b'P', 17: b'Q', 18: b'R', 19: b'S', 20: b'T', 21: b'U', 22: b'V', 23: b'W', 24: b'X', 25: b'Y', 26: b'Z', 27: b'[', 28: b'\\', 29: b']', 30: b'^', 31: b'_', 32: b'`'}` 19 | - SIZE\_TO\_VARSTR = `{1: b'b', 2: b'c', 3: b'd', 4: b'e', 5: b'f'}` 20 | - STR\_TO\_SIZE = `{b'A': 1, b'B': 2, b'C': 3, b'D': 4, b'E': 5, b'F': 6, b'G': 7, b'H': 8, b'I': 9, b'J': 10, b'K': 11, b'L': 12, b'M': 13, b'N': 14, b'O': 15, b'P': 16, b'Q': 17, b'R': 18, b'S': 19, b'T': 20, b'U': 21, b'V': 22, b'W': 23, b'X': 24, b'Y': 25, b'Z': 26, b'[': 27, b'\\': 28, b']': 29, b'^': 30, b'_': 31, b'`': 32}` 21 | - TAG\_TO\_LETTER = `{b'g': 'a', b'h': 'b', b'i': 'c', b'j': 'd', b'k': 'e', b'l': 'f', b'm': 'g', b'n': 'h', b'o': 'i', b'p': 'j', b'q': 'k', b'r': 'l', b's': 'm', b't': 'n', b'u': 'o', b'v': 'p', b'w': 'q', b'x': 'r', b'y': 's', b'z': 't', b'{': 'u', b'|': 'v', b'}': 'w', b'~': 'x', b'\x7f': 'y', b'\x80': 'z', b'\x81': 'A', b'\x82': 'B', b'\x83': 'C', b'\x84': 'D', b'\x85': 'E', b'\x86': 'F', b'\x87': 'G', b'\x88': 'H', b'\x89': 'I', b'\x8a': 'J', b'\x8b': 'K', b'\x8c': 'L', b'\x8d': 'M', b'\x8e': 'N', b'\x8f': 'O', b'\x90': 'P', b'\x91': 'Q', b'\x92': 'R', b'\x93': 'S', b'\x94': 'T', b'\x95': 'U', b'\x96': 'V', b'\x97': 'W', b'\x98': 'X', b'\x99': 'Y', b'\x9a': 'Z'}` 22 | - VARSTR\_TO\_SIZE = `{b'b': 1, b'c': 2, b'd': 3, b'e': 4, b'f': 5}` 23 | - tags = `` 24 | 25 |

Back to top

26 | -------------------------------------------------------------------------------- /docs/api/README.md: -------------------------------------------------------------------------------- 1 | # Paradict API Reference 2 | Here are modules that make up [Paradict](/README.md): 3 | 4 | [paradict.\_\_init\_\_](/docs/api/modules/paradict/__init__/README.md) 5 |
6 | No docstring. 7 | 8 | [paradict.const.\_\_init\_\_](/docs/api/modules/paradict/const/__init__/README.md) 9 |
10 | No docstring. 11 | 12 | [paradict.deserializer.\_\_init\_\_](/docs/api/modules/paradict/deserializer/__init__/README.md) 13 |
14 | High-level functions to deserialize Paradict binary/text data into a Python dict 15 | 16 | [paradict.deserializer.buffered\_bin\_stream](/docs/api/modules/paradict/deserializer/buffered_bin_stream/README.md) 17 |
18 | A FIFO queue for processing binary Paradict data 19 | 20 | [paradict.deserializer.buffered\_text\_stream](/docs/api/modules/paradict/deserializer/buffered_text_stream/README.md) 21 |
22 | A FIFO queue for processing textual Paradict data 23 | 24 | [paradict.deserializer.decoder](/docs/api/modules/paradict/deserializer/decoder/README.md) 25 |
26 | No docstring. 27 | 28 | [paradict.deserializer.scanner](/docs/api/modules/paradict/deserializer/scanner/README.md) 29 |
30 | No docstring. 31 | 32 | [paradict.deserializer.unpacker](/docs/api/modules/paradict/deserializer/unpacker/README.md) 33 |
34 | No docstring. 35 | 36 | [paradict.errors.\_\_init\_\_](/docs/api/modules/paradict/errors/__init__/README.md) 37 |
38 | No docstring. 39 | 40 | [paradict.io\_bin.\_\_init\_\_](/docs/api/modules/paradict/io_bin/__init__/README.md) 41 |
42 | Load and dump binary Paradict from/to file 43 | 44 | [paradict.io\_text.\_\_init\_\_](/docs/api/modules/paradict/io_text/__init__/README.md) 45 |
46 | Load and dump text Paradict from/to file 47 | 48 | [paradict.kv.\_\_init\_\_](/docs/api/modules/paradict/kv/__init__/README.md) 49 |
50 | This module exposes the split function that will parse a valid key-value string 51 | 52 | [paradict.misc.\_\_init\_\_](/docs/api/modules/paradict/misc/__init__/README.md) 53 |
54 | Private miscellaneous functions and classes. 55 | 56 | [paradict.serializer.\_\_init\_\_](/docs/api/modules/paradict/serializer/__init__/README.md) 57 |
58 | High-level functions to serialize Python dict in Paradict binary/text format 59 | 60 | [paradict.serializer.encoder](/docs/api/modules/paradict/serializer/encoder/README.md) 61 |
62 | No docstring. 63 | 64 | [paradict.serializer.packer](/docs/api/modules/paradict/serializer/packer/README.md) 65 |
66 | No docstring. 67 | 68 | [paradict.tags.\_\_init\_\_](/docs/api/modules/paradict/tags/__init__/README.md) 69 |
70 | binary Paradict: 256 tags from NOP (`\x00`) to END (`\xff`) 71 | 72 | [paradict.tags.mappings](/docs/api/modules/paradict/tags/mappings/README.md) 73 |
74 | Private miscellaneous module for the Paradict binary format 75 | 76 | [paradict.typeref.\_\_init\_\_](/docs/api/modules/paradict/typeref/__init__/README.md) 77 |
78 | TypeRef for type specs and customization 79 | 80 | [paradict.validator.\_\_init\_\_](/docs/api/modules/paradict/validator/__init__/README.md) 81 |
82 | Data validation module 83 | 84 | [paradict.xtypes.\_\_init\_\_](/docs/api/modules/paradict/xtypes/__init__/README.md) 85 |
86 | Boxes to hold grids, hexadecimal integers, et cetera 87 | 88 |

Back to top

89 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/tags/mappings/fields.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/tags/mappings/README.md) | [Source](/src/paradict/tags/mappings.py) 3 | 4 | # Fields within module 5 | > Module: [paradict.tags.mappings](/docs/api/modules/paradict/tags/mappings/README.md) 6 | 7 | Here are fields exposed in the module: 8 | 9 | | Field | Value | 10 | | --- | --- | 11 | | BIN\_TO\_SIZE | `{b'(': 1, b')': 2, b'*': 3, b'+': 4, b',': 5}` | 12 | | LETTER\_TO\_TAG | `{'a': b'g', 'b': b'h', 'c': b'i', 'd': b'j', 'e': b'k', 'f': b'l', 'g': b'm', 'h': b'n', 'i': b'o', 'j': b'p', 'k': b'q', 'l': b'r', 'm': b's', 'n': b't', 'o': b'u', 'p': b'v', 'q': b'w', 'r': b'x', 's': b'y', 't': b'z', 'u': b'{', 'v': b'|', 'w': b'}', 'x': b'~', 'y': b'\x7f', 'z': b'\x80', 'A': b'\x81', 'B': b'\x82', 'C': b'\x83', 'D': b'\x84', 'E': b'\x85', 'F': b'\x86', 'G': b'\x87', 'H': b'\x88', 'I': b'\x89', 'J': b'\x8a', 'K': b'\x8b', 'L': b'\x8c', 'M': b'\x8d', 'N': b'\x8e', 'O': b'\x8f', 'P': b'\x90', 'Q': b'\x91', 'R': b'\x92', 'S': b'\x93', 'T': b'\x94', 'U': b'\x95', 'V': b'\x96', 'W': b'\x97', 'X': b'\x98', 'Y': b'\x99', 'Z': b'\x9a'}` | 13 | | NINT\_TO\_SIZE | `{b'7': 1, b'8': 2, b'9': 3, b':': 4, b';': 5, b'<': 6, b'=': 7, b'>': 8}` | 14 | | PINT\_TO\_SIZE | `{b'-': 1, b'.': 2, b'/': 3, b'0': 4, b'1': 5, b'2': 6, b'3': 7, b'4': 8}` | 15 | | SIZE\_TO\_BIN | `{1: b'(', 2: b')', 3: b'*', 4: b'+', 5: b','}` | 16 | | SIZE\_TO\_NINT | `{1: b'7', 2: b'8', 3: b'9', 4: b':', 5: b';', 6: b'<', 7: b'=', 8: b'>'}` | 17 | | SIZE\_TO\_PINT | `{1: b'-', 2: b'.', 3: b'/', 4: b'0', 5: b'1', 6: b'2', 7: b'3', 8: b'4'}` | 18 | | SIZE\_TO\_STR | `{1: b'A', 2: b'B', 3: b'C', 4: b'D', 5: b'E', 6: b'F', 7: b'G', 8: b'H', 9: b'I', 10: b'J', 11: b'K', 12: b'L', 13: b'M', 14: b'N', 15: b'O', 16: b'P', 17: b'Q', 18: b'R', 19: b'S', 20: b'T', 21: b'U', 22: b'V', 23: b'W', 24: b'X', 25: b'Y', 26: b'Z', 27: b'[', 28: b'\\', 29: b']', 30: b'^', 31: b'_', 32: b'`'}` | 19 | | SIZE\_TO\_VARSTR | `{1: b'b', 2: b'c', 3: b'd', 4: b'e', 5: b'f'}` | 20 | | STR\_TO\_SIZE | `{b'A': 1, b'B': 2, b'C': 3, b'D': 4, b'E': 5, b'F': 6, b'G': 7, b'H': 8, b'I': 9, b'J': 10, b'K': 11, b'L': 12, b'M': 13, b'N': 14, b'O': 15, b'P': 16, b'Q': 17, b'R': 18, b'S': 19, b'T': 20, b'U': 21, b'V': 22, b'W': 23, b'X': 24, b'Y': 25, b'Z': 26, b'[': 27, b'\\': 28, b']': 29, b'^': 30, b'_': 31, b'`': 32}` | 21 | | TAG\_TO\_LETTER | `{b'g': 'a', b'h': 'b', b'i': 'c', b'j': 'd', b'k': 'e', b'l': 'f', b'm': 'g', b'n': 'h', b'o': 'i', b'p': 'j', b'q': 'k', b'r': 'l', b's': 'm', b't': 'n', b'u': 'o', b'v': 'p', b'w': 'q', b'x': 'r', b'y': 's', b'z': 't', b'{': 'u', b'|': 'v', b'}': 'w', b'~': 'x', b'\x7f': 'y', b'\x80': 'z', b'\x81': 'A', b'\x82': 'B', b'\x83': 'C', b'\x84': 'D', b'\x85': 'E', b'\x86': 'F', b'\x87': 'G', b'\x88': 'H', b'\x89': 'I', b'\x8a': 'J', b'\x8b': 'K', b'\x8c': 'L', b'\x8d': 'M', b'\x8e': 'N', b'\x8f': 'O', b'\x90': 'P', b'\x91': 'Q', b'\x92': 'R', b'\x93': 'S', b'\x94': 'T', b'\x95': 'U', b'\x96': 'V', b'\x97': 'W', b'\x98': 'X', b'\x99': 'Y', b'\x9a': 'Z'}` | 22 | | VARSTR\_TO\_SIZE | `{b'b': 1, b'c': 2, b'd': 3, b'e': 4, b'f': 5}` | 23 | | tags | `` | 24 | 25 |

Back to top

26 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/__init__/class-Validator.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/__init__/README.md) | [Source](/src/paradict/__init__.py) 3 | 4 | # Class Validator 5 | > Module: [paradict.\_\_init\_\_](/docs/api/modules/paradict/__init__/README.md) 6 | > 7 | > Class: **Validator** 8 | > 9 | > Inheritance: `object` 10 | 11 | Class to validate data against a schema 12 | 13 | ## Properties table 14 | Here are properties exposed in the class: 15 | 16 | | Property | Methods | Description | 17 | | --- | --- | --- | 18 | | schema | _getter_ | No docstring. | 19 | | type\_ref | _getter_ | No docstring. | 20 | 21 |

Back to top

22 | 23 | # Methods within class 24 | Here are methods exposed in the class: 25 | - [\_\_init\_\_](#__init__) 26 | - [validate](#validate) 27 | - [\_ensure\_spec](#_ensure_spec) 28 | - [\_validate](#_validate) 29 | - [\_validate\_datatype](#_validate_datatype) 30 | - [\_validate\_dict](#_validate_dict) 31 | - [\_validate\_list](#_validate_list) 32 | - [\_validate\_obj](#_validate_obj) 33 | - [\_validate\_set](#_validate_set) 34 | 35 | ## \_\_init\_\_ 36 | Init 37 | 38 | ```python 39 | def __init__(self, schema, type_ref=None): 40 | ... 41 | ``` 42 | 43 | | Parameter | Description | 44 | | --- | --- | 45 | | schema | the schema | 46 | | type\_ref | optional TypeRef instance | 47 | 48 |

Back to top

49 | 50 | ## validate 51 | Validate data. Might raise a validation error 52 | 53 | ```python 54 | def validate(self, data): 55 | ... 56 | ``` 57 | 58 |

Back to top

59 | 60 | ## \_ensure\_spec 61 | No docstring 62 | 63 | ```python 64 | def _ensure_spec(self, target, spec): 65 | ... 66 | ``` 67 | 68 |

Back to top

69 | 70 | ## \_validate 71 | No docstring 72 | 73 | ```python 74 | def _validate(self, target, schema): 75 | ... 76 | ``` 77 | 78 |

Back to top

79 | 80 | ## \_validate\_datatype 81 | No docstring 82 | 83 | ```python 84 | def _validate_datatype(self, target, datatype): 85 | ... 86 | ``` 87 | 88 |

Back to top

89 | 90 | ## \_validate\_dict 91 | No docstring 92 | 93 | ```python 94 | def _validate_dict(self, target, schema): 95 | ... 96 | ``` 97 | 98 |

Back to top

99 | 100 | ## \_validate\_list 101 | Schema SHOULD be a list 102 | 103 | ```python 104 | def _validate_list(self, target, schema): 105 | ... 106 | ``` 107 | 108 |

Back to top

109 | 110 | ## \_validate\_obj 111 | No docstring 112 | 113 | ```python 114 | def _validate_obj(self, target, schema): 115 | ... 116 | ``` 117 | 118 |

Back to top

119 | 120 | ## \_validate\_set 121 | Schema SHOULD be a set 122 | 123 | ```python 124 | def _validate_set(self, target, schema): 125 | ... 126 | ``` 127 | 128 |

Back to top

129 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/validator/__init__/class-Validator.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/validator/__init__/README.md) | [Source](/src/paradict/validator/__init__.py) 3 | 4 | # Class Validator 5 | > Module: [paradict.validator.\_\_init\_\_](/docs/api/modules/paradict/validator/__init__/README.md) 6 | > 7 | > Class: **Validator** 8 | > 9 | > Inheritance: `object` 10 | 11 | Class to validate data against a schema 12 | 13 | ## Properties table 14 | Here are properties exposed in the class: 15 | 16 | | Property | Methods | Description | 17 | | --- | --- | --- | 18 | | schema | _getter_ | No docstring. | 19 | | type\_ref | _getter_ | No docstring. | 20 | 21 |

Back to top

22 | 23 | # Methods within class 24 | Here are methods exposed in the class: 25 | - [\_\_init\_\_](#__init__) 26 | - [validate](#validate) 27 | - [\_ensure\_spec](#_ensure_spec) 28 | - [\_validate](#_validate) 29 | - [\_validate\_datatype](#_validate_datatype) 30 | - [\_validate\_dict](#_validate_dict) 31 | - [\_validate\_list](#_validate_list) 32 | - [\_validate\_obj](#_validate_obj) 33 | - [\_validate\_set](#_validate_set) 34 | 35 | ## \_\_init\_\_ 36 | Init 37 | 38 | ```python 39 | def __init__(self, schema, type_ref=None): 40 | ... 41 | ``` 42 | 43 | | Parameter | Description | 44 | | --- | --- | 45 | | schema | the schema | 46 | | type\_ref | optional TypeRef instance | 47 | 48 |

Back to top

49 | 50 | ## validate 51 | Validate data. Might raise a validation error 52 | 53 | ```python 54 | def validate(self, data): 55 | ... 56 | ``` 57 | 58 |

Back to top

59 | 60 | ## \_ensure\_spec 61 | No docstring 62 | 63 | ```python 64 | def _ensure_spec(self, target, spec): 65 | ... 66 | ``` 67 | 68 |

Back to top

69 | 70 | ## \_validate 71 | No docstring 72 | 73 | ```python 74 | def _validate(self, target, schema): 75 | ... 76 | ``` 77 | 78 |

Back to top

79 | 80 | ## \_validate\_datatype 81 | No docstring 82 | 83 | ```python 84 | def _validate_datatype(self, target, datatype): 85 | ... 86 | ``` 87 | 88 |

Back to top

89 | 90 | ## \_validate\_dict 91 | No docstring 92 | 93 | ```python 94 | def _validate_dict(self, target, schema): 95 | ... 96 | ``` 97 | 98 |

Back to top

99 | 100 | ## \_validate\_list 101 | Schema SHOULD be a list 102 | 103 | ```python 104 | def _validate_list(self, target, schema): 105 | ... 106 | ``` 107 | 108 |

Back to top

109 | 110 | ## \_validate\_obj 111 | No docstring 112 | 113 | ```python 114 | def _validate_obj(self, target, schema): 115 | ... 116 | ``` 117 | 118 |

Back to top

119 | 120 | ## \_validate\_set 121 | Schema SHOULD be a set 122 | 123 | ```python 124 | def _validate_set(self, target, schema): 125 | ... 126 | ``` 127 | 128 |

Back to top

129 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/buffered_bin_stream/class-BufferedBinStream.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/deserializer/buffered_bin_stream/README.md) | [Source](/src/paradict/deserializer/buffered_bin_stream.py) 3 | 4 | # Class BufferedBinStream 5 | > Module: [paradict.deserializer.buffered\_bin\_stream](/docs/api/modules/paradict/deserializer/buffered_bin_stream/README.md) 6 | > 7 | > Class: **BufferedBinStream** 8 | > 9 | > Inheritance: `object` 10 | 11 | A FIFO queue for processing binary Paradict data 12 | 13 | ## Properties table 14 | Here are properties exposed in the class: 15 | 16 | | Property | Methods | Description | 17 | | --- | --- | --- | 18 | | buffer | _getter_ | No docstring. | 19 | 20 |

Back to top

21 | 22 | # Methods within class 23 | Here are methods exposed in the class: 24 | - [\_\_init\_\_](#__init__) 25 | - [get](#get) 26 | - [get\_all](#get_all) 27 | - [is\_empty](#is_empty) 28 | - [put](#put) 29 | - [\_clear\_status](#_clear_status) 30 | - [\_read](#_read) 31 | - [\_read\_buffer](#_read_buffer) 32 | - [\_update\_expected\_width\_var](#_update_expected_width_var) 33 | - [\_update\_tag\_var](#_update_tag_var) 34 | 35 | ## \_\_init\_\_ 36 | Initialize self. See help(type(self)) for accurate signature. 37 | 38 | ```python 39 | def __init__(self): 40 | ... 41 | ``` 42 | 43 |

Back to top

44 | 45 | ## get 46 | No docstring 47 | 48 | ```python 49 | def get(self): 50 | ... 51 | ``` 52 | 53 |

Back to top

54 | 55 | ## get\_all 56 | Generator for iteratively getting each tag-payload tuple composing the 57 | raw data stored in the buffer 58 | 59 | ```python 60 | def get_all(self): 61 | ... 62 | ``` 63 | 64 |

Back to top

65 | 66 | ## is\_empty 67 | No docstring 68 | 69 | ```python 70 | def is_empty(self): 71 | ... 72 | ``` 73 | 74 |

Back to top

75 | 76 | ## put 77 | Store binary data in the buffer. This data will then be iteratively 78 | extracted by the 'get' method 79 | 80 | ```python 81 | def put(self, raw): 82 | ... 83 | ``` 84 | 85 |

Back to top

86 | 87 | ## \_clear\_status 88 | No docstring 89 | 90 | ```python 91 | def _clear_status(self): 92 | ... 93 | ``` 94 | 95 |

Back to top

96 | 97 | ## \_read 98 | No docstring 99 | 100 | ```python 101 | def _read(self): 102 | ... 103 | ``` 104 | 105 |

Back to top

106 | 107 | ## \_read\_buffer 108 | No docstring 109 | 110 | ```python 111 | def _read_buffer(self, reader): 112 | ... 113 | ``` 114 | 115 |

Back to top

116 | 117 | ## \_update\_expected\_width\_var 118 | No docstring 119 | 120 | ```python 121 | def _update_expected_width_var(self): 122 | ... 123 | ``` 124 | 125 |

Back to top

126 | 127 | ## \_update\_tag\_var 128 | No docstring 129 | 130 | ```python 131 | def _update_tag_var(self): 132 | ... 133 | ``` 134 | 135 |

Back to top

136 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/scanner/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/deserializer/scanner.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.deserializer.scanner** 6 | 7 | No docstring. 8 | 9 | ## Fields 10 | - [**All fields**](/docs/api/modules/paradict/deserializer/scanner/fields.md) 11 | - BIN\_TO\_SIZE = `{b'(': 1, b')': 2, b'*': 3, b'+': 4, b',': 5}` 12 | - NINT\_TO\_SIZE = `{b'7': 1, b'8': 2, b'9': 3, b':': 4, b';': 5, b'<': 6, b'=': 7, b'>': 8}` 13 | - PINT\_TO\_SIZE = `{b'-': 1, b'.': 2, b'/': 3, b'0': 4, b'1': 5, b'2': 6, b'3': 7, b'4': 8}` 14 | - STR\_TO\_SIZE = `{b'A': 1, b'B': 2, b'C': 3, b'D': 4, b'E': 5, b'F': 6, b'G': 7, b'H': 8, b'I': 9, b'J': 10, b'K': 11, b'L': 12, b'M': 13, b'N': 14, b'O': 15, b'P': 16, b'Q': 17, b'R': 18, b'S': 19, b'T': 20, b'U': 21, b'V': 22, b'W': 23, b'X': 24, b'Y': 25, b'Z': 26, b'[': 27, b'\\': 28, b']': 29, b'^': 30, b'_': 31, b'`': 32}` 15 | - VARSTR\_TO\_SIZE = `{b'b': 1, b'c': 2, b'd': 3, b'e': 4, b'f': 5}` 16 | - os = `` 17 | - paradict = `` 18 | - tags = `` 19 | 20 |

Back to top

21 | 22 | ## Functions 23 | - [**All functions**](/docs/api/modules/paradict/deserializer/scanner/funcs.md) 24 | - [get\_slice\_for\_fixed\_length\_datum](/docs/api/modules/paradict/deserializer/scanner/funcs.md#get_slice_for_fixed_length_datum): This function returns the slice object for datums with fixed-length payload 25 | - [get\_slice\_for\_variable\_length\_datum](/docs/api/modules/paradict/deserializer/scanner/funcs.md#get_slice_for_variable_length_datum): This function is used to generate a slice object for tags with variable-length payload such as: STR_SHORT, STR_MEDIUM, STR_LONG,... 26 | - [process\_bin](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_bin): No docstring. 27 | - [process\_nint\_big](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_nint_big): No docstring. 28 | - [process\_nint\_heavy](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_nint_heavy): No docstring. 29 | - [process\_nintx](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_nintx): No docstring. 30 | - [process\_pint\_big](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_pint_big): No docstring. 31 | - [process\_pint\_heavy](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_pint_heavy): No docstring. 32 | - [process\_pintx](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_pintx): No docstring. 33 | - [process\_str](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_str): No docstring. 34 | - [process\_strx](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_strx): No docstring. 35 | - [process\_tag](/docs/api/modules/paradict/deserializer/scanner/funcs.md#process_tag): No docstring. 36 | - [read\_payload\_size](/docs/api/modules/paradict/deserializer/scanner/funcs.md#read_payload_size): Read the expected size of payload Note that nb is the number of bytes encoding the size of payload 37 | - [scan](/docs/api/modules/paradict/deserializer/scanner/funcs.md#scan): Scan a binary Paradict file object, yielding a tag with the slice object of its associated payload 38 | 39 |

Back to top

40 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/encoder/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/serializer/encoder/README.md) | [Source](/src/paradict/serializer/encoder.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.serializer.encoder](/docs/api/modules/paradict/serializer/encoder/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [encode\_bin](#encode_bin) 9 | - [encode\_bin\_int](#encode_bin_int) 10 | - [encode\_bool](#encode_bool) 11 | - [encode\_complex](#encode_complex) 12 | - [encode\_date](#encode_date) 13 | - [encode\_datetime](#encode_datetime) 14 | - [encode\_float](#encode_float) 15 | - [encode\_hex\_int](#encode_hex_int) 16 | - [encode\_int](#encode_int) 17 | - [encode\_multiline\_str](#encode_multiline_str) 18 | - [encode\_null](#encode_null) 19 | - [encode\_oct\_int](#encode_oct_int) 20 | - [encode\_str](#encode_str) 21 | - [encode\_time](#encode_time) 22 | 23 | ## encode\_bin 24 | No docstring 25 | 26 | ```python 27 | def encode_bin(val): 28 | ... 29 | ``` 30 | 31 |

Back to top

32 | 33 | ## encode\_bin\_int 34 | No docstring 35 | 36 | ```python 37 | def encode_bin_int(val): 38 | ... 39 | ``` 40 | 41 |

Back to top

42 | 43 | ## encode\_bool 44 | No docstring 45 | 46 | ```python 47 | def encode_bool(val): 48 | ... 49 | ``` 50 | 51 |

Back to top

52 | 53 | ## encode\_complex 54 | No docstring 55 | 56 | ```python 57 | def encode_complex(val): 58 | ... 59 | ``` 60 | 61 |

Back to top

62 | 63 | ## encode\_date 64 | Parse date and time with the ISO 8601 format 65 | 66 | ```python 67 | def encode_date(val): 68 | ... 69 | ``` 70 | 71 |

Back to top

72 | 73 | ## encode\_datetime 74 | No docstring 75 | 76 | ```python 77 | def encode_datetime(val): 78 | ... 79 | ``` 80 | 81 |

Back to top

82 | 83 | ## encode\_float 84 | No docstring 85 | 86 | ```python 87 | def encode_float(val): 88 | ... 89 | ``` 90 | 91 |

Back to top

92 | 93 | ## encode\_hex\_int 94 | No docstring 95 | 96 | ```python 97 | def encode_hex_int(val): 98 | ... 99 | ``` 100 | 101 |

Back to top

102 | 103 | ## encode\_int 104 | No docstring 105 | 106 | ```python 107 | def encode_int(val): 108 | ... 109 | ``` 110 | 111 |

Back to top

112 | 113 | ## encode\_multiline\_str 114 | No docstring 115 | 116 | ```python 117 | def encode_multiline_str(val): 118 | ... 119 | ``` 120 | 121 |

Back to top

122 | 123 | ## encode\_null 124 | No docstring 125 | 126 | ```python 127 | def encode_null(val): 128 | ... 129 | ``` 130 | 131 |

Back to top

132 | 133 | ## encode\_oct\_int 134 | No docstring 135 | 136 | ```python 137 | def encode_oct_int(val): 138 | ... 139 | ``` 140 | 141 |

Back to top

142 | 143 | ## encode\_str 144 | No docstring 145 | 146 | ```python 147 | def encode_str(val): 148 | ... 149 | ``` 150 | 151 |

Back to top

152 | 153 | ## encode\_time 154 | No docstring 155 | 156 | ```python 157 | def encode_time(val): 158 | ... 159 | ``` 160 | 161 |

Back to top

162 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/xtypes/__init__/class-Obj.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/xtypes/__init__/README.md) | [Source](/src/paradict/xtypes/__init__.py) 3 | 4 | # Class Obj 5 | > Module: [paradict.xtypes.\_\_init\_\_](/docs/api/modules/paradict/xtypes/__init__/README.md) 6 | > 7 | > Class: **Obj** 8 | > 9 | > Inheritance: `collections.UserDict` 10 | 11 | Box to hold an Extension Object. Such objects behave like a dictionary. 12 | An object builder is passed as argument to the right functions, thus, 13 | the object is consumed/used to build a new valid data value 14 | 15 | ## Fields table 16 | Here are fields exposed in the class: 17 | 18 | | Field | Value | 19 | | --- | --- | 20 | | \_MutableMapping\_\_marker | `` | 21 | | \_abc\_impl | `<_abc._abc_data object at 0x794d9e1f0580>` | 22 | 23 |

Back to top

24 | 25 | # Methods within class 26 | Here are methods exposed in the class: 27 | - [\_\_init\_\_](#__init__) 28 | - [clear](#clear) 29 | - [copy](#copy) 30 | - [fromkeys](#fromkeys) 31 | - [get](#get) 32 | - [items](#items) 33 | - [keys](#keys) 34 | - [pop](#pop) 35 | - [popitem](#popitem) 36 | - [setdefault](#setdefault) 37 | - [update](#update) 38 | - [values](#values) 39 | 40 | ## \_\_init\_\_ 41 | Initialize self. See help(type(self)) for accurate signature. 42 | 43 | ```python 44 | def __init__(self, dict=None, /, **kwargs): 45 | ... 46 | ``` 47 | 48 |

Back to top

49 | 50 | ## clear 51 | D.clear() -> None. Remove all items from D. 52 | 53 | ```python 54 | def clear(self): 55 | ... 56 | ``` 57 | 58 |

Back to top

59 | 60 | ## copy 61 | No docstring 62 | 63 | ```python 64 | def copy(self): 65 | ... 66 | ``` 67 | 68 |

Back to top

69 | 70 | ## fromkeys 71 | No docstring 72 | 73 | ```python 74 | @classmethod 75 | def fromkeys(iterable, value=None): 76 | ... 77 | ``` 78 | 79 |

Back to top

80 | 81 | ## get 82 | D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. 83 | 84 | ```python 85 | def get(self, key, default=None): 86 | ... 87 | ``` 88 | 89 |

Back to top

90 | 91 | ## items 92 | D.items() -> a set-like object providing a view on D's items 93 | 94 | ```python 95 | def items(self): 96 | ... 97 | ``` 98 | 99 |

Back to top

100 | 101 | ## keys 102 | D.keys() -> a set-like object providing a view on D's keys 103 | 104 | ```python 105 | def keys(self): 106 | ... 107 | ``` 108 | 109 |

Back to top

110 | 111 | ## pop 112 | D.pop(k[,d]) -> v, remove specified key and return the corresponding value. 113 | If key is not found, d is returned if given, otherwise KeyError is raised. 114 | 115 | ```python 116 | def pop(self, key, default=): 117 | ... 118 | ``` 119 | 120 |

Back to top

121 | 122 | ## popitem 123 | D.popitem() -> (k, v), remove and return some (key, value) pair 124 | as a 2-tuple; but raise KeyError if D is empty. 125 | 126 | ```python 127 | def popitem(self): 128 | ... 129 | ``` 130 | 131 |

Back to top

132 | 133 | ## setdefault 134 | D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D 135 | 136 | ```python 137 | def setdefault(self, key, default=None): 138 | ... 139 | ``` 140 | 141 |

Back to top

142 | 143 | ## update 144 | D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. 145 | If E present and has a .keys() method, does: for k in E: D[k] = E[k] 146 | If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v 147 | In either case, this is followed by: for k, v in F.items(): D[k] = v 148 | 149 | ```python 150 | def update(self, other=(), /, **kwds): 151 | ... 152 | ``` 153 | 154 |

Back to top

155 | 156 | ## values 157 | D.values() -> an object providing a view on D's values 158 | 159 | ```python 160 | def values(self): 161 | ... 162 | ``` 163 | 164 |

Back to top

165 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/xtypes/__init__/class-Grid.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/xtypes/__init__/README.md) | [Source](/src/paradict/xtypes/__init__.py) 3 | 4 | # Class Grid 5 | > Module: [paradict.xtypes.\_\_init\_\_](/docs/api/modules/paradict/xtypes/__init__/README.md) 6 | > 7 | > Class: **Grid** 8 | > 9 | > Inheritance: `collections.UserList` 10 | 11 | Box to hold a grid. A grid is made of numbers and should 12 | be consistent (rows should be of same size) 13 | 14 | Example: 15 | ``` 16 | # a grid with 2 rows and 3 columns 17 | my_grid = Grid([(0, 1, 0), 18 | (1, 0, 1)]) 19 | ``` 20 | 21 | ## Fields table 22 | Here are fields exposed in the class: 23 | 24 | | Field | Value | 25 | | --- | --- | 26 | | \_abc\_impl | `<_abc._abc_data object at 0x794d9e1e8880>` | 27 | 28 |

Back to top

29 | 30 | # Methods within class 31 | Here are methods exposed in the class: 32 | - [\_\_init\_\_](#__init__) 33 | - [append](#append) 34 | - [clear](#clear) 35 | - [copy](#copy) 36 | - [count](#count) 37 | - [extend](#extend) 38 | - [index](#index) 39 | - [insert](#insert) 40 | - [pop](#pop) 41 | - [remove](#remove) 42 | - [reverse](#reverse) 43 | - [sort](#sort) 44 | - [\_UserList\_\_cast](#_userlist__cast) 45 | 46 | ## \_\_init\_\_ 47 | Initialize self. See help(type(self)) for accurate signature. 48 | 49 | ```python 50 | def __init__(self, initlist=None): 51 | ... 52 | ``` 53 | 54 |

Back to top

55 | 56 | ## append 57 | S.append(value) -- append value to the end of the sequence 58 | 59 | ```python 60 | def append(self, item): 61 | ... 62 | ``` 63 | 64 |

Back to top

65 | 66 | ## clear 67 | S.clear() -> None -- remove all items from S 68 | 69 | ```python 70 | def clear(self): 71 | ... 72 | ``` 73 | 74 |

Back to top

75 | 76 | ## copy 77 | No docstring 78 | 79 | ```python 80 | def copy(self): 81 | ... 82 | ``` 83 | 84 |

Back to top

85 | 86 | ## count 87 | S.count(value) -> integer -- return number of occurrences of value 88 | 89 | ```python 90 | def count(self, item): 91 | ... 92 | ``` 93 | 94 |

Back to top

95 | 96 | ## extend 97 | S.extend(iterable) -- extend sequence by appending elements from the iterable 98 | 99 | ```python 100 | def extend(self, other): 101 | ... 102 | ``` 103 | 104 |

Back to top

105 | 106 | ## index 107 | S.index(value, [start, [stop]]) -> integer -- return first index of value. 108 | Raises ValueError if the value is not present. 109 | 110 | Supporting start and stop arguments is optional, but 111 | recommended. 112 | 113 | ```python 114 | def index(self, item, *args): 115 | ... 116 | ``` 117 | 118 |

Back to top

119 | 120 | ## insert 121 | S.insert(index, value) -- insert value before index 122 | 123 | ```python 124 | def insert(self, i, item): 125 | ... 126 | ``` 127 | 128 |

Back to top

129 | 130 | ## pop 131 | S.pop([index]) -> item -- remove and return item at index (default last). 132 | Raise IndexError if list is empty or index is out of range. 133 | 134 | ```python 135 | def pop(self, i=-1): 136 | ... 137 | ``` 138 | 139 |

Back to top

140 | 141 | ## remove 142 | S.remove(value) -- remove first occurrence of value. 143 | Raise ValueError if the value is not present. 144 | 145 | ```python 146 | def remove(self, item): 147 | ... 148 | ``` 149 | 150 |

Back to top

151 | 152 | ## reverse 153 | S.reverse() -- reverse *IN PLACE* 154 | 155 | ```python 156 | def reverse(self): 157 | ... 158 | ``` 159 | 160 |

Back to top

161 | 162 | ## sort 163 | No docstring 164 | 165 | ```python 166 | def sort(self, /, *args, **kwds): 167 | ... 168 | ``` 169 | 170 |

Back to top

171 | 172 | ## \_UserList\_\_cast 173 | No docstring 174 | 175 | ```python 176 | def _UserList__cast(self, other): 177 | ... 178 | ``` 179 | 180 |

Back to top

181 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/typeref/__init__/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/typeref/__init__.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.typeref.\_\_init\_\_** 6 | 7 | TypeRef for type specs and customization 8 | 9 | ## Classes 10 | - [**TypeRef**](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md): This class represents a mechanism for customizing Python types allowed for (de)serializing data with Paradict classes and functi... 11 | - [adapters](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 12 | - [bin\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 13 | - [bin\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 14 | - [bool\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 15 | - [bool\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 16 | - [complex\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 17 | - [complex\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 18 | - [date\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 19 | - [date\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 20 | - [datetime\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 21 | - [datetime\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 22 | - [dict\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 23 | - [dict\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 24 | - [float\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 25 | - [float\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 26 | - [grid\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 27 | - [grid\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 28 | - [int\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 29 | - [int\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 30 | - [list\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 31 | - [list\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 32 | - [obj\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 33 | - [obj\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 34 | - [set\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 35 | - [set\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 36 | - [str\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 37 | - [str\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 38 | - [time\_type](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 39 | - [time\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#properties-table); _getter, setter_ 40 | - [adapt](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#adapt): Checks the 'adapters' attribute to find out if there is an adapter function registered for the type of the data argument. Then, ... 41 | - [check](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#check): This function accepts as argument a Python type, and return a Datatype instance if the type is supported/registered, else return... 42 | - [\_create\_map](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#_create_map): No docstring. 43 | - [\_update\_types](/docs/api/modules/paradict/typeref/__init__/class-TypeRef.md#_update_types): No docstring. 44 | 45 |

Back to top

46 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/scanner/funcs.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/deserializer/scanner/README.md) | [Source](/src/paradict/deserializer/scanner.py) 3 | 4 | # Functions within module 5 | > Module: [paradict.deserializer.scanner](/docs/api/modules/paradict/deserializer/scanner/README.md) 6 | 7 | Here are functions exposed in the module: 8 | - [get\_slice\_for\_fixed\_length\_datum](#get_slice_for_fixed_length_datum) 9 | - [get\_slice\_for\_variable\_length\_datum](#get_slice_for_variable_length_datum) 10 | - [process\_bin](#process_bin) 11 | - [process\_nint\_big](#process_nint_big) 12 | - [process\_nint\_heavy](#process_nint_heavy) 13 | - [process\_nintx](#process_nintx) 14 | - [process\_pint\_big](#process_pint_big) 15 | - [process\_pint\_heavy](#process_pint_heavy) 16 | - [process\_pintx](#process_pintx) 17 | - [process\_str](#process_str) 18 | - [process\_strx](#process_strx) 19 | - [process\_tag](#process_tag) 20 | - [read\_payload\_size](#read_payload_size) 21 | - [scan](#scan) 22 | 23 | ## get\_slice\_for\_fixed\_length\_datum 24 | This function returns the slice object for 25 | datums with fixed-length payload 26 | 27 | ```python 28 | def get_slice_for_fixed_length_datum(file, payload_size): 29 | ... 30 | ``` 31 | 32 |

Back to top

33 | 34 | ## get\_slice\_for\_variable\_length\_datum 35 | This function is used to generate a slice object for 36 | tags with variable-length payload such as: 37 | STR_SHORT, STR_MEDIUM, STR_LONG, STR_BIG, STR_HEAVY, 38 | BIN_SHORT, BIN_MEDIUM, BIN_LONG, BIN_BIG, and BIN_HEAVY. 39 | 40 | nb is the number of bytes encoding the size of payload 41 | 42 | This function returns a slice object 43 | 44 | ```python 45 | def get_slice_for_variable_length_datum(file, nb): 46 | ... 47 | ``` 48 | 49 |

Back to top

50 | 51 | ## process\_bin 52 | No docstring 53 | 54 | ```python 55 | def process_bin(file, tag): 56 | ... 57 | ``` 58 | 59 |

Back to top

60 | 61 | ## process\_nint\_big 62 | No docstring 63 | 64 | ```python 65 | def process_nint_big(file, tag): 66 | ... 67 | ``` 68 | 69 |

Back to top

70 | 71 | ## process\_nint\_heavy 72 | No docstring 73 | 74 | ```python 75 | def process_nint_heavy(file, tag): 76 | ... 77 | ``` 78 | 79 |

Back to top

80 | 81 | ## process\_nintx 82 | No docstring 83 | 84 | ```python 85 | def process_nintx(file, tag): 86 | ... 87 | ``` 88 | 89 |

Back to top

90 | 91 | ## process\_pint\_big 92 | No docstring 93 | 94 | ```python 95 | def process_pint_big(file, tag): 96 | ... 97 | ``` 98 | 99 |

Back to top

100 | 101 | ## process\_pint\_heavy 102 | No docstring 103 | 104 | ```python 105 | def process_pint_heavy(file, tag): 106 | ... 107 | ``` 108 | 109 |

Back to top

110 | 111 | ## process\_pintx 112 | No docstring 113 | 114 | ```python 115 | def process_pintx(file, tag): 116 | ... 117 | ``` 118 | 119 |

Back to top

120 | 121 | ## process\_str 122 | No docstring 123 | 124 | ```python 125 | def process_str(file, tag): 126 | ... 127 | ``` 128 | 129 |

Back to top

130 | 131 | ## process\_strx 132 | No docstring 133 | 134 | ```python 135 | def process_strx(file, tag): 136 | ... 137 | ``` 138 | 139 |

Back to top

140 | 141 | ## process\_tag 142 | No docstring 143 | 144 | ```python 145 | def process_tag(file, tag): 146 | ... 147 | ``` 148 | 149 |

Back to top

150 | 151 | ## read\_payload\_size 152 | Read the expected size of payload 153 | Note that nb is the number of bytes encoding the size of payload 154 | 155 | ```python 156 | def read_payload_size(file, nb): 157 | ... 158 | ``` 159 | 160 |

Back to top

161 | 162 | ## scan 163 | Scan a binary Paradict file object, yielding a tag with 164 | the slice object of its associated payload 165 | 166 | ```python 167 | def scan(file): 168 | ... 169 | ``` 170 | 171 |

Back to top

172 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/unpacker/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/deserializer/unpacker.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.deserializer.unpacker** 6 | 7 | No docstring. 8 | 9 | ## Classes 10 | - [**Unpacker**](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md): Class to convert some binary Paradict data into a Python dict 11 | - [data](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#properties-table); _getter_ 12 | - [obj\_builder](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#properties-table); _getter, setter_ 13 | - [queue](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#properties-table); _getter, setter_ 14 | - [receiver](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#properties-table); _getter, setter_ 15 | - [type\_ref](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#properties-table); _getter, setter_ 16 | - [feed](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#feed): Feed in arbitrary chunks of data 17 | - [process](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#process): Pass in a tag and its associated payload 18 | - [\_cleanup\_stack](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_cleanup_stack): No docstring. 19 | - [\_consume\_block](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_consume_block): No docstring. 20 | - [\_create\_alpha\_context](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_create_alpha_context): No docstring. 21 | - [\_create\_beta\_context](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_create_beta_context): No docstring. 22 | - [\_create\_context](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_create_context): No docstring. 23 | - [\_get\_context](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_get_context): No docstring. 24 | - [\_interpret](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_interpret): No docstring. 25 | - [\_remove\_block](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_remove_block): No docstring. 26 | - [\_remove\_context](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_remove_context): No docstring. 27 | - [\_unpack\_bin](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_bin): No docstring. 28 | - [\_unpack\_bin\_int](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_bin_int): No docstring. 29 | - [\_unpack\_bool](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_bool): No docstring. 30 | - [\_unpack\_complex](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_complex): No docstring. 31 | - [\_unpack\_date](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_date): No docstring. 32 | - [\_unpack\_datetime](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_datetime): No docstring. 33 | - [\_unpack\_float](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_float): No docstring. 34 | - [\_unpack\_float\_misc](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_float_misc): No docstring. 35 | - [\_unpack\_grid](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_grid): No docstring. 36 | - [\_unpack\_hex\_int](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_hex_int): No docstring. 37 | - [\_unpack\_int](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_int): No docstring. 38 | - [\_unpack\_null](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_null): No docstring. 39 | - [\_unpack\_obj](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_obj): No docstring. 40 | - [\_unpack\_oct\_int](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_oct_int): No docstring. 41 | - [\_unpack\_payload](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_payload): No docstring. 42 | - [\_unpack\_str](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_str): No docstring. 43 | - [\_unpack\_time](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_unpack_time): No docstring. 44 | - [\_update\_context](/docs/api/modules/paradict/deserializer/unpacker/class-Unpacker.md#_update_context): No docstring. 45 | 46 |

Back to top

47 | -------------------------------------------------------------------------------- /tests/box/test_box.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from paradict import xtypes 3 | 4 | 5 | class TestHexInt(unittest.TestCase): 6 | 7 | def test_with_int(self): 8 | for key, val in {0: 0, 9 | 1: 1, 10 | -255: -255}.items(): 11 | with self.subTest("Val: {}".format(key)): 12 | r = xtypes.HexInt(key) 13 | self.assertEqual(val, r) 14 | 15 | def test_with_str_int(self): 16 | for key, val in {"0": 0, 17 | "1": 1, 18 | "-255": -255, 19 | "0x0": 0, 20 | "0x1": 1, 21 | "-0xff": -255}.items(): 22 | with self.subTest("Val: {}".format(key)): 23 | r = xtypes.HexInt(key) 24 | self.assertEqual(val, r) 25 | 26 | def test_string_output(self): 27 | for key, val in {0: "0x0", 28 | 1: "0x1", 29 | -255: "-0xff", 30 | "0x0": "0x0", 31 | "0x1": "0x1", 32 | "-0x000000ff": "-0x0000_00ff"}.items(): 33 | with self.subTest("Val: {}".format(key)): 34 | r = str(xtypes.HexInt(key)).lower() 35 | self.assertEqual(val, r) 36 | 37 | def test_with_different_base(self): 38 | r = xtypes.HexInt("-0b11111111") 39 | self.assertEqual(-255, r) 40 | 41 | def test_string_output_with_different_base(self): 42 | r = xtypes.HexInt("-0b1111_1111") # the number of digits counts 43 | self.assertEqual("-0xff", str(r).lower()) 44 | 45 | 46 | class TestOctInt(unittest.TestCase): 47 | 48 | def test_with_int(self): 49 | for key, val in {0: 0, 50 | 1: 1, 51 | -255: -255}.items(): 52 | with self.subTest("Val: {}".format(key)): 53 | r = xtypes.OctInt(key) 54 | self.assertEqual(val, r) 55 | 56 | def test_with_str_int(self): 57 | for key, val in {"0": 0, 58 | "1": 1, 59 | "-255": -255, 60 | "0o0": 0, 61 | "0o1": 1, 62 | "-0o377": -255}.items(): 63 | with self.subTest("Val: {}".format(key)): 64 | r = xtypes.OctInt(key) 65 | self.assertEqual(val, r) 66 | 67 | def test_string_output(self): 68 | for key, val in {0: "0o0", 69 | 1: "0o1", 70 | -255: "-0o377", 71 | "0o0": "0o0", 72 | "0o1": "0o1", 73 | "-0o000377": "-0o000_377"}.items(): 74 | with self.subTest("Val: {}".format(key)): 75 | r = str(xtypes.OctInt(key)).lower() 76 | self.assertEqual(val, r) 77 | 78 | def test_with_different_base(self): 79 | r = xtypes.OctInt("-0xff") 80 | self.assertEqual(-255, r) 81 | 82 | def test_string_output_with_different_base(self): 83 | r = xtypes.OctInt("-0x00ff") 84 | self.assertEqual("-0o377", str(r).lower()) 85 | 86 | 87 | class TestBinInt(unittest.TestCase): 88 | 89 | def test_with_int(self): 90 | for key, val in {0: 0, 91 | 1: 1, 92 | -255: -255}.items(): 93 | with self.subTest("Val: {}".format(key)): 94 | r = xtypes.BinInt(key) 95 | self.assertEqual(val, r) 96 | 97 | def test_with_str_int(self): 98 | for key, val in {"0": 0, 99 | "1": 1, 100 | "-255": -255, 101 | "0b0": 0, 102 | "0b1": 1, 103 | "-0b11111111": -255}.items(): 104 | with self.subTest("Val: {}".format(key)): 105 | r = xtypes.BinInt(key) 106 | self.assertEqual(val, r) 107 | 108 | def test_string_output(self): 109 | for key, val in {0: "0b0", 110 | 1: "0b1", 111 | -255: "-0b1111_1111", 112 | "0b0": "0b0", 113 | "0b1": "0b1", 114 | "-0b000011111111": "-0b0000_1111_1111"}.items(): 115 | with self.subTest("Val: {}".format(key)): 116 | r = str(xtypes.BinInt(key)).lower() 117 | self.assertEqual(val, r) 118 | 119 | def test_with_different_base(self): 120 | r = xtypes.BinInt("-0xff") 121 | self.assertEqual(-255, r) 122 | 123 | def test_string_output_with_different_base(self): 124 | r = xtypes.BinInt("-0xff") 125 | self.assertEqual("-0b1111_1111", str(r).lower()) 126 | 127 | 128 | if __name__ == '__main__': 129 | unittest.main() 130 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/__init__/class-TypeRef.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/__init__/README.md) | [Source](/src/paradict/__init__.py) 3 | 4 | # Class TypeRef 5 | > Module: [paradict.\_\_init\_\_](/docs/api/modules/paradict/__init__/README.md) 6 | > 7 | > Class: **TypeRef** 8 | > 9 | > Inheritance: `object` 10 | 11 | This class represents a mechanism for customizing 12 | Python types allowed for (de)serializing data with Paradict classes and functions. 13 | For example, one might want to only use Python OrderedDict instead of the regular 14 | dict. In this case, just create a TypeRef instance, and make sure that you 15 | set the dict_type attribute via the construction or a property. 16 | 17 | ```python 18 | type_ref = TypeRef(dict_type=OrderedDict) 19 | ``` 20 | 21 | Still with this class, one could 'adapt' some exotic datatype so it will 22 | conform with Python datatypes allowed in Paradict (de)serialization. 23 | To do so, set the adapters attribute like this: 24 | 25 | ```python 26 | adapters = {MyExoticType1: adapterFunction1, MyExoticType2: adapterFunction2} 27 | type_ref = TypeRef(adapters=adapters) 28 | ``` 29 | 30 | ## Properties table 31 | Here are properties exposed in the class: 32 | 33 | | Property | Methods | Description | 34 | | --- | --- | --- | 35 | | adapters | _getter, setter_ | No docstring. | 36 | | bin\_type | _getter, setter_ | No docstring. | 37 | | bin\_types | _getter, setter_ | No docstring. | 38 | | bool\_type | _getter, setter_ | No docstring. | 39 | | bool\_types | _getter, setter_ | No docstring. | 40 | | complex\_type | _getter, setter_ | No docstring. | 41 | | complex\_types | _getter, setter_ | No docstring. | 42 | | date\_type | _getter, setter_ | No docstring. | 43 | | date\_types | _getter, setter_ | No docstring. | 44 | | datetime\_type | _getter, setter_ | No docstring. | 45 | | datetime\_types | _getter, setter_ | No docstring. | 46 | | dict\_type | _getter, setter_ | No docstring. | 47 | | dict\_types | _getter, setter_ | No docstring. | 48 | | float\_type | _getter, setter_ | No docstring. | 49 | | float\_types | _getter, setter_ | No docstring. | 50 | | grid\_type | _getter, setter_ | No docstring. | 51 | | grid\_types | _getter, setter_ | No docstring. | 52 | | int\_type | _getter, setter_ | No docstring. | 53 | | int\_types | _getter, setter_ | No docstring. | 54 | | list\_type | _getter, setter_ | No docstring. | 55 | | list\_types | _getter, setter_ | No docstring. | 56 | | obj\_type | _getter, setter_ | No docstring. | 57 | | obj\_types | _getter, setter_ | No docstring. | 58 | | set\_type | _getter, setter_ | No docstring. | 59 | | set\_types | _getter, setter_ | No docstring. | 60 | | str\_type | _getter, setter_ | No docstring. | 61 | | str\_types | _getter, setter_ | No docstring. | 62 | | time\_type | _getter, setter_ | No docstring. | 63 | | time\_types | _getter, setter_ | No docstring. | 64 | 65 |

Back to top

66 | 67 | # Methods within class 68 | Here are methods exposed in the class: 69 | - [\_\_init\_\_](#__init__) 70 | - [adapt](#adapt) 71 | - [check](#check) 72 | - [\_create\_map](#_create_map) 73 | - [\_update\_types](#_update_types) 74 | 75 | ## \_\_init\_\_ 76 | Initialize self. See help(type(self)) for accurate signature. 77 | 78 | ```python 79 | def __init__(self, adapters=None, dict_type=None, list_type=None, set_type=None, obj_type=None, dict_types=None, list_types=None, set_types=None, obj_types=None, bin_type=None, bool_type=None, complex_type=None, date_type=None, datetime_type=None, float_type=None, grid_type=None, int_type=None, str_type=None, time_type=None, bin_types=None, bool_types=None, complex_types=None, date_types=None, datetime_types=None, float_types=None, grid_types=None, int_types=None, str_types=None, time_types=None): 80 | ... 81 | ``` 82 | 83 |

Back to top

84 | 85 | ## adapt 86 | Checks the 'adapters' attribute to find out if there is 87 | an adapter function registered for the type of the data argument. 88 | Then, calls the adapter on the value. 89 | 90 | ```python 91 | def adapt(self, value): 92 | ... 93 | ``` 94 | 95 | | Parameter | Description | 96 | | --- | --- | 97 | | value | the data value to adapt is an arbitrary Python object | 98 | 99 | ### Value to return 100 | Returns the adapted value or the same value if no adapter is registered for its type 101 | 102 |

Back to top

103 | 104 | ## check 105 | This function accepts as argument a Python type, and return 106 | a Datatype instance if the type is supported/registered, else returns None 107 | 108 | ```python 109 | def check(self, dtype): 110 | ... 111 | ``` 112 | 113 |

Back to top

114 | 115 | ## \_create\_map 116 | No docstring 117 | 118 | ```python 119 | def _create_map(self): 120 | ... 121 | ``` 122 | 123 |

Back to top

124 | 125 | ## \_update\_types 126 | No docstring 127 | 128 | ```python 129 | def _update_types(self, name, datatype): 130 | ... 131 | ``` 132 | 133 |

Back to top

134 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/typeref/__init__/class-TypeRef.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/typeref/__init__/README.md) | [Source](/src/paradict/typeref/__init__.py) 3 | 4 | # Class TypeRef 5 | > Module: [paradict.typeref.\_\_init\_\_](/docs/api/modules/paradict/typeref/__init__/README.md) 6 | > 7 | > Class: **TypeRef** 8 | > 9 | > Inheritance: `object` 10 | 11 | This class represents a mechanism for customizing 12 | Python types allowed for (de)serializing data with Paradict classes and functions. 13 | For example, one might want to only use Python OrderedDict instead of the regular 14 | dict. In this case, just create a TypeRef instance, and make sure that you 15 | set the dict_type attribute via the construction or a property. 16 | 17 | ```python 18 | type_ref = TypeRef(dict_type=OrderedDict) 19 | ``` 20 | 21 | Still with this class, one could 'adapt' some exotic datatype so it will 22 | conform with Python datatypes allowed in Paradict (de)serialization. 23 | To do so, set the adapters attribute like this: 24 | 25 | ```python 26 | adapters = {MyExoticType1: adapterFunction1, MyExoticType2: adapterFunction2} 27 | type_ref = TypeRef(adapters=adapters) 28 | ``` 29 | 30 | ## Properties table 31 | Here are properties exposed in the class: 32 | 33 | | Property | Methods | Description | 34 | | --- | --- | --- | 35 | | adapters | _getter, setter_ | No docstring. | 36 | | bin\_type | _getter, setter_ | No docstring. | 37 | | bin\_types | _getter, setter_ | No docstring. | 38 | | bool\_type | _getter, setter_ | No docstring. | 39 | | bool\_types | _getter, setter_ | No docstring. | 40 | | complex\_type | _getter, setter_ | No docstring. | 41 | | complex\_types | _getter, setter_ | No docstring. | 42 | | date\_type | _getter, setter_ | No docstring. | 43 | | date\_types | _getter, setter_ | No docstring. | 44 | | datetime\_type | _getter, setter_ | No docstring. | 45 | | datetime\_types | _getter, setter_ | No docstring. | 46 | | dict\_type | _getter, setter_ | No docstring. | 47 | | dict\_types | _getter, setter_ | No docstring. | 48 | | float\_type | _getter, setter_ | No docstring. | 49 | | float\_types | _getter, setter_ | No docstring. | 50 | | grid\_type | _getter, setter_ | No docstring. | 51 | | grid\_types | _getter, setter_ | No docstring. | 52 | | int\_type | _getter, setter_ | No docstring. | 53 | | int\_types | _getter, setter_ | No docstring. | 54 | | list\_type | _getter, setter_ | No docstring. | 55 | | list\_types | _getter, setter_ | No docstring. | 56 | | obj\_type | _getter, setter_ | No docstring. | 57 | | obj\_types | _getter, setter_ | No docstring. | 58 | | set\_type | _getter, setter_ | No docstring. | 59 | | set\_types | _getter, setter_ | No docstring. | 60 | | str\_type | _getter, setter_ | No docstring. | 61 | | str\_types | _getter, setter_ | No docstring. | 62 | | time\_type | _getter, setter_ | No docstring. | 63 | | time\_types | _getter, setter_ | No docstring. | 64 | 65 |

Back to top

66 | 67 | # Methods within class 68 | Here are methods exposed in the class: 69 | - [\_\_init\_\_](#__init__) 70 | - [adapt](#adapt) 71 | - [check](#check) 72 | - [\_create\_map](#_create_map) 73 | - [\_update\_types](#_update_types) 74 | 75 | ## \_\_init\_\_ 76 | Initialize self. See help(type(self)) for accurate signature. 77 | 78 | ```python 79 | def __init__(self, adapters=None, dict_type=None, list_type=None, set_type=None, obj_type=None, dict_types=None, list_types=None, set_types=None, obj_types=None, bin_type=None, bool_type=None, complex_type=None, date_type=None, datetime_type=None, float_type=None, grid_type=None, int_type=None, str_type=None, time_type=None, bin_types=None, bool_types=None, complex_types=None, date_types=None, datetime_types=None, float_types=None, grid_types=None, int_types=None, str_types=None, time_types=None): 80 | ... 81 | ``` 82 | 83 |

Back to top

84 | 85 | ## adapt 86 | Checks the 'adapters' attribute to find out if there is 87 | an adapter function registered for the type of the data argument. 88 | Then, calls the adapter on the value. 89 | 90 | ```python 91 | def adapt(self, value): 92 | ... 93 | ``` 94 | 95 | | Parameter | Description | 96 | | --- | --- | 97 | | value | the data value to adapt is an arbitrary Python object | 98 | 99 | ### Value to return 100 | Returns the adapted value or the same value if no adapter is registered for its type 101 | 102 |

Back to top

103 | 104 | ## check 105 | This function accepts as argument a Python type, and return 106 | a Datatype instance if the type is supported/registered, else returns None 107 | 108 | ```python 109 | def check(self, dtype): 110 | ... 111 | ``` 112 | 113 |

Back to top

114 | 115 | ## \_create\_map 116 | No docstring 117 | 118 | ```python 119 | def _create_map(self): 120 | ... 121 | ``` 122 | 123 |

Back to top

124 | 125 | ## \_update\_types 126 | No docstring 127 | 128 | ```python 129 | def _update_types(self, name, datatype): 130 | ... 131 | ``` 132 | 133 |

Back to top

134 | -------------------------------------------------------------------------------- /src/paradict/deserializer/scanner.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import paradict.io_text 4 | from paradict import tags 5 | from paradict.tags.mappings import (PINT_TO_SIZE, 6 | NINT_TO_SIZE, BIN_TO_SIZE, 7 | VARSTR_TO_SIZE, STR_TO_SIZE) 8 | 9 | 10 | def scan(file): 11 | """Scan a binary Paradict file object, yielding a tag with 12 | the slice object of its associated payload""" 13 | file.seek(0) 14 | while 1: 15 | tag = file.read(1) 16 | if not tag: 17 | return 18 | file.seek(-1, os.SEEK_CUR) # put cursor back to original position 19 | # STRx 20 | if tags.STR_8 <= tag <= tags.STR_256: 21 | slice_object = process_strx(file, tag) 22 | # STR 23 | elif tag in (tags.STR_SHORT, 24 | tags.STR_MEDIUM, 25 | tags.STR_LONG, 26 | tags.STR_BIG, 27 | tags.STR_HEAVY): 28 | slice_object = process_str(file, tag) 29 | # BIN 30 | elif tag in (tags.BIN_SHORT, 31 | tags.BIN_MEDIUM, 32 | tags.BIN_LONG, 33 | tags.BIN_BIG, 34 | tags.BIN_HEAVY): 35 | slice_object = process_bin(file, tag) 36 | # PINTx 37 | elif tags.PINT_8 <= tag <= tags.PINT_64: 38 | slice_object = process_pintx(file, tag) 39 | # PINT_BIG 40 | elif tag == tags.PINT_BIG: 41 | slice_object = process_pint_big(file, tag) 42 | # PINT_HEAVY 43 | elif tag == tags.PINT_HEAVY: 44 | slice_object = process_pint_heavy(file, tag) 45 | # NINTx 46 | elif tags.NINT_8 <= tag <= tags.NINT_64: 47 | slice_object = process_nintx(file, tag) 48 | # NINT_BIG 49 | elif tag == tags.NINT_BIG: 50 | slice_object = process_nint_big(file, tag) 51 | # NINT_HEAVY 52 | elif tag == tags.NINT_HEAVY: 53 | slice_object = process_nint_heavy(file, tag) 54 | # else... 55 | else: 56 | slice_object = process_tag(file, tag) 57 | yield tag, slice_object 58 | 59 | 60 | def read_payload_size(file, nb): 61 | """ 62 | Read the expected size of payload 63 | Note that nb is the number of bytes encoding the size of payload 64 | """ 65 | position = file.tell() 66 | r = file.read(nb) 67 | file.seek(position) 68 | return int.from_bytes(r, "little", signed=False) 69 | 70 | 71 | def get_slice_for_fixed_length_datum(file, payload_size): 72 | """ 73 | This function returns the slice object for 74 | datums with fixed-length payload 75 | """ 76 | position = file.tell() 77 | width = 1 + payload_size # 1 tag + size 78 | start, stop = position, position + width 79 | file.seek(stop) 80 | return slice(start, stop) 81 | 82 | 83 | def get_slice_for_variable_length_datum(file, nb): 84 | """ 85 | This function is used to generate a slice object for 86 | tags with variable-length payload such as: 87 | STR_SHORT, STR_MEDIUM, STR_LONG, STR_BIG, STR_HEAVY, 88 | BIN_SHORT, BIN_MEDIUM, BIN_LONG, BIN_BIG, and BIN_HEAVY. 89 | 90 | nb is the number of bytes encoding the size of payload 91 | 92 | This function returns a slice object 93 | """ 94 | # put the file cursor right after the tag 95 | position = file.tell() 96 | file.seek(position+1) 97 | # header_size 98 | header_size = 1 + nb # 1 tag + nb 99 | payload_size = read_payload_size(file, nb) + 1 # \x00 as payload size means 1 100 | # Width is the size (bytes) of the datum (header + payload) 101 | # note that the header is made of tag + byte(s) to store payload size 102 | width = header_size + payload_size 103 | start, stop = position, position + width 104 | file.seek(stop) # move the file cursor to the stop 105 | return slice(start, stop) 106 | 107 | 108 | def process_tag(file, tag): 109 | position, width = file.tell(), 1 110 | start, stop = position, position + width 111 | file.seek(stop) # move the file cursor to the stop 112 | return slice(start, stop) 113 | 114 | 115 | def process_str(file, tag): 116 | # nb is the number of bytes to encode the size of payload 117 | nb = VARSTR_TO_SIZE[tag] 118 | return get_slice_for_variable_length_datum(file, nb) 119 | 120 | 121 | def process_strx(file, tag): 122 | payload_size = STR_TO_SIZE[tag] 123 | return get_slice_for_fixed_length_datum(file, payload_size) 124 | 125 | 126 | def process_bin(file, tag): 127 | # nb is the number of bytes to encode the size of payload 128 | nb = BIN_TO_SIZE[tag] 129 | return get_slice_for_variable_length_datum(file, nb) 130 | 131 | 132 | def process_pint_big(file, tag): 133 | nb = 1 134 | return get_slice_for_variable_length_datum(file, nb) 135 | 136 | 137 | def process_pint_heavy(file, tag): 138 | nb = 2 139 | return get_slice_for_variable_length_datum(file, nb) 140 | 141 | 142 | def process_pintx(file, tag): 143 | payload_size = PINT_TO_SIZE[tag] 144 | return get_slice_for_fixed_length_datum(file, payload_size) 145 | 146 | 147 | def process_nint_big(file, tag): 148 | return process_pint_big(file, tag) 149 | 150 | 151 | def process_nint_heavy(file, tag): 152 | return process_pint_heavy(file, tag) 153 | 154 | 155 | def process_nintx(file, tag): 156 | payload_size = NINT_TO_SIZE[tag] 157 | return get_slice_for_fixed_length_datum(file, payload_size) 158 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/deserializer/decoder/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/deserializer/decoder.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.deserializer.decoder** 6 | 7 | No docstring. 8 | 9 | ## Classes 10 | - [**Decoder**](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md): Class to convert some textual Paradict data into a Python dict 11 | - [data](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#properties-table); _getter_ 12 | - [obj\_builder](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#properties-table); _getter, setter_ 13 | - [queue](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#properties-table); _getter, setter_ 14 | - [receiver](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#properties-table); _getter, setter_ 15 | - [root\_dir](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#properties-table); _getter, setter_ 16 | - [type\_ref](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#properties-table); _getter, setter_ 17 | - [feed](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#feed): Feed the decoder engine with some string. The string might represent a line in the textual Paradict data, or an ... 18 | - [\_check\_key](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_check_key): No docstring. 19 | - [\_check\_line](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_check_line): Check the validity of the indent in the line Returns the indent-less version of line 20 | - [\_check\_multiline\_tag](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_check_multiline_tag): No docstring. 21 | - [\_cleanup\_stack](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_cleanup_stack): No docstring. 22 | - [\_consume\_bin\_block](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_consume_bin_block): No docstring. 23 | - [\_consume\_grid\_block](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_consume_grid_block): No docstring. 24 | - [\_consume\_obj\_block](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_consume_obj_block): No docstring. 25 | - [\_consume\_raw\_block](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_consume_raw_block): No docstring. 26 | - [\_consume\_str\_block](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_consume_str_block): No docstring. 27 | - [\_decode\_bin](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_bin): No docstring. 28 | - [\_decode\_bool](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_bool): No docstring. 29 | - [\_decode\_complex\_number](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_complex_number): No docstring. 30 | - [\_decode\_container](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_container): No docstring. 31 | - [\_decode\_date](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_date): No docstring. 32 | - [\_decode\_datetime](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_datetime): No docstring. 33 | - [\_decode\_float](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_float): No docstring. 34 | - [\_decode\_int](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_int): No docstring. 35 | - [\_decode\_load\_func](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_load_func): No docstring. 36 | - [\_decode\_null](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_null): No docstring. 37 | - [\_decode\_str](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_str): No docstring. 38 | - [\_decode\_time](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_time): No docstring. 39 | - [\_decode\_value](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_decode_value): No docstring. 40 | - [\_get\_context](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_get_context): No docstring. 41 | - [\_get\_parent\_context](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_get_parent_context): No docstring. 42 | - [\_interpret](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_interpret): No docstring. 43 | - [\_process](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_process): No docstring. 44 | - [\_update\_context](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_update_context): No docstring. 45 | - [\_update\_dict\_container](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_update_dict_container): No docstring. 46 | - [\_update\_list\_container](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_update_list_container): No docstring. 47 | - [\_update\_obj\_container](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_update_obj_container): No docstring. 48 | - [\_update\_parent\_context](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_update_parent_context): No docstring. 49 | - [\_update\_set\_container](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_update_set_container): No docstring. 50 | - [\_update\_stack](/docs/api/modules/paradict/deserializer/decoder/class-Decoder.md#_update_stack): No docstring. 51 | 52 |

Back to top

53 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/__init__/class-Packer.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/__init__/README.md) | [Source](/src/paradict/__init__.py) 3 | 4 | # Class Packer 5 | > Module: [paradict.\_\_init\_\_](/docs/api/modules/paradict/__init__/README.md) 6 | > 7 | > Class: **Packer** 8 | > 9 | > Inheritance: `object` 10 | 11 | Class to convert some binary Python dict into Paradict binary format 12 | 13 | ## Properties table 14 | Here are properties exposed in the class: 15 | 16 | | Property | Methods | Description | 17 | | --- | --- | --- | 18 | | auto\_index | _getter_ | No docstring. | 19 | | dict\_only | _getter_ | No docstring. | 20 | | index\_dict | _getter_ | Index dictionary for when the root container is a dict | 21 | | type\_ref | _getter, setter_ | No docstring. | 22 | 23 |

Back to top

24 | 25 | # Methods within class 26 | Here are methods exposed in the class: 27 | - [\_\_init\_\_](#__init__) 28 | - [pack](#pack) 29 | - [\_pack](#_pack) 30 | - [\_pack\_bin](#_pack_bin) 31 | - [\_pack\_bin\_int](#_pack_bin_int) 32 | - [\_pack\_bool](#_pack_bool) 33 | - [\_pack\_complex](#_pack_complex) 34 | - [\_pack\_date](#_pack_date) 35 | - [\_pack\_datetime](#_pack_datetime) 36 | - [\_pack\_dict](#_pack_dict) 37 | - [\_pack\_float](#_pack_float) 38 | - [\_pack\_grid](#_pack_grid) 39 | - [\_pack\_hex\_int](#_pack_hex_int) 40 | - [\_pack\_int](#_pack_int) 41 | - [\_pack\_list](#_pack_list) 42 | - [\_pack\_null](#_pack_null) 43 | - [\_pack\_obj](#_pack_obj) 44 | - [\_pack\_oct\_int](#_pack_oct_int) 45 | - [\_pack\_set](#_pack_set) 46 | - [\_pack\_str](#_pack_str) 47 | - [\_pack\_time](#_pack_time) 48 | 49 | ## \_\_init\_\_ 50 | Init 51 | 52 | ```python 53 | def __init__(self, type_ref=None, dict_only=False, auto_index=False): 54 | ... 55 | ``` 56 | 57 | | Parameter | Description | 58 | | --- | --- | 59 | | type\_ref | optional TypeRef object | 60 | | dict\_only | boolean to enforce dict as root | 61 | 62 |

Back to top

63 | 64 | ## pack 65 | Generator for iteratively packing data by yielding bytes datum forged in 66 | Paradict binary format 67 | 68 | ```python 69 | def pack(self, data): 70 | ... 71 | ``` 72 | 73 |

Back to top

74 | 75 | ## \_pack 76 | No docstring 77 | 78 | ```python 79 | def _pack(self, data): 80 | ... 81 | ``` 82 | 83 |

Back to top

84 | 85 | ## \_pack\_bin 86 | No docstring 87 | 88 | ```python 89 | def _pack_bin(self, data): 90 | ... 91 | ``` 92 | 93 |

Back to top

94 | 95 | ## \_pack\_bin\_int 96 | No docstring 97 | 98 | ```python 99 | def _pack_bin_int(self, data): 100 | ... 101 | ``` 102 | 103 |

Back to top

104 | 105 | ## \_pack\_bool 106 | No docstring 107 | 108 | ```python 109 | def _pack_bool(self, data): 110 | ... 111 | ``` 112 | 113 |

Back to top

114 | 115 | ## \_pack\_complex 116 | No docstring 117 | 118 | ```python 119 | def _pack_complex(self, data): 120 | ... 121 | ``` 122 | 123 |

Back to top

124 | 125 | ## \_pack\_date 126 | No docstring 127 | 128 | ```python 129 | def _pack_date(self, data): 130 | ... 131 | ``` 132 | 133 |

Back to top

134 | 135 | ## \_pack\_datetime 136 | No docstring 137 | 138 | ```python 139 | def _pack_datetime(self, data): 140 | ... 141 | ``` 142 | 143 |

Back to top

144 | 145 | ## \_pack\_dict 146 | No docstring 147 | 148 | ```python 149 | def _pack_dict(self, data): 150 | ... 151 | ``` 152 | 153 |

Back to top

154 | 155 | ## \_pack\_float 156 | No docstring 157 | 158 | ```python 159 | def _pack_float(self, data): 160 | ... 161 | ``` 162 | 163 |

Back to top

164 | 165 | ## \_pack\_grid 166 | No docstring 167 | 168 | ```python 169 | def _pack_grid(self, data): 170 | ... 171 | ``` 172 | 173 |

Back to top

174 | 175 | ## \_pack\_hex\_int 176 | No docstring 177 | 178 | ```python 179 | def _pack_hex_int(self, data): 180 | ... 181 | ``` 182 | 183 |

Back to top

184 | 185 | ## \_pack\_int 186 | No docstring 187 | 188 | ```python 189 | def _pack_int(self, data): 190 | ... 191 | ``` 192 | 193 |

Back to top

194 | 195 | ## \_pack\_list 196 | No docstring 197 | 198 | ```python 199 | def _pack_list(self, data): 200 | ... 201 | ``` 202 | 203 |

Back to top

204 | 205 | ## \_pack\_null 206 | No docstring 207 | 208 | ```python 209 | def _pack_null(self, data): 210 | ... 211 | ``` 212 | 213 |

Back to top

214 | 215 | ## \_pack\_obj 216 | No docstring 217 | 218 | ```python 219 | def _pack_obj(self, data): 220 | ... 221 | ``` 222 | 223 |

Back to top

224 | 225 | ## \_pack\_oct\_int 226 | No docstring 227 | 228 | ```python 229 | def _pack_oct_int(self, data): 230 | ... 231 | ``` 232 | 233 |

Back to top

234 | 235 | ## \_pack\_set 236 | No docstring 237 | 238 | ```python 239 | def _pack_set(self, data): 240 | ... 241 | ``` 242 | 243 |

Back to top

244 | 245 | ## \_pack\_str 246 | No docstring 247 | 248 | ```python 249 | def _pack_str(self, data): 250 | ... 251 | ``` 252 | 253 |

Back to top

254 | 255 | ## \_pack\_time 256 | No docstring 257 | 258 | ```python 259 | def _pack_time(self, data): 260 | ... 261 | ``` 262 | 263 |

Back to top

264 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/packer/class-Packer.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/serializer/packer/README.md) | [Source](/src/paradict/serializer/packer.py) 3 | 4 | # Class Packer 5 | > Module: [paradict.serializer.packer](/docs/api/modules/paradict/serializer/packer/README.md) 6 | > 7 | > Class: **Packer** 8 | > 9 | > Inheritance: `object` 10 | 11 | Class to convert some binary Python dict into Paradict binary format 12 | 13 | ## Properties table 14 | Here are properties exposed in the class: 15 | 16 | | Property | Methods | Description | 17 | | --- | --- | --- | 18 | | auto\_index | _getter_ | No docstring. | 19 | | dict\_only | _getter_ | No docstring. | 20 | | index\_dict | _getter_ | Index dictionary for when the root container is a dict | 21 | | type\_ref | _getter, setter_ | No docstring. | 22 | 23 |

Back to top

24 | 25 | # Methods within class 26 | Here are methods exposed in the class: 27 | - [\_\_init\_\_](#__init__) 28 | - [pack](#pack) 29 | - [\_pack](#_pack) 30 | - [\_pack\_bin](#_pack_bin) 31 | - [\_pack\_bin\_int](#_pack_bin_int) 32 | - [\_pack\_bool](#_pack_bool) 33 | - [\_pack\_complex](#_pack_complex) 34 | - [\_pack\_date](#_pack_date) 35 | - [\_pack\_datetime](#_pack_datetime) 36 | - [\_pack\_dict](#_pack_dict) 37 | - [\_pack\_float](#_pack_float) 38 | - [\_pack\_grid](#_pack_grid) 39 | - [\_pack\_hex\_int](#_pack_hex_int) 40 | - [\_pack\_int](#_pack_int) 41 | - [\_pack\_list](#_pack_list) 42 | - [\_pack\_null](#_pack_null) 43 | - [\_pack\_obj](#_pack_obj) 44 | - [\_pack\_oct\_int](#_pack_oct_int) 45 | - [\_pack\_set](#_pack_set) 46 | - [\_pack\_str](#_pack_str) 47 | - [\_pack\_time](#_pack_time) 48 | 49 | ## \_\_init\_\_ 50 | Init 51 | 52 | ```python 53 | def __init__(self, type_ref=None, dict_only=False, auto_index=False): 54 | ... 55 | ``` 56 | 57 | | Parameter | Description | 58 | | --- | --- | 59 | | type\_ref | optional TypeRef object | 60 | | dict\_only | boolean to enforce dict as root | 61 | 62 |

Back to top

63 | 64 | ## pack 65 | Generator for iteratively packing data by yielding bytes datum forged in 66 | Paradict binary format 67 | 68 | ```python 69 | def pack(self, data): 70 | ... 71 | ``` 72 | 73 |

Back to top

74 | 75 | ## \_pack 76 | No docstring 77 | 78 | ```python 79 | def _pack(self, data): 80 | ... 81 | ``` 82 | 83 |

Back to top

84 | 85 | ## \_pack\_bin 86 | No docstring 87 | 88 | ```python 89 | def _pack_bin(self, data): 90 | ... 91 | ``` 92 | 93 |

Back to top

94 | 95 | ## \_pack\_bin\_int 96 | No docstring 97 | 98 | ```python 99 | def _pack_bin_int(self, data): 100 | ... 101 | ``` 102 | 103 |

Back to top

104 | 105 | ## \_pack\_bool 106 | No docstring 107 | 108 | ```python 109 | def _pack_bool(self, data): 110 | ... 111 | ``` 112 | 113 |

Back to top

114 | 115 | ## \_pack\_complex 116 | No docstring 117 | 118 | ```python 119 | def _pack_complex(self, data): 120 | ... 121 | ``` 122 | 123 |

Back to top

124 | 125 | ## \_pack\_date 126 | No docstring 127 | 128 | ```python 129 | def _pack_date(self, data): 130 | ... 131 | ``` 132 | 133 |

Back to top

134 | 135 | ## \_pack\_datetime 136 | No docstring 137 | 138 | ```python 139 | def _pack_datetime(self, data): 140 | ... 141 | ``` 142 | 143 |

Back to top

144 | 145 | ## \_pack\_dict 146 | No docstring 147 | 148 | ```python 149 | def _pack_dict(self, data): 150 | ... 151 | ``` 152 | 153 |

Back to top

154 | 155 | ## \_pack\_float 156 | No docstring 157 | 158 | ```python 159 | def _pack_float(self, data): 160 | ... 161 | ``` 162 | 163 |

Back to top

164 | 165 | ## \_pack\_grid 166 | No docstring 167 | 168 | ```python 169 | def _pack_grid(self, data): 170 | ... 171 | ``` 172 | 173 |

Back to top

174 | 175 | ## \_pack\_hex\_int 176 | No docstring 177 | 178 | ```python 179 | def _pack_hex_int(self, data): 180 | ... 181 | ``` 182 | 183 |

Back to top

184 | 185 | ## \_pack\_int 186 | No docstring 187 | 188 | ```python 189 | def _pack_int(self, data): 190 | ... 191 | ``` 192 | 193 |

Back to top

194 | 195 | ## \_pack\_list 196 | No docstring 197 | 198 | ```python 199 | def _pack_list(self, data): 200 | ... 201 | ``` 202 | 203 |

Back to top

204 | 205 | ## \_pack\_null 206 | No docstring 207 | 208 | ```python 209 | def _pack_null(self, data): 210 | ... 211 | ``` 212 | 213 |

Back to top

214 | 215 | ## \_pack\_obj 216 | No docstring 217 | 218 | ```python 219 | def _pack_obj(self, data): 220 | ... 221 | ``` 222 | 223 |

Back to top

224 | 225 | ## \_pack\_oct\_int 226 | No docstring 227 | 228 | ```python 229 | def _pack_oct_int(self, data): 230 | ... 231 | ``` 232 | 233 |

Back to top

234 | 235 | ## \_pack\_set 236 | No docstring 237 | 238 | ```python 239 | def _pack_set(self, data): 240 | ... 241 | ``` 242 | 243 |

Back to top

244 | 245 | ## \_pack\_str 246 | No docstring 247 | 248 | ```python 249 | def _pack_str(self, data): 250 | ... 251 | ``` 252 | 253 |

Back to top

254 | 255 | ## \_pack\_time 256 | No docstring 257 | 258 | ```python 259 | def _pack_time(self, data): 260 | ... 261 | ``` 262 | 263 |

Back to top

264 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/encoder/README.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | Module | [Source](/src/paradict/serializer/encoder.py) 3 | 4 | # Module Overview 5 | > Module: **paradict.serializer.encoder** 6 | 7 | No docstring. 8 | 9 | ## Fields 10 | - [**All fields**](/docs/api/modules/paradict/serializer/encoder/fields.md) 11 | - base64 = `` 12 | - const = `` 13 | - errors = `` 14 | - misc = `` 15 | - os = `` 16 | - re = `` 17 | - xtypes = `` 18 | 19 |

Back to top

20 | 21 | ## Functions 22 | - [**All functions**](/docs/api/modules/paradict/serializer/encoder/funcs.md) 23 | - [encode\_bin](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_bin): No docstring. 24 | - [encode\_bin\_int](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_bin_int): No docstring. 25 | - [encode\_bool](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_bool): No docstring. 26 | - [encode\_complex](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_complex): No docstring. 27 | - [encode\_date](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_date): Parse date and time with the ISO 8601 format 28 | - [encode\_datetime](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_datetime): No docstring. 29 | - [encode\_float](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_float): No docstring. 30 | - [encode\_hex\_int](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_hex_int): No docstring. 31 | - [encode\_int](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_int): No docstring. 32 | - [encode\_multiline\_str](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_multiline_str): No docstring. 33 | - [encode\_null](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_null): No docstring. 34 | - [encode\_oct\_int](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_oct_int): No docstring. 35 | - [encode\_str](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_str): No docstring. 36 | - [encode\_time](/docs/api/modules/paradict/serializer/encoder/funcs.md#encode_time): No docstring. 37 | 38 |

Back to top

39 | 40 | ## Classes 41 | - [**Context**](/docs/api/modules/paradict/serializer/encoder/class-Context.md): Context(name, collection, indents) 42 | - name: Alias for field number 0 43 | - collection: Alias for field number 1 44 | - indents: Alias for field number 2 45 | - [**Encoder**](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md): Convert a Python dictionary object to Paradict text format 46 | - [attachments\_dir](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#properties-table); _getter, setter_ 47 | - [bin\_to\_text](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#properties-table); _getter, setter_ 48 | - [mode](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#properties-table); _getter, setter_ 49 | - [root\_dir](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#properties-table); _getter, setter_ 50 | - [type\_ref](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#properties-table); _getter, setter_ 51 | - [encode](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#encode): Generator for iteratively encoding data by yielding lines of Paradict text format 52 | - [\_check\_key](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_check_key): No docstring. 53 | - [\_encode](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode): No docstring. 54 | - [\_encode\_bin](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_bin): No docstring. 55 | - [\_encode\_bin\_int](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_bin_int): No docstring. 56 | - [\_encode\_bool](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_bool): No docstring. 57 | - [\_encode\_complex](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_complex): No docstring. 58 | - [\_encode\_date](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_date): No docstring. 59 | - [\_encode\_datetime](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_datetime): No docstring. 60 | - [\_encode\_dict](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_dict): No docstring. 61 | - [\_encode\_dict\_and\_obj](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_dict_and_obj): No docstring. 62 | - [\_encode\_float](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_float): No docstring. 63 | - [\_encode\_grid](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_grid): No docstring. 64 | - [\_encode\_hex\_int](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_hex_int): No docstring. 65 | - [\_encode\_int](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_int): No docstring. 66 | - [\_encode\_list](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_list): No docstring. 67 | - [\_encode\_null](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_null): No docstring. 68 | - [\_encode\_obj](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_obj): No docstring. 69 | - [\_encode\_oct\_int](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_oct_int): No docstring. 70 | - [\_encode\_set](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_set): No docstring. 71 | - [\_encode\_str](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_str): No docstring. 72 | - [\_encode\_time](/docs/api/modules/paradict/serializer/encoder/class-Encoder.md#_encode_time): No docstring. 73 | 74 |

Back to top

75 | -------------------------------------------------------------------------------- /src/paradict/tags/mappings.py: -------------------------------------------------------------------------------- 1 | """Private miscellaneous module for the Paradict binary format""" 2 | from paradict import tags 3 | 4 | 5 | # Mapping payload sizes in bytes to PINT tags 6 | SIZE_TO_PINT = {1: tags.PINT_8, 2: tags.PINT_16, 7 | 3: tags.PINT_24, 4: tags.PINT_32, 8 | 5: tags.PINT_40, 6: tags.PINT_48, 9 | 7: tags.PINT_56, 8: tags.PINT_64} 10 | 11 | # Mapping PINT tags to payload sizes in bytes 12 | PINT_TO_SIZE = {tags.PINT_8: 1, tags.PINT_16: 2, 13 | tags.PINT_24: 3, tags.PINT_32: 4, 14 | tags.PINT_40: 5, tags.PINT_48: 6, 15 | tags.PINT_56: 7, tags.PINT_64: 8} 16 | 17 | 18 | # Mapping payload sizes in bytes to NINT tags 19 | SIZE_TO_NINT = {1: tags.NINT_8, 2: tags.NINT_16, 20 | 3: tags.NINT_24, 4: tags.NINT_32, 21 | 5: tags.NINT_40, 6: tags.NINT_48, 22 | 7: tags.NINT_56, 8: tags.NINT_64} 23 | 24 | # Mapping NINT tags to payload sizes in bytes 25 | NINT_TO_SIZE = {tags.NINT_8: 1, tags.NINT_16: 2, 26 | tags.NINT_24: 3, tags.NINT_32: 4, 27 | tags.NINT_40: 5, tags.NINT_48: 6, 28 | tags.NINT_56: 7, tags.NINT_64: 8} 29 | 30 | 31 | # Mapping payload sizes in bytes to fixed-length STR tags 32 | SIZE_TO_STR = {1: tags.STR_8, 2: tags.STR_16, 33 | 3: tags.STR_24, 4: tags.STR_32, 34 | 5: tags.STR_40, 6: tags.STR_48, 35 | 7: tags.STR_56, 8: tags.STR_64, 36 | 9: tags.STR_72, 10: tags.STR_80, 37 | 11: tags.STR_88, 12: tags.STR_96, 38 | 13: tags.STR_104, 14: tags.STR_112, 39 | 15: tags.STR_120, 16: tags.STR_128, 40 | 17: tags.STR_136, 18: tags.STR_144, 41 | 19: tags.STR_152, 20: tags.STR_160, 42 | 21: tags.STR_168, 22: tags.STR_176, 43 | 23: tags.STR_184, 24: tags.STR_192, 44 | 25: tags.STR_200, 26: tags.STR_208, 45 | 27: tags.STR_216, 28: tags.STR_224, 46 | 29: tags.STR_232, 30: tags.STR_240, 47 | 31: tags.STR_248, 32: tags.STR_256} 48 | 49 | # Mapping fixed-length STR tags to payload sizes in bytes 50 | STR_TO_SIZE = {tags.STR_8: 1, tags.STR_16: 2, 51 | tags.STR_24: 3, tags.STR_32: 4, 52 | tags.STR_40: 5, tags.STR_48: 6, 53 | tags.STR_56: 7, tags.STR_64: 8, 54 | tags.STR_72: 9, tags.STR_80: 10, 55 | tags.STR_88:11, tags.STR_96: 12, 56 | tags.STR_104: 13, tags.STR_112: 14, 57 | tags.STR_120: 15, tags.STR_128: 16, 58 | tags.STR_136: 17, tags.STR_144: 18, 59 | tags.STR_152: 19, tags.STR_160: 20, 60 | tags.STR_168: 21, tags.STR_176: 22, 61 | tags.STR_184: 23, tags.STR_192: 24, 62 | tags.STR_200: 25, tags.STR_208: 26, 63 | tags.STR_216: 27, tags.STR_224: 28, 64 | tags.STR_232: 29, tags.STR_240: 30, 65 | tags.STR_248: 31, tags.STR_256: 32} 66 | 67 | 68 | # Mapping BIN tags to number of bytes for encoding payload sizes 69 | BIN_TO_SIZE = {tags.BIN_SHORT: 1, 70 | tags.BIN_MEDIUM: 2, 71 | tags.BIN_LONG: 3, 72 | tags.BIN_BIG: 4, 73 | tags.BIN_HEAVY: 5} 74 | 75 | # Mapping number of bytes for encoding payload sizes to BIN tags 76 | SIZE_TO_BIN = {1: tags.BIN_SHORT, 77 | 2: tags.BIN_MEDIUM, 78 | 3: tags.BIN_LONG, 79 | 4: tags.BIN_BIG, 80 | 5: tags.BIN_HEAVY} 81 | 82 | # Mapping variable-length STR tags to number of bytes for encoding payload sizes 83 | VARSTR_TO_SIZE = {tags.STR_SHORT: 1, 84 | tags.STR_MEDIUM: 2, 85 | tags.STR_LONG: 3, 86 | tags.STR_BIG: 4, 87 | tags.STR_HEAVY: 5} 88 | 89 | # Mapping number of bytes for encoding payload sizes to variable-length STR tags 90 | SIZE_TO_VARSTR = {1: tags.STR_SHORT, 91 | 2: tags.STR_MEDIUM, 92 | 3: tags.STR_LONG, 93 | 4: tags.STR_BIG, 94 | 5: tags.STR_HEAVY} 95 | 96 | 97 | # Mapping lower and upper alphabet letters to CHAR tags 98 | LETTER_TO_TAG = {"a": tags.CHAR_A, "b": tags.CHAR_B, 99 | "c": tags.CHAR_C, "d": tags.CHAR_D, 100 | "e": tags.CHAR_E, "f": tags.CHAR_F, 101 | "g": tags.CHAR_G, "h": tags.CHAR_H, 102 | "i": tags.CHAR_I, "j": tags.CHAR_J, 103 | "k": tags.CHAR_K, "l": tags.CHAR_L, 104 | "m": tags.CHAR_M, "n": tags.CHAR_N, 105 | "o": tags.CHAR_O, "p": tags.CHAR_P, 106 | "q": tags.CHAR_Q, "r": tags.CHAR_R, 107 | "s": tags.CHAR_S, "t": tags.CHAR_T, 108 | "u": tags.CHAR_U, "v": tags.CHAR_V, 109 | "w": tags.CHAR_W, "x": tags.CHAR_X, 110 | "y": tags.CHAR_Y, "z": tags.CHAR_Z, 111 | "A": tags.CHAR_UP_A, "B": tags.CHAR_UP_B, 112 | "C": tags.CHAR_UP_C, "D": tags.CHAR_UP_D, 113 | "E": tags.CHAR_UP_E, "F": tags.CHAR_UP_F, 114 | "G": tags.CHAR_UP_G, "H": tags.CHAR_UP_H, 115 | "I": tags.CHAR_UP_I, "J": tags.CHAR_UP_J, 116 | "K": tags.CHAR_UP_K, "L": tags.CHAR_UP_L, 117 | "M": tags.CHAR_UP_M, "N": tags.CHAR_UP_N, 118 | "O": tags.CHAR_UP_O, "P": tags.CHAR_UP_P, 119 | "Q": tags.CHAR_UP_Q, "R": tags.CHAR_UP_R, 120 | "S": tags.CHAR_UP_S, "T": tags.CHAR_UP_T, 121 | "U": tags.CHAR_UP_U, "V": tags.CHAR_UP_V, 122 | "W": tags.CHAR_UP_W, "X": tags.CHAR_UP_X, 123 | "Y": tags.CHAR_UP_Y, "Z": tags.CHAR_UP_Z} 124 | 125 | # Mapping CHAR tags to lower and upper alphabet letters 126 | TAG_TO_LETTER = {tags.CHAR_A: "a", tags.CHAR_B: "b", 127 | tags.CHAR_C: "c", tags.CHAR_D: "d", 128 | tags.CHAR_E: "e", tags.CHAR_F: "f", 129 | tags.CHAR_G: "g", tags.CHAR_H: "h", 130 | tags.CHAR_I: "i", tags.CHAR_J: "j", 131 | tags.CHAR_K: "k", tags.CHAR_L: "l", 132 | tags.CHAR_M: "m", tags.CHAR_N: "n", 133 | tags.CHAR_O: "o", tags.CHAR_P: "p", 134 | tags.CHAR_Q: "q", tags.CHAR_R: "r", 135 | tags.CHAR_S: "s", tags.CHAR_T: "t", 136 | tags.CHAR_U: "u", tags.CHAR_V: "v", 137 | tags.CHAR_W: "w", tags.CHAR_X: "x", 138 | tags.CHAR_Y: "y", tags.CHAR_Z: "z", 139 | tags.CHAR_UP_A: "A", tags.CHAR_UP_B: "B", 140 | tags.CHAR_UP_C: "C", tags.CHAR_UP_D: "D", 141 | tags.CHAR_UP_E: "E", tags.CHAR_UP_F: "F", 142 | tags.CHAR_UP_G: "G", tags.CHAR_UP_H: "H", 143 | tags.CHAR_UP_I: "I", tags.CHAR_UP_J: "J", 144 | tags.CHAR_UP_K: "K", tags.CHAR_UP_L: "L", 145 | tags.CHAR_UP_M: "M", tags.CHAR_UP_N: "N", 146 | tags.CHAR_UP_O: "O", tags.CHAR_UP_P: "P", 147 | tags.CHAR_UP_Q: "Q", tags.CHAR_UP_R: "R", 148 | tags.CHAR_UP_S: "S", tags.CHAR_UP_T: "T", 149 | tags.CHAR_UP_U: "U", tags.CHAR_UP_V: "V", 150 | tags.CHAR_UP_W: "W", tags.CHAR_UP_X: "X", 151 | tags.CHAR_UP_Y: "Y", tags.CHAR_UP_Z: "Z"} 152 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/__init__/class-Encoder.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/__init__/README.md) | [Source](/src/paradict/__init__.py) 3 | 4 | # Class Encoder 5 | > Module: [paradict.\_\_init\_\_](/docs/api/modules/paradict/__init__/README.md) 6 | > 7 | > Class: **Encoder** 8 | > 9 | > Inheritance: `object` 10 | 11 | Convert a Python dictionary object to Paradict text format 12 | 13 | ## Properties table 14 | Here are properties exposed in the class: 15 | 16 | | Property | Methods | Description | 17 | | --- | --- | --- | 18 | | attachments\_dir | _getter, setter_ | No docstring. | 19 | | bin\_to\_text | _getter, setter_ | No docstring. | 20 | | mode | _getter, setter_ | No docstring. | 21 | | root\_dir | _getter, setter_ | No docstring. | 22 | | type\_ref | _getter, setter_ | No docstring. | 23 | 24 |

Back to top

25 | 26 | # Methods within class 27 | Here are methods exposed in the class: 28 | - [\_\_init\_\_](#__init__) 29 | - [encode](#encode) 30 | - [\_check\_key](#_check_key) 31 | - [\_encode](#_encode) 32 | - [\_encode\_bin](#_encode_bin) 33 | - [\_encode\_bin\_int](#_encode_bin_int) 34 | - [\_encode\_bool](#_encode_bool) 35 | - [\_encode\_complex](#_encode_complex) 36 | - [\_encode\_date](#_encode_date) 37 | - [\_encode\_datetime](#_encode_datetime) 38 | - [\_encode\_dict](#_encode_dict) 39 | - [\_encode\_dict\_and\_obj](#_encode_dict_and_obj) 40 | - [\_encode\_float](#_encode_float) 41 | - [\_encode\_grid](#_encode_grid) 42 | - [\_encode\_hex\_int](#_encode_hex_int) 43 | - [\_encode\_int](#_encode_int) 44 | - [\_encode\_list](#_encode_list) 45 | - [\_encode\_null](#_encode_null) 46 | - [\_encode\_obj](#_encode_obj) 47 | - [\_encode\_oct\_int](#_encode_oct_int) 48 | - [\_encode\_set](#_encode_set) 49 | - [\_encode\_str](#_encode_str) 50 | - [\_encode\_time](#_encode_time) 51 | 52 | ## \_\_init\_\_ 53 | Init 54 | 55 | ```python 56 | def __init__(self, mode='d', type_ref=None, bin_to_text=True, root_dir=None, attachments_dir='attachments'): 57 | ... 58 | ``` 59 | 60 | | Parameter | Description | 61 | | --- | --- | 62 | | mode | either const.DATA_MODE or const.CONFIG_MODE. Defaults to DATA_MODE. | 63 | | type\_ref | optional TypeRef object | 64 | | bin\_to\_text | boolean to tell whether bin data should be embedded as base16 or stored in a linked file | 65 | | root\_dir | root directory in which the attachments dir is supposed to be | 66 | | attachments\_dir | attachments directory. This is a path that is relative to the root dir. Note that relative paths should use a slash as separator. | 67 | 68 |

Back to top

69 | 70 | ## encode 71 | Generator for iteratively encoding data by yielding lines of Paradict text format 72 | 73 | ```python 74 | def encode(self, data): 75 | ... 76 | ``` 77 | 78 |

Back to top

79 | 80 | ## \_check\_key 81 | No docstring 82 | 83 | ```python 84 | def _check_key(self, key): 85 | ... 86 | ``` 87 | 88 |

Back to top

89 | 90 | ## \_encode 91 | No docstring 92 | 93 | ```python 94 | def _encode(self, data, indents=-1): 95 | ... 96 | ``` 97 | 98 |

Back to top

99 | 100 | ## \_encode\_bin 101 | No docstring 102 | 103 | ```python 104 | def _encode_bin(self, data, indents=0): 105 | ... 106 | ``` 107 | 108 |

Back to top

109 | 110 | ## \_encode\_bin\_int 111 | No docstring 112 | 113 | ```python 114 | def _encode_bin_int(self, data, indents=0): 115 | ... 116 | ``` 117 | 118 |

Back to top

119 | 120 | ## \_encode\_bool 121 | No docstring 122 | 123 | ```python 124 | def _encode_bool(self, data, indents=0): 125 | ... 126 | ``` 127 | 128 |

Back to top

129 | 130 | ## \_encode\_complex 131 | No docstring 132 | 133 | ```python 134 | def _encode_complex(self, data, indents=0): 135 | ... 136 | ``` 137 | 138 |

Back to top

139 | 140 | ## \_encode\_date 141 | No docstring 142 | 143 | ```python 144 | def _encode_date(self, data, indents=0): 145 | ... 146 | ``` 147 | 148 |

Back to top

149 | 150 | ## \_encode\_datetime 151 | No docstring 152 | 153 | ```python 154 | def _encode_datetime(self, data, indents=0): 155 | ... 156 | ``` 157 | 158 |

Back to top

159 | 160 | ## \_encode\_dict 161 | No docstring 162 | 163 | ```python 164 | def _encode_dict(self, data, indents): 165 | ... 166 | ``` 167 | 168 |

Back to top

169 | 170 | ## \_encode\_dict\_and\_obj 171 | No docstring 172 | 173 | ```python 174 | def _encode_dict_and_obj(self, tag, data, indents=0): 175 | ... 176 | ``` 177 | 178 |

Back to top

179 | 180 | ## \_encode\_float 181 | No docstring 182 | 183 | ```python 184 | def _encode_float(self, data, indents=0): 185 | ... 186 | ``` 187 | 188 |

Back to top

189 | 190 | ## \_encode\_grid 191 | No docstring 192 | 193 | ```python 194 | def _encode_grid(self, data, indents=0): 195 | ... 196 | ``` 197 | 198 |

Back to top

199 | 200 | ## \_encode\_hex\_int 201 | No docstring 202 | 203 | ```python 204 | def _encode_hex_int(self, data, indents=0): 205 | ... 206 | ``` 207 | 208 |

Back to top

209 | 210 | ## \_encode\_int 211 | No docstring 212 | 213 | ```python 214 | def _encode_int(self, data, indents=0): 215 | ... 216 | ``` 217 | 218 |

Back to top

219 | 220 | ## \_encode\_list 221 | No docstring 222 | 223 | ```python 224 | def _encode_list(self, data, indents=0): 225 | ... 226 | ``` 227 | 228 |

Back to top

229 | 230 | ## \_encode\_null 231 | No docstring 232 | 233 | ```python 234 | def _encode_null(self, data, indents=0): 235 | ... 236 | ``` 237 | 238 |

Back to top

239 | 240 | ## \_encode\_obj 241 | No docstring 242 | 243 | ```python 244 | def _encode_obj(self, data, indents=0): 245 | ... 246 | ``` 247 | 248 |

Back to top

249 | 250 | ## \_encode\_oct\_int 251 | No docstring 252 | 253 | ```python 254 | def _encode_oct_int(self, data, indents=0): 255 | ... 256 | ``` 257 | 258 |

Back to top

259 | 260 | ## \_encode\_set 261 | No docstring 262 | 263 | ```python 264 | def _encode_set(self, data, indents=0): 265 | ... 266 | ``` 267 | 268 |

Back to top

269 | 270 | ## \_encode\_str 271 | No docstring 272 | 273 | ```python 274 | def _encode_str(self, data, indents=0): 275 | ... 276 | ``` 277 | 278 |

Back to top

279 | 280 | ## \_encode\_time 281 | No docstring 282 | 283 | ```python 284 | def _encode_time(self, data, indents=0): 285 | ... 286 | ``` 287 | 288 |

Back to top

289 | -------------------------------------------------------------------------------- /docs/api/modules/paradict/serializer/encoder/class-Encoder.md: -------------------------------------------------------------------------------- 1 | ###### Paradict API Reference 2 | [Home](/docs/api/README.md) | [Project](/README.md) | [Module](/docs/api/modules/paradict/serializer/encoder/README.md) | [Source](/src/paradict/serializer/encoder.py) 3 | 4 | # Class Encoder 5 | > Module: [paradict.serializer.encoder](/docs/api/modules/paradict/serializer/encoder/README.md) 6 | > 7 | > Class: **Encoder** 8 | > 9 | > Inheritance: `object` 10 | 11 | Convert a Python dictionary object to Paradict text format 12 | 13 | ## Properties table 14 | Here are properties exposed in the class: 15 | 16 | | Property | Methods | Description | 17 | | --- | --- | --- | 18 | | attachments\_dir | _getter, setter_ | No docstring. | 19 | | bin\_to\_text | _getter, setter_ | No docstring. | 20 | | mode | _getter, setter_ | No docstring. | 21 | | root\_dir | _getter, setter_ | No docstring. | 22 | | type\_ref | _getter, setter_ | No docstring. | 23 | 24 |

Back to top

25 | 26 | # Methods within class 27 | Here are methods exposed in the class: 28 | - [\_\_init\_\_](#__init__) 29 | - [encode](#encode) 30 | - [\_check\_key](#_check_key) 31 | - [\_encode](#_encode) 32 | - [\_encode\_bin](#_encode_bin) 33 | - [\_encode\_bin\_int](#_encode_bin_int) 34 | - [\_encode\_bool](#_encode_bool) 35 | - [\_encode\_complex](#_encode_complex) 36 | - [\_encode\_date](#_encode_date) 37 | - [\_encode\_datetime](#_encode_datetime) 38 | - [\_encode\_dict](#_encode_dict) 39 | - [\_encode\_dict\_and\_obj](#_encode_dict_and_obj) 40 | - [\_encode\_float](#_encode_float) 41 | - [\_encode\_grid](#_encode_grid) 42 | - [\_encode\_hex\_int](#_encode_hex_int) 43 | - [\_encode\_int](#_encode_int) 44 | - [\_encode\_list](#_encode_list) 45 | - [\_encode\_null](#_encode_null) 46 | - [\_encode\_obj](#_encode_obj) 47 | - [\_encode\_oct\_int](#_encode_oct_int) 48 | - [\_encode\_set](#_encode_set) 49 | - [\_encode\_str](#_encode_str) 50 | - [\_encode\_time](#_encode_time) 51 | 52 | ## \_\_init\_\_ 53 | Init 54 | 55 | ```python 56 | def __init__(self, mode='d', type_ref=None, bin_to_text=True, root_dir=None, attachments_dir='attachments'): 57 | ... 58 | ``` 59 | 60 | | Parameter | Description | 61 | | --- | --- | 62 | | mode | either const.DATA_MODE or const.CONFIG_MODE. Defaults to DATA_MODE. | 63 | | type\_ref | optional TypeRef object | 64 | | bin\_to\_text | boolean to tell whether bin data should be embedded as base16 or stored in a linked file | 65 | | root\_dir | root directory in which the attachments dir is supposed to be | 66 | | attachments\_dir | attachments directory. This is a path that is relative to the root dir. Note that relative paths should use a slash as separator. | 67 | 68 |

Back to top

69 | 70 | ## encode 71 | Generator for iteratively encoding data by yielding lines of Paradict text format 72 | 73 | ```python 74 | def encode(self, data): 75 | ... 76 | ``` 77 | 78 |

Back to top

79 | 80 | ## \_check\_key 81 | No docstring 82 | 83 | ```python 84 | def _check_key(self, key): 85 | ... 86 | ``` 87 | 88 |

Back to top

89 | 90 | ## \_encode 91 | No docstring 92 | 93 | ```python 94 | def _encode(self, data, indents=-1): 95 | ... 96 | ``` 97 | 98 |

Back to top

99 | 100 | ## \_encode\_bin 101 | No docstring 102 | 103 | ```python 104 | def _encode_bin(self, data, indents=0): 105 | ... 106 | ``` 107 | 108 |

Back to top

109 | 110 | ## \_encode\_bin\_int 111 | No docstring 112 | 113 | ```python 114 | def _encode_bin_int(self, data, indents=0): 115 | ... 116 | ``` 117 | 118 |

Back to top

119 | 120 | ## \_encode\_bool 121 | No docstring 122 | 123 | ```python 124 | def _encode_bool(self, data, indents=0): 125 | ... 126 | ``` 127 | 128 |

Back to top

129 | 130 | ## \_encode\_complex 131 | No docstring 132 | 133 | ```python 134 | def _encode_complex(self, data, indents=0): 135 | ... 136 | ``` 137 | 138 |

Back to top

139 | 140 | ## \_encode\_date 141 | No docstring 142 | 143 | ```python 144 | def _encode_date(self, data, indents=0): 145 | ... 146 | ``` 147 | 148 |

Back to top

149 | 150 | ## \_encode\_datetime 151 | No docstring 152 | 153 | ```python 154 | def _encode_datetime(self, data, indents=0): 155 | ... 156 | ``` 157 | 158 |

Back to top

159 | 160 | ## \_encode\_dict 161 | No docstring 162 | 163 | ```python 164 | def _encode_dict(self, data, indents): 165 | ... 166 | ``` 167 | 168 |

Back to top

169 | 170 | ## \_encode\_dict\_and\_obj 171 | No docstring 172 | 173 | ```python 174 | def _encode_dict_and_obj(self, tag, data, indents=0): 175 | ... 176 | ``` 177 | 178 |

Back to top

179 | 180 | ## \_encode\_float 181 | No docstring 182 | 183 | ```python 184 | def _encode_float(self, data, indents=0): 185 | ... 186 | ``` 187 | 188 |

Back to top

189 | 190 | ## \_encode\_grid 191 | No docstring 192 | 193 | ```python 194 | def _encode_grid(self, data, indents=0): 195 | ... 196 | ``` 197 | 198 |

Back to top

199 | 200 | ## \_encode\_hex\_int 201 | No docstring 202 | 203 | ```python 204 | def _encode_hex_int(self, data, indents=0): 205 | ... 206 | ``` 207 | 208 |

Back to top

209 | 210 | ## \_encode\_int 211 | No docstring 212 | 213 | ```python 214 | def _encode_int(self, data, indents=0): 215 | ... 216 | ``` 217 | 218 |

Back to top

219 | 220 | ## \_encode\_list 221 | No docstring 222 | 223 | ```python 224 | def _encode_list(self, data, indents=0): 225 | ... 226 | ``` 227 | 228 |

Back to top

229 | 230 | ## \_encode\_null 231 | No docstring 232 | 233 | ```python 234 | def _encode_null(self, data, indents=0): 235 | ... 236 | ``` 237 | 238 |

Back to top

239 | 240 | ## \_encode\_obj 241 | No docstring 242 | 243 | ```python 244 | def _encode_obj(self, data, indents=0): 245 | ... 246 | ``` 247 | 248 |

Back to top

249 | 250 | ## \_encode\_oct\_int 251 | No docstring 252 | 253 | ```python 254 | def _encode_oct_int(self, data, indents=0): 255 | ... 256 | ``` 257 | 258 |

Back to top

259 | 260 | ## \_encode\_set 261 | No docstring 262 | 263 | ```python 264 | def _encode_set(self, data, indents=0): 265 | ... 266 | ``` 267 | 268 |

Back to top

269 | 270 | ## \_encode\_str 271 | No docstring 272 | 273 | ```python 274 | def _encode_str(self, data, indents=0): 275 | ... 276 | ``` 277 | 278 |

Back to top

279 | 280 | ## \_encode\_time 281 | No docstring 282 | 283 | ```python 284 | def _encode_time(self, data, indents=0): 285 | ... 286 | ``` 287 | 288 |

Back to top

289 | --------------------------------------------------------------------------------