-
Notifications
You must be signed in to change notification settings - Fork 913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New pyln modules. #3733
Merged
cdecker
merged 18 commits into
ElementsProject:master
from
rustyrussell:guilt/pyln-messages
Jun 12, 2020
Merged
New pyln modules. #3733
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ca71845
pyln: add Makefile
rustyrussell 31fa55e
pyln: add pyln.proto.message.
rustyrussell 16297af
patch message-export-types.patch
rustyrussell 1bff330
pyln.proto.message: use BufferedIOBase instead of bytes for binary ops.
rustyrussell 46151ed
pyln.proto.message: expose fundamental MessageTypes as variables.
rustyrussell e274226
pyln: add (undocumented) u8 fundamental type.
rustyrussell 59e2064
message: support option fields.
rustyrussell 784d138
pyln.proto.message: separate fundamental types from other subtypes.
rustyrussell a4eb933
pyln: new module pyln.proto.message.bolts
rustyrussell 42fc48f
new modules: pyln.proto.message.{bolt1,bolt2,bolt4,bolt7}
rustyrussell 3ed6831
pyln.proto.message: support adding two namespaces.
rustyrussell 360bcaf
pyln.proto.message: python-fluency feedback from @darosior
rustyrussell 4a336db
pyln.proto.message: export more.
rustyrussell efd38a4
pyln.proto.message: allow fields with options to be missing.
rustyrussell bef68d3
pyln.proto.message.*: Add Makefile to do mypy checks.
rustyrussell 851122d
pyln.proto.message.*: add type annotations.
rustyrussell e0d3174
pyln.proto.message: expose array types, add set_field for Message class.
rustyrussell 5dbec8f
pyln.proto.message: fix handling of missing optional fields.
rustyrussell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,13 @@ class MessageNamespace(object): | |
domain, such as within a given BOLT""" | ||
def __init__(self, csv_lines=[]): | ||
self.subtypes = {} | ||
self.fundamentaltypes = {} | ||
self.tlvtypes = {} | ||
self.messagetypes = {} | ||
|
||
# For convenience, basic types go in every namespace | ||
for t in fundamental_types(): | ||
self.add_subtype(t) | ||
self.add_fundamentaltype(t) | ||
|
||
self.load_csv(csv_lines) | ||
|
||
|
@@ -26,6 +27,10 @@ def add_subtype(self, t): | |
return ValueError('Already have {}'.format(prev)) | ||
self.subtypes[t.name] = t | ||
|
||
def add_fundamentaltype(self, t): | ||
assert not self.get_type(t.name) | ||
self.fundamentaltypes[t.name] = t | ||
|
||
def add_tlvtype(self, t): | ||
prev = self.get_type(t.name) | ||
if prev: | ||
|
@@ -51,6 +56,11 @@ def get_msgtype_by_number(self, num): | |
return m | ||
return None | ||
|
||
def get_fundamentaltype(self, name): | ||
if name in self.fundamentaltypes: | ||
return self.fundamentaltypes[name] | ||
return None | ||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An idiomatic way of doing this is with the getter and default value: return self.fundamentaltypes.get(name, None) |
||
|
||
def get_subtype(self, name): | ||
if name in self.subtypes: | ||
return self.subtypes[name] | ||
|
@@ -62,7 +72,9 @@ def get_tlvtype(self, name): | |
return None | ||
|
||
def get_type(self, name): | ||
t = self.get_subtype(name) | ||
t = self.get_fundamentaltype(name) | ||
if not t: | ||
t = self.get_subtype(name) | ||
if not t: | ||
t = self.get_tlvtype(name) | ||
return t | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be weakened a bit to be
Which would no longer fail outright if we happen to add the same type multiple times.