Parse the output according to specified format. Raise an error if the output can't be parsed.
(a, fmt)
| 160 | raise Exception |
| 161 | |
| 162 | def parse_output(a, fmt): |
| 163 | """Parse the output according to specified format. |
| 164 | |
| 165 | Raise an error if the output can't be parsed.""" |
| 166 | if fmt == 'json': # json: compare parsed data |
| 167 | return json.loads(a) |
| 168 | elif fmt == 'hex': # hex: parse and compare binary data |
| 169 | return bytes.fromhex(a.strip()) |
| 170 | else: |
| 171 | raise NotImplementedError("Don't know how to compare %s" % fmt) |
| 172 | |
| 173 | if __name__ == '__main__': |
| 174 | main() |