1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-08 22:40:59 +00:00

Message can be initialized with kwargs

This commit is contained in:
Jan Pochyla 2016-06-01 14:06:41 +02:00 committed by Pavol Rusnak
parent 67ea7dbd15
commit 46f96ddb81
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -117,9 +117,9 @@ class MessageType:
self.__flags[tag] = flags
return self # Allow add_field chaining.
def __call__(self):
def __call__(self, **fields):
# Creates an instance of this message type.
return Message(self)
return Message(self, **fields)
def __has_flag(self, tag, flag, mask):
# Checks whether the field with the specified tag has the specified flag.
@ -197,9 +197,10 @@ class MessageType:
class Message:
# Represents a message instance.
def __init__(self, message_type):
def __init__(self, message_type, **fields):
# Initializes a new instance of the specified message type.
self.message_type = message_type
self.__dict__.update(fields)
def dump(self, fp):
# Dumps the message into a write-like object.