From e947afc3cbd5d3eb0571b49f42fc74ea0fcedc8d Mon Sep 17 00:00:00 2001 From: Justin Buchanan Date: Thu, 19 Oct 2023 18:22:37 -0700 Subject: [PATCH] handle bytes and bytearray codec outputs in cq-cli.py --- cq-cli.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cq-cli.py b/cq-cli.py index 6e1ace1..f724668 100755 --- a/cq-cli.py +++ b/cq-cli.py @@ -390,8 +390,14 @@ def main(): if outfile == None: print(converted) else: - with open(outfile, 'w') as file: - file.write(converted) + if isinstance(converted, str): + with open(outfile, 'w') as file: + file.write(converted) + elif isinstance(converted, (bytes, bytearray)): + with open(outfile, 'wb') as file: + file.write(converted) + else: + raise TypeError("Expected converted output to be str, bytes, or bytearray. Got '%s'" % type(converted).__name__) except Exception: out_tb = traceback.format_exc()