Show More
@@ -110,10 +110,13 b' ARGUMENT_RECORD_HEADER = struct.Struct(r' | |||||
110 |
|
110 | |||
111 | def humanflags(mapping, value): |
|
111 | def humanflags(mapping, value): | |
112 | """Convert a numeric flags value to a human value, using a mapping table.""" |
|
112 | """Convert a numeric flags value to a human value, using a mapping table.""" | |
|
113 | namemap = {v: k for k, v in mapping.iteritems()} | |||
113 | flags = [] |
|
114 | flags = [] | |
114 | for val, name in sorted({v: k for k, v in mapping.iteritems()}.iteritems()): |
|
115 | val = 1 | |
|
116 | while value >= val: | |||
115 | if value & val: |
|
117 | if value & val: | |
116 | flags.append(name) |
|
118 | flags.append(namemap.get(val, '<unknown 0x%02x>' % val)) | |
|
119 | val <<= 1 | |||
117 |
|
120 | |||
118 | return b'|'.join(flags) |
|
121 | return b'|'.join(flags) | |
119 |
|
122 | |||
@@ -140,7 +143,7 b' class frame(object):' | |||||
140 | payload = attr.ib() |
|
143 | payload = attr.ib() | |
141 |
|
144 | |||
142 | def __repr__(self): |
|
145 | def __repr__(self): | |
143 | typename = '<unknown>' |
|
146 | typename = '<unknown 0x%02x>' % self.typeid | |
144 | for name, value in FRAME_TYPES.iteritems(): |
|
147 | for name, value in FRAME_TYPES.iteritems(): | |
145 | if value == self.typeid: |
|
148 | if value == self.typeid: | |
146 | typename = name |
|
149 | typename = name |
General Comments 0
You need to be logged in to leave comments.
Login now