Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ca71845
pyln: add Makefile
rustyrussell May 18, 2020
31fa55e
pyln: add pyln.proto.message.
rustyrussell May 28, 2020
16297af
patch message-export-types.patch
rustyrussell Jun 3, 2020
1bff330
pyln.proto.message: use BufferedIOBase instead of bytes for binary ops.
rustyrussell Jun 4, 2020
46151ed
pyln.proto.message: expose fundamental MessageTypes as variables.
rustyrussell Jun 4, 2020
e274226
pyln: add (undocumented) u8 fundamental type.
rustyrussell Jun 4, 2020
59e2064
message: support option fields.
rustyrussell Jun 4, 2020
784d138
pyln.proto.message: separate fundamental types from other subtypes.
rustyrussell Jun 4, 2020
a4eb933
pyln: new module pyln.proto.message.bolts
rustyrussell Jun 4, 2020
42fc48f
new modules: pyln.proto.message.{bolt1,bolt2,bolt4,bolt7}
rustyrussell Jun 4, 2020
3ed6831
pyln.proto.message: support adding two namespaces.
rustyrussell Jun 4, 2020
360bcaf
pyln.proto.message: python-fluency feedback from @darosior
rustyrussell Jun 4, 2020
4a336db
pyln.proto.message: export more.
rustyrussell Jun 4, 2020
efd38a4
pyln.proto.message: allow fields with options to be missing.
rustyrussell Jun 4, 2020
bef68d3
pyln.proto.message.*: Add Makefile to do mypy checks.
rustyrussell Jun 4, 2020
851122d
pyln.proto.message.*: add type annotations.
rustyrussell Jun 12, 2020
e0d3174
pyln.proto.message: expose array types, add set_field for Message class.
rustyrussell Jun 12, 2020
5dbec8f
pyln.proto.message: fix handling of missing optional fields.
rustyrussell Jun 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions contrib/pyln-proto/pyln/proto/message/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .array_types import SizedArrayType, DynamicArrayType, EllipsisArrayType
from .message import MessageNamespace, MessageType, Message, SubtypeType
from .fundamental_types import split_field, FieldType

Expand All @@ -10,6 +11,9 @@
"SubtypeType",
"FieldType",
"split_field",
"SizedArrayType",
"DynamicArrayType",
"EllipsisArrayType",
Comment on lines +14 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these only required for unit tests? In that case we could also not expose them here, and have the unit tests reach directly into .array_types

from pyln.proto.message.array_types import SizedArrayType, DynamicArrayType, EllipsisArrayType

If that helps keep the interface clean for the actual protocol tests.


# fundamental_types
'byte',
Expand Down
22 changes: 12 additions & 10 deletions contrib/pyln-proto/pyln/proto/message/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,22 +545,24 @@ def __init__(self, messagetype: MessageType, **kwargs):

# Convert arguments from strings to values if necessary.
for field in kwargs:
f = self.messagetype.find_field(field)
if f is None:
raise ValueError("Unknown field {}".format(field))

v = kwargs[field]
if isinstance(v, str):
v, remainder = f.fieldtype.val_from_str(v)
if remainder != '':
raise ValueError('Unexpected {} at end of initializer for {}'.format(remainder, field))
self.fields[field] = v
self.set_field(field, kwargs[field])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be achieved with this:

for key, val in kwargs.items():
    self.set_field(key, val)


bad_lens = self.messagetype.len_fields_bad(self.messagetype.name,
self.fields)
if bad_lens:
raise ValueError("Inconsistent length fields: {}".format(bad_lens))

def set_field(self, field: str, val: Any) -> None:
f = self.messagetype.find_field(field)
if f is None:
raise ValueError("Unknown field {}".format(field))

if isinstance(val, str):
val, remainder = f.fieldtype.val_from_str(val)
if remainder != '':
raise ValueError('Unexpected {} at end of initializer for {}'.format(remainder, field))
self.fields[field] = val

def missing_fields(self) -> List[str]:
"""Are any required fields missing?"""
missing: List[str] = []
Expand Down