diff options
Diffstat (limited to 'freezed_deps/base58/__main__.py')
-rw-r--r-- | freezed_deps/base58/__main__.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/freezed_deps/base58/__main__.py b/freezed_deps/base58/__main__.py new file mode 100644 index 0000000..b76fdad --- /dev/null +++ b/freezed_deps/base58/__main__.py @@ -0,0 +1,47 @@ +import argparse +import sys + +from base58 import b58decode, b58decode_check, b58encode, b58encode_check + + +def main(): + '''Base58 encode or decode FILE, or standard input, to standard output.''' + + stdout = sys.stdout.buffer + + parser = argparse.ArgumentParser(description=main.__doc__) + parser.add_argument( + 'file', + metavar='FILE', + nargs='?', + type=argparse.FileType('r'), + default='-') + parser.add_argument( + '-d', '--decode', + action='store_true', + help='decode data') + parser.add_argument( + '-c', '--check', + action='store_true', + help='append a checksum before encoding') + + args = parser.parse_args() + fun = { + (False, False): b58encode, + (False, True): b58encode_check, + (True, False): b58decode, + (True, True): b58decode_check + }[(args.decode, args.check)] + + data = args.file.buffer.read() + + try: + result = fun(data) + except Exception as e: + sys.exit(e) + + stdout.write(result) + + +if __name__ == '__main__': + main() |