summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-10-31 16:19:11 -0700
committerScott Maxwell <scott@codecobblers.com>2013-10-31 16:19:11 -0700
commitd26bf3e63efea0002fd81c7579f2b37cc6c587c1 (patch)
treebdc2c5aed0df356104aa82327fc3acf9dc839e2e
parent951e8cfd3a4d892cdaed82ce6b62803dcc001209 (diff)
More type conversion
-rw-r--r--paramiko/channel.py2
-rw-r--r--paramiko/common.py2
-rw-r--r--paramiko/py3compat.py10
-rw-r--r--paramiko/sftp.py4
-rw-r--r--paramiko/sftp_client.py4
5 files changed, 11 insertions, 11 deletions
diff --git a/paramiko/channel.py b/paramiko/channel.py
index d715bb88..6a8a7984 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 9161f309..5d7ab313 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 e4830dad..fd6488d8 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 11aa3cb4..41864600 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 7703246a..22a9a045 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)