Last active
March 24, 2020 15:42
-
-
Save Ananto30/0c1e7f6c67d21046783042bc69ffbe25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import msgpack | |
class Btypes: | |
def pack(self): | |
return msgpack.packb(Btypes.get_all_vars(self)) | |
@classmethod | |
def unpack(cls, d): | |
return cls(**msgpack.unpackb(d, raw=False)) | |
@staticmethod | |
def get_all_vars(obj): | |
values = vars(obj) | |
for k, v in values.items(): | |
if isinstance(v, Btypes): | |
values[k] = vars(v) | |
return values | |
class Etypes(Btypes): | |
def __init__(self, operation: str, request, response=None): | |
self.operation = operation | |
self.request = request | |
self.response = response | |
class TypeCheckFailedException(Exception): | |
pass | |
def type_check(o, t): | |
if not isinstance(o, t): | |
raise TypeCheckFailedException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment