summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--paramiko/sftp_client.py17
-rw-r--r--paramiko/sftp_file.py2
-rw-r--r--paramiko/sftp_server.py4
3 files changed, 12 insertions, 11 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index 22a9a045..11b61f74 100644
--- a/paramiko/sftp_client.py
+++ b/paramiko/sftp_client.py
@@ -48,6 +48,7 @@ def _to_unicode(s):
except UnicodeError:
return s
+b_slash = b('/')
class SFTPClient (BaseSFTP):
"""
@@ -185,8 +186,8 @@ class SFTPClient (BaseSFTP):
raise SFTPError('Expected name response')
count = msg.get_int()
for i in range(count):
- filename = _to_unicode(msg.get_string())
- longname = _to_unicode(msg.get_string())
+ filename = msg.get_text()
+ longname = msg.get_text()
attr = SFTPAttributes._from_msg(msg, filename, longname)
if (filename != '.') and (filename != '..'):
filelist.append(attr)
@@ -494,7 +495,7 @@ class SFTPClient (BaseSFTP):
count = msg.get_int()
if count != 1:
raise SFTPError('Realpath returned %d results' % count)
- return _to_unicode(msg.get_string())
+ return msg.get_text()
def chdir(self, path):
"""
@@ -517,7 +518,7 @@ class SFTPClient (BaseSFTP):
return
if not stat.S_ISDIR(self.stat(path).st_mode):
raise SFTPError(errno.ENOTDIR, "%s: %s" % (os.strerror(errno.ENOTDIR), path))
- self._cwd = self.normalize(path).encode('utf-8')
+ self._cwd = b(self.normalize(path))
def getcwd(self):
"""
@@ -530,7 +531,7 @@ class SFTPClient (BaseSFTP):
@since: 1.4
"""
- return self._cwd
+ return u(self._cwd)
def putfo(self, fl, remotepath, file_size=0, callback=None, confirm=True):
"""
@@ -769,15 +770,15 @@ class SFTPClient (BaseSFTP):
Return an adjusted path if we're emulating a "current working
directory" for the server.
"""
- path = bytestring(path)
+ path = b(path)
if self._cwd is None:
return path
if (len(path) > 0) and (path[0] == '/'):
# absolute path
return path
- if self._cwd == '/':
+ if self._cwd == b_slash:
return self._cwd + path
- return self._cwd + '/' + path
+ return self._cwd + b_slash + path
class SFTP (SFTPClient):
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py
index 8cc72336..754d0384 100644
--- a/paramiko/sftp_file.py
+++ b/paramiko/sftp_file.py
@@ -165,7 +165,7 @@ class SFTPFile (BufferedFile):
def _write(self, data):
# may write less than requested if it would exceed max packet size
chunk = min(len(data), self.MAX_REQUEST_SIZE)
- self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), str(data[:chunk])))
+ self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), data[:chunk]))
if not self.pipelined or (len(self._reqs) > 100 and self.sftp.sock.recv_ready()):
while len(self._reqs):
req = self._reqs.popleft()
diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py
index 63fe5cc6..19f1ab9d 100644
--- a/paramiko/sftp_server.py
+++ b/paramiko/sftp_server.py
@@ -183,7 +183,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
msg.add_int(item)
elif type(item) is long:
msg.add_int64(item)
- elif isinstance(item, string_types):
+ elif isinstance(item, (string_types, bytes_types)):
msg.add_string(item)
elif type(item) is SFTPAttributes:
item._pack(msg)
@@ -196,7 +196,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
# must be error code
self._send_status(request_number, handle)
return
- handle._set_name('hx%d' % self.next_handle)
+ handle._set_name(b('hx%d' % self.next_handle))
self.next_handle += 1
if folder:
self.folder_table[handle._get_name()] = handle