From c9929e0f904bfd06c3719a771f42280922781c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szil=C3=A1rd=20Pfeiffer?= Date: Mon, 13 Nov 2023 19:39:57 +0100 Subject: [PATCH] fix(serializabel)!: Use str verion of CryptoDataParamsBase objets in Markdown result --- cryptoparser/common/base.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cryptoparser/common/base.py b/cryptoparser/common/base.py index 5c61b85..a2c2dfe 100644 --- a/cryptoparser/common/base.py +++ b/cryptoparser/common/base.py @@ -60,6 +60,12 @@ def __call__(self, obj, level): class Serializable(object): # pylint: disable=too-few-public-methods + _MARKDOWN_RESULT_STRING_CLASSES = ( + CryptoDataParamsBase, + ipaddress.IPv4Network, + ipaddress.IPv6Network, + urllib3.util.url.Url, + ) post_text_encoder = SerializableTextEncoder() @staticmethod @@ -239,12 +245,12 @@ def _markdown_result(cls, obj, level=0): # pylint: disable=too-many-branches return cls.post_text_encoder(obj.value, level) return cls.post_text_encoder(obj.name, level) - elif isinstance(obj, (ipaddress.IPv4Network, ipaddress.IPv6Network, urllib3.util.url.Url)): + elif attr.has(type(obj)): + result = cls._markdown_result_complex(obj, level) + elif isinstance(obj, cls._MARKDOWN_RESULT_STRING_CLASSES): return False, str(obj) elif isinstance(obj, datetime.timedelta): return False, str(obj.seconds) - elif attr.has(type(obj)): - result = cls._markdown_result_complex(obj, level) elif hasattr(obj, '_asdict'): result = cls._markdown_result(obj._asdict(), level) elif hasattr(obj, '__dict__') or isinstance(obj, dict):