More type conversion
This commit is contained in:
parent
951e8cfd3a
commit
d26bf3e63e
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue