From d5f43fa4dbd0e31d9ac3e2e57ead70c4a9780888 Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Tue, 2 Oct 2018 15:06:48 +0200 Subject: [PATCH] xmr: serialize reimport removed - complex types are not surviving protocol boundary anymore, no need to fix hierarchy problems due to unimporting --- src/apps/monero/xmr/serialize/xmrserialize.py | 44 +------------------ 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/src/apps/monero/xmr/serialize/xmrserialize.py b/src/apps/monero/xmr/serialize/xmrserialize.py index ea8b56919..28a02a1ad 100644 --- a/src/apps/monero/xmr/serialize/xmrserialize.py +++ b/src/apps/monero/xmr/serialize/xmrserialize.py @@ -31,10 +31,6 @@ >>> """ ''' -import sys - -from trezor import log - from apps.monero.xmr.serialize.base_types import IntType, UVarintType, XmrType from apps.monero.xmr.serialize.erefs import eref, get_elem, set_elem from apps.monero.xmr.serialize.int_serialize import ( @@ -54,18 +50,6 @@ ) -def import_def(module, name): - if module not in sys.modules: - if not module.startswith("apps.monero"): - raise ValueError("Module not allowed: %s" % module) - if __debug__: - log.debug(__name__, "Importing: from %s import %s", module, name) - __import__(module, None, None, (name,), 0) - - r = getattr(sys.modules[module], name) - return r - - class Archive: """ Archive object for object binary serialization / deserialization. @@ -255,7 +239,8 @@ def _get_type(self, elem_type): if issubclass(elem_type, XmrType): return elem_type - # Basic decision types + # Basic message types determined by the name. + # Due to unimport workflow the hierarchy linking may got lost. etypes = ( UVarintType, IntType, @@ -270,31 +255,6 @@ def _get_type(self, elem_type): if cname == e.__name__: return e - # Inferred type: need to translate it to the current - try: - m = elem_type.__module__ - r = import_def(m, cname) - sub_test = issubclass(r, XmrType) - if __debug__: - log.debug( - __name__, - "resolved %s, sub: %s, id_e: %s, id_mod: %s", - r, - sub_test, - id(r), - id(sys.modules[m]), - ) - if not sub_test: - log.warning(__name__, "resolution hierarchy broken") - - return r - - except Exception as e: - raise ValueError( - "Could not translate elem type: %s %s, exc: %s %s" - % (type(elem_type), elem_type, type(e), e) - ) - def _is_type(self, elem_type, test_type): return issubclass(elem_type, test_type)