Source code for bobocep.bobocep

# Copyright (c) 2019-2023 r3w0p
# The following code can be redistributed and/or
# modified under the terms of the MIT License.

"""
Core classes.
"""

from abc import ABC, abstractmethod


[docs]class BoboError(Exception): """ A `BoboCEP` error. """
[docs]class BoboJSONableError(BoboError): """ A JSONable error. """
[docs]class BoboJSONable(ABC): """ An abstract interface for JSONable types. """
[docs] @abstractmethod def to_json_str(self) -> str: """ :return: A JSON `str` representation of an object of this type. """
[docs] @abstractmethod def to_json_dict(self) -> dict: """ :return: A JSON `dict` representation of an object of this type. """
[docs] @staticmethod @abstractmethod def from_json_str(j: str) -> 'BoboJSONable': """ :param j: A JSON `str` representation of an object of this type. :return: A new instance of this type. """
[docs] @staticmethod @abstractmethod def from_json_dict(d: dict) -> 'BoboJSONable': """ :param d: A JSON `dict` representation of an object of this type. :return: A new instance of this type. """