ethos_penalps.utilities.own_object_json_encoding_decoding#
Module Contents#
Classes#
Extensible JSON <https://json.org> encoder for Python data structures. |
|
Simple JSON <https://json.org> decoder |
|
Extensible JSON <https://json.org> encoder for Python data structures. |
|
Simple JSON <https://json.org> decoder |
- class ethos_penalps.utilities.own_object_json_encoding_decoding.ExtendedEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#
Bases:
json.JSONEncoderExtensible JSON <https://json.org> encoder for Python data structures.
Supports the following objects and types by default:
Python
JSON
dict
object
list, tuple
array
str
string
int, float
number
True
true
False
false
None
null
To extend this to recognize other objects, subclass and implement a
.default()method with another method that returns a serializable object foroif possible, otherwise it should call the superclass implementation (to raiseTypeError).- default(obj)#
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class ethos_penalps.utilities.own_object_json_encoding_decoding.ExtendedDecoder(**kwargs)#
Bases:
json.JSONDecoderSimple JSON <https://json.org> decoder
Performs the following translations in decoding by default:
JSON
Python
object
dict
array
list
string
str
number (int)
int
number (real)
float
true
True
false
False
null
None
It also understands
NaN,Infinity, and-Infinityas their correspondingfloatvalues, which is outside the JSON spec.- object_hook(obj)#
- class ethos_penalps.utilities.own_object_json_encoding_decoding.MyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#
Bases:
ExtendedEncoderExtensible JSON <https://json.org> encoder for Python data structures.
Supports the following objects and types by default:
Python
JSON
dict
object
list, tuple
array
str
string
int, float
number
True
true
False
false
None
null
To extend this to recognize other objects, subclass and implement a
.default()method with another method that returns a serializable object foroif possible, otherwise it should call the superclass implementation (to raiseTypeError).- encode_BatchStream(batch_stream: ethos_penalps.stream.BatchStream) dict#
- encode_ContinuousStream(continuous_stream: ethos_penalps.stream.ContinuousStream) dict#
- encode_StreamHandler(stream_handler: ethos_penalps.stream_handler.StreamHandler) dict#
- class ethos_penalps.utilities.own_object_json_encoding_decoding.MyDecoder(**kwargs)#
Bases:
ExtendedDecoderSimple JSON <https://json.org> decoder
Performs the following translations in decoding by default:
JSON
Python
object
dict
array
list
string
str
number (int)
int
number (real)
float
true
True
false
False
null
None
It also understands
NaN,Infinity, and-Infinityas their correspondingfloatvalues, which is outside the JSON spec.- decode_BatchStream(batch_stream_dictionary: dict) ethos_penalps.stream.BatchStream#
- decode_ContinuousStream(continuous_stream_dictionary: dict) ethos_penalps.stream.ContinuousStream#
- decode_StreamHandler(stream_handler_dict: dict) ethos_penalps.stream_handler.StreamHandler#