diff --git a/paramiko/channel.py b/paramiko/channel.py index d715bb8..6a8a798 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -969,7 +969,7 @@ class Channel (object): self.transport._send_user_message(m) def _feed(self, m): - if isinstance(m, bytes_type): + if isinstance(m, bytes_types): # passed from _feed_extended s = m else: diff --git a/paramiko/common.py b/paramiko/common.py index 9161f30..5d7ab31 100644 --- a/paramiko/common.py +++ b/paramiko/common.py @@ -140,7 +140,7 @@ else: def asbytes(s): - if not isinstance(s, bytes_type): + if not isinstance(s, bytes_types): if isinstance(s, string_types): s = b(s) else: diff --git a/paramiko/py3compat.py b/paramiko/py3compat.py index e4830da..fd6488d 100644 --- a/paramiko/py3compat.py +++ b/paramiko/py3compat.py @@ -1,6 +1,6 @@ import sys -__all__ = ['PY3', 'string_types', 'integer_types', 'text_type', 'bytes_type', 'long', 'input', 'bytestring', 'byte_ord', 'byte_chr', 'byte_mask', 'b', 'u', 'b2s', 'StringIO', 'BytesIO', 'is_callable', 'MAXSIZE', 'next'] +__all__ = ['PY3', 'string_types', 'integer_types', 'text_type', 'bytes_types', 'long', 'input', 'bytestring', 'byte_ord', 'byte_chr', 'byte_mask', 'b', 'u', 'b2s', 'StringIO', 'BytesIO', 'is_callable', 'MAXSIZE', 'next'] PY3 = sys.version_info[0] >= 3 @@ -8,9 +8,9 @@ if PY3: import collections import struct string_types = str - integer_types = int text_type = str - bytes_type = bytes + bytes_types = bytes + integer_types = int long = int input = input @@ -65,9 +65,9 @@ if PY3: MAXSIZE = sys.maxsize # NOQA else: string_types = basestring - integer_types = (int, long) text_type = unicode - bytes_type = str + bytes_types = str + integer_types = (int, long) long = long input = raw_input diff --git a/paramiko/sftp.py b/paramiko/sftp.py index 11aa3cb..4186460 100644 --- a/paramiko/sftp.py +++ b/paramiko/sftp.py @@ -142,7 +142,7 @@ class BaseSFTP (object): return def _read_all(self, n): - out = '' + out = bytes() while n > 0: if isinstance(self.sock, socket.socket): # sometimes sftp is used directly over a socket instead of @@ -176,7 +176,7 @@ class BaseSFTP (object): x = self._read_all(4) # most sftp servers won't accept packets larger than about 32k, so # anything with the high byte set (> 16MB) is just garbage. - if x[0] != '\x00': + if byte_ord(x[0]): raise SFTPError('Garbage packet received') size = struct.unpack('>I', x)[0] data = self._read_all(size) diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 7703246..22a9a04 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -42,7 +42,7 @@ def _to_unicode(s): """ try: return s.encode('ascii') - except UnicodeError: + except (UnicodeError, AttributeError): try: return s.decode('utf-8') except UnicodeError: @@ -698,7 +698,7 @@ class SFTPClient (BaseSFTP): msg.add_int(item) elif isinstance(item, long): msg.add_int64(item) - elif isinstance(item, string_types): + elif isinstance(item, (string_types, bytes_types)): msg.add_string(item) elif isinstance(item, SFTPAttributes): item._pack(msg)