clean MessageBase
@@ -58,7 +58,8 @@ class MessageBase(Mapping, MessageValidator):
typename = None
def __init__(self, *args, **kwargs):
- assert not (args and kwargs), '*args, **kwargs cannot be used together'
+ assert not (args and kwargs), \
+ '*args, **kwargs cannot be used together'
if kwargs:
# op field is not required since there is self.typename
@@ -70,14 +71,15 @@ class MessageBase(Mapping, MessageValidator):
"same as a number of fields in schema, but it was {}" \
.format(argsLen)
- if args:
- input_as_dict = dict(zip(map(itemgetter(0), self.schema), args))
- else:
- input_as_dict = kwargs
+ input_as_dict = kwargs if kwargs else self._join_with_schema(args)
self.validate(input_as_dict)
+
self._fields = OrderedDict((name, input_as_dict[name]) for name, _ in self.schema)
+ def _join_with_schema(self, args):
+ return dict(zip(map(itemgetter(0), self.schema), args))
+
def __getattr__(self, item):
return self._fields[item]
