diff options
author | Martin Packman <gzlist@googlemail.com> | 2017-05-25 20:37:14 +0100 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2017-06-09 13:41:17 -0700 |
commit | e66899a87ed2e510b66116284fc95763f5a2f4ec (patch) | |
tree | 97dfe2033c70d97d4f7a30b4f36ec892b50ea269 /paramiko/file.py | |
parent | 85dd4d777ccfe9e9fd23c650d43386a0b50444b7 (diff) | |
download | paramiko-e66899a87ed2e510b66116284fc95763f5a2f4ec.tar.gz |
Allow any buffer type to written to BufferedFile
Fixes #967
Also adds test coverage for writing various types to
BufferedFile which required some small changes to the test
LoopbackFile subclass.
Change against the 1.17 branch.
Diffstat (limited to 'paramiko/file.py')
-rw-r--r-- | paramiko/file.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/paramiko/file.py b/paramiko/file.py index 5212091a..35637b8e 100644 --- a/paramiko/file.py +++ b/paramiko/file.py @@ -18,7 +18,7 @@ from paramiko.common import ( linefeed_byte_value, crlf, cr_byte, linefeed_byte, cr_byte_value, ) -from paramiko.py3compat import BytesIO, PY2, u, b, bytes_types +from paramiko.py3compat import BytesIO, PY2, u, bytes_types, text_type from paramiko.util import ClosingContextManager @@ -391,7 +391,10 @@ class BufferedFile (ClosingContextManager): :param data: ``str``/``bytes`` data to write """ - data = b(data) + if isinstance(data, text_type): + # GZ 2017-05-25: Accepting text on a binary stream unconditionally + # cooercing to utf-8 seems questionable, but compatibility reasons? + data = data.encode('utf-8') if self._closed: raise IOError('File is closed') if not (self._flags & self.FLAG_WRITE): |