Conversation
* Fixes #118 (please see issue for details) * Introduce `capabilities` property (for cases where there are >1 capablity) * Keep older `capability` property for backward compatibility * Added `__bgp10` unittest, which broke the original parser
obormot
left a comment
There was a problem hiding this comment.
minor comments.. looks good overall 👍
|
|
||
| def __bytes__(self): | ||
| caps = b''.join(map(bytes, self.capabilities)) | ||
| self.cap_len = len(caps) |
There was a problem hiding this comment.
unused?
also prob shouldn't create new fields inside this method
| self.capability = self.capabilities[0] | ||
|
|
||
| def __len__(self): | ||
| return self.__hdr_len__ + sum(map(len, self.capabilities)) |
There was a problem hiding this comment.
calling len() on each instance of capability would cause serialization to bytes, then taking the resulting length. would something like sum(cap.len for cap in self.capabilities) achieve the same result?
There was a problem hiding this comment.
Alternatively you could override the __len__ method to return that header element?
| while self.data: | ||
| capability = self.Capability(self.data) | ||
| l.append(capability) | ||
| self.data = self.data[self.__hdr_len__+capability.len:] |
There was a problem hiding this comment.
I believe pep8 would want whitespace around +
|
Hi @kbandla , |
| self.capability = self.capabilities[0] | ||
|
|
||
| def __len__(self): | ||
| return self.__hdr_len__ + sum(map(len, self.capabilities)) |
There was a problem hiding this comment.
This doesn't cover the case where the type is AUTHENTICATION, as capabilities won't exist (and it doesn't count the length of the authentication data).
| return self.__hdr_len__ + sum(map(len, self.capabilities)) | ||
|
|
||
| def __bytes__(self): | ||
| caps = b''.join(map(bytes, self.capabilities)) |
There was a problem hiding this comment.
This will also fail if this is an authentication parameter. Perhaps some variant of caps = bytes(self.data) if not isinstance(self.data, list) else b''.join(map(bytes, self.data))?
capabilitiesproperty (for cases where there are >1 capablity)capabilityproperty for backward compatibility__bgp10unittest, which broke the original parser