summaryrefslogtreecommitdiff
path: root/debian/patches/0001-Upstream-GitHub-Pull-Request-352-to-fix-buffer-objec.patch
blob: 123f7c9fa8c2b470f360bf87ef8b45ca7be6f872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From: "Jeremy T. Bouse" <Jeremy.Bouse@coxinc.com>
Date: Sun, 24 Aug 2014 20:47:42 -0400
Subject: Upstream GitHub Pull Request #352 to fix "buffer" objects

Include https://github.com/paramiko/paramiko/pull/352 patch to
resolve issue with support passing in "buffer" objects again
where bytestrings are expected.
---
 paramiko/py3compat.py |  4 ++++
 tests/test_file.py    | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/paramiko/py3compat.py b/paramiko/py3compat.py
index 8842b98..57c096b 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 c6edd7a..22a34ac 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()