From 3b045612a05bb688ad44481062dbd4a3fb390499 Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Tue, 2 Oct 2018 15:01:06 +0200 Subject: [PATCH] xmr: serialize - TupleType removed --- .../monero/xmr/serialize/message_types.py | 6 -- src/apps/monero/xmr/serialize/xmrserialize.py | 66 ------------------- 2 files changed, 72 deletions(-) diff --git a/src/apps/monero/xmr/serialize/message_types.py b/src/apps/monero/xmr/serialize/message_types.py index ab6a5b996..becae5db8 100644 --- a/src/apps/monero/xmr/serialize/message_types.py +++ b/src/apps/monero/xmr/serialize/message_types.py @@ -71,12 +71,6 @@ class ContainerType(XmrType): ELEM_TYPE = None -class TupleType(XmrType): - @classmethod - def f_specs(cls): - return () - - class MessageType(XmrType): def __init__(self, **kwargs): for kw in kwargs: diff --git a/src/apps/monero/xmr/serialize/xmrserialize.py b/src/apps/monero/xmr/serialize/xmrserialize.py index 167cc99a7..ea8b56919 100644 --- a/src/apps/monero/xmr/serialize/xmrserialize.py +++ b/src/apps/monero/xmr/serialize/xmrserialize.py @@ -47,7 +47,6 @@ BlobType, ContainerType, MessageType, - TupleType, UnicodeType, VariantType, container_elem_type, @@ -193,21 +192,6 @@ def container_val(self, elem, container_type, params=None): else: raise ValueError("Not supported") - def tuple(self, elem=None, elem_type=None, params=None): - """ - Loads/dumps tuple - """ - if hasattr(elem_type, "serialize_archive"): - container = elem_type() if elem is None else elem - return container.serialize_archive( - self, elem=elem, elem_type=elem_type, params=params - ) - - if self.writing: - return self._dump_tuple(self.iobj, elem, elem_type, params) - else: - return self._load_tuple(self.iobj, elem_type, params=params, elem=elem) - def variant(self, elem=None, elem_type=None, params=None, wrapped=None): """ Loads/dumps variant type @@ -279,7 +263,6 @@ def _get_type(self, elem_type): UnicodeType, VariantType, ContainerType, - TupleType, MessageType, ) cname = elem_type.__name__ @@ -342,9 +325,6 @@ def field(self, elem=None, elem_type=None, params=None): container=get_elem(elem), container_type=elem_type, params=params ) - elif self._is_type(etype, TupleType): # tuple ~ simple list - fvalue = self.tuple(elem=get_elem(elem), elem_type=elem_type, params=params) - elif self._is_type(etype, MessageType): fvalue = self.message(get_elem(elem), msg_type=elem_type) @@ -420,52 +400,6 @@ def _load_container(self, reader, container_type, params=None, container=None): res.append(fvalue) return res - def _dump_tuple(self, writer, elem, elem_type, params=None): - """ - Dumps tuple of elements to the writer. - """ - if len(elem) != len(elem_type.f_specs()): - raise ValueError( - "Fixed size tuple has not defined size: %s" % len(elem_type.f_specs()) - ) - dump_uvarint(writer, len(elem)) - - elem_fields = params[0] if params else None - if elem_fields is None: - elem_fields = elem_type.f_specs() - for idx, elem in enumerate(elem): - self.dump_field( - writer, elem, elem_fields[idx], params[1:] if params else None - ) - - def _load_tuple(self, reader, elem_type, params=None, elem=None): - """ - Loads tuple of elements from the reader. Supports the tuple ref. - Returns loaded tuple. - """ - - c_len = load_uvarint(reader) - if elem and c_len != len(elem): - raise ValueError("Size mismatch") - if c_len != len(elem_type.f_specs()): - raise ValueError("Tuple size mismatch") - - elem_fields = params[0] if params else None - if elem_fields is None: - elem_fields = elem_type.f_specs() - - res = elem if elem else [] - for i in range(c_len): - fvalue = self.load_field( - reader, - elem_fields[i], - params[1:] if params else None, - eref(res, i) if elem else None, - ) - if not elem: - res.append(fvalue) - return res - def _dump_message_field(self, writer, msg, field, fvalue=None): """ Dumps a message field to the writer. Field is defined by the message field specification.