Parse the output according to specified format. Raise an error if the output can't be parsed.
(a, fmt)
| 118 | |
| 119 | |
| 120 | def parse_output(a, fmt): |
| 121 | """Parse the output according to specified format. |
| 122 | |
| 123 | Raise an error if the output can't be parsed.""" |
| 124 | if fmt == 'json': # json: compare parsed data |
| 125 | return json.loads(a) |
| 126 | elif fmt == 'hex': # hex: parse and compare binary data |
| 127 | return bytes.fromhex(a.strip()) |
| 128 | else: |
| 129 | raise NotImplementedError("Don't know how to compare %s" % fmt) |
| 130 | |
| 131 | |
| 132 | if __name__ == "__main__": |