diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-03-17 15:52:23 +0100 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-03-17 15:52:23 +0100 |
commit | f0627bed3e8815e8138fbe72b740483f69d6ac7a (patch) | |
tree | b3c76a0cc0efe1a08ee50683a647292fe91ba90d /rsa/cli.py | |
parent | 3d5c098dbcd1f7732b7b559f793f4b0944e90884 (diff) | |
download | rsa-git-f0627bed3e8815e8138fbe72b740483f69d6ac7a.tar.gz |
More CLI tests & clearer bytes stuff
Ensuring that bytes are written correctly on all supported Python
versions, including when writing to stdout.
Diffstat (limited to 'rsa/cli.py')
-rw-r--r-- | rsa/cli.py | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -84,8 +84,10 @@ def keygen(): else: print('Writing private key to stdout', file=sys.stderr) if sys.version_info[0] >= 3: - data = data.decode('ascii') # on Py3 we must write text, not bytes - sys.stdout.write(data) + # on Py3 we must use the buffer interface to write bytes. + sys.stdout.buffer.write(data) + else: + sys.stdout.write(data) class CryptoOperation(object): @@ -114,7 +116,7 @@ class CryptoOperation(object): self.output_help = self.output_help % self.__class__.__dict__ @abc.abstractmethod - def perform_operation(self, indata, key, cli_args=None): + def perform_operation(self, indata, key, cli_args): """Performs the program's operation. Implement in a subclass. @@ -192,8 +194,10 @@ class CryptoOperation(object): else: print('Writing output to stdout', file=sys.stderr) if sys.version_info[0] >= 3: - data = outdata.decode('ascii') # on Py3 we must write text, not bytes - sys.stdout.write(outdata) + # on Py3 we must use the buffer interface to write bytes. + sys.stdout.buffer.write(outdata) + else: + sys.stdout.write(outdata) class EncryptOperation(CryptoOperation): |