diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2014-07-05 23:51:38 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2014-07-09 03:30:29 +0200 |
commit | 9ef02e1a97477a1476f64e690fb6bc21e78be037 (patch) | |
tree | e5bfaac6ef80f1bbf280829abd21f4e789d68f52 | |
parent | e811e715833373dd2f2ba898089695eee9c882ed (diff) |
Support passing in "buffer" objects again where bytestrings are expected.
This fixes bzr's use of paramiko.
Fixes issue #343/#285.
-rw-r--r-- | paramiko/py3compat.py | 4 | ||||
-rwxr-xr-x | tests/test_file.py | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/paramiko/py3compat.py b/paramiko/py3compat.py index 8842b988..57c096b2 100644 --- a/paramiko/py3compat.py +++ b/paramiko/py3compat.py @@ -39,6 +39,8 @@ if PY2: return s elif isinstance(s, unicode): return s.encode(encoding) + elif isinstance(s, buffer): + return s else: raise TypeError("Expected unicode or bytes, got %r" % s) @@ -49,6 +51,8 @@ if PY2: return s.decode(encoding) elif isinstance(s, unicode): return s + elif isinstance(s, buffer): + return s.decode(encoding) else: raise TypeError("Expected unicode or bytes, got %r" % s) diff --git a/tests/test_file.py b/tests/test_file.py index c6edd7af..22a34aca 100755 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -23,6 +23,7 @@ Some unit tests for the BufferedFile abstraction. import unittest from paramiko.file import BufferedFile from paramiko.common import linefeed_byte, crlf, cr_byte +import sys class LoopbackFile (BufferedFile): @@ -151,6 +152,15 @@ class BufferedFileTest (unittest.TestCase): b'need to close them again.\n') f.close() + def test_8_buffering(self): + """ + verify that buffered objects can be written + """ + if sys.version_info[0] == 2: + f = LoopbackFile('r+', 16) + f.write(buffer(b'Too small.')) + f.close() + if __name__ == '__main__': from unittest import main main() |