ethos_penalps.utilities.own_object_json_encoding_decoding#

Module Contents#

Classes#

ExtendedEncoder

Extensible JSON <https://json.org> encoder for Python data structures.

ExtendedDecoder

Simple JSON <https://json.org> decoder

MyEncoder

Extensible JSON <https://json.org> encoder for Python data structures.

MyDecoder

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.JSONEncoder

Extensible 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 for o if possible, otherwise it should call the superclass implementation (to raise TypeError).

default(obj)#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

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.JSONDecoder

Simple 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 -Infinity as their corresponding float values, 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: ExtendedEncoder

Extensible 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 for o if possible, otherwise it should call the superclass implementation (to raise TypeError).

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: ExtendedDecoder

Simple 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 -Infinity as their corresponding float values, 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#