summaryrefslogtreecommitdiff
path: root/paramiko/sftp_client.py
diff options
context:
space:
mode:
authorDorian Pula <dorian.pula@amber-penguin-software.ca>2017-05-30 12:23:33 -0400
committerJeff Forcier <jeff@bitprophet.org>2017-05-31 17:14:40 -0700
commitddf1e357b43a8ca69848d550021f269b48361214 (patch)
treea693c5f179eafaa3725b89deb47e7e92b3416ce8 /paramiko/sftp_client.py
parentecb297518267487853813109da946d7240d717e1 (diff)
downloadparamiko-ddf1e357b43a8ca69848d550021f269b48361214.tar.gz
Additional PEP8 fixes.
Diffstat (limited to 'paramiko/sftp_client.py')
-rw-r--r--paramiko/sftp_client.py79
1 files changed, 49 insertions, 30 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index 12a9506f..245e5072 100644
--- a/paramiko/sftp_client.py
+++ b/paramiko/sftp_client.py
@@ -28,13 +28,15 @@ from paramiko import util
from paramiko.channel import Channel
from paramiko.message import Message
from paramiko.common import INFO, DEBUG, o777
-from paramiko.py3compat import bytestring, b, u, long, string_types, bytes_types
-from paramiko.sftp import BaseSFTP, CMD_OPENDIR, CMD_HANDLE, SFTPError, CMD_READDIR, \
- CMD_NAME, CMD_CLOSE, SFTP_FLAG_READ, SFTP_FLAG_WRITE, SFTP_FLAG_CREATE, \
- SFTP_FLAG_TRUNC, SFTP_FLAG_APPEND, SFTP_FLAG_EXCL, CMD_OPEN, CMD_REMOVE, \
- CMD_RENAME, CMD_MKDIR, CMD_RMDIR, CMD_STAT, CMD_ATTRS, CMD_LSTAT, \
- CMD_SYMLINK, CMD_SETSTAT, CMD_READLINK, CMD_REALPATH, CMD_STATUS, SFTP_OK, \
- SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED
+from paramiko.py3compat import bytestring, b, u, long, string_types, \
+ bytes_types
+from paramiko.sftp import BaseSFTP, CMD_OPENDIR, CMD_HANDLE, SFTPError, \
+ CMD_READDIR, CMD_NAME, CMD_CLOSE, SFTP_FLAG_READ, SFTP_FLAG_WRITE, \
+ SFTP_FLAG_CREATE, SFTP_FLAG_TRUNC, SFTP_FLAG_APPEND, SFTP_FLAG_EXCL, \
+ CMD_OPEN, CMD_REMOVE, CMD_RENAME, CMD_MKDIR, CMD_RMDIR, CMD_STAT, \
+ CMD_ATTRS, CMD_LSTAT, CMD_SYMLINK, CMD_SETSTAT, CMD_READLINK, \
+ CMD_REALPATH, CMD_STATUS, SFTP_OK, SFTP_EOF, SFTP_NO_SUCH_FILE, \
+ SFTP_PERMISSION_DENIED
from paramiko.sftp_attr import SFTPAttributes
from paramiko.ssh_exception import SSHException
@@ -56,6 +58,7 @@ def _to_unicode(s):
except UnicodeError:
return s
+
b_slash = b'/'
@@ -93,13 +96,16 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
if type(sock) is Channel:
# override default logger
transport = self.sock.get_transport()
- self.logger = util.get_logger(transport.get_log_channel() + '.sftp')
+ self.logger = util.get_logger(
+ transport.get_log_channel() + '.sftp')
self.ultra_debug = transport.get_hexdump()
try:
server_version = self._send_version()
except EOFError:
raise SSHException('EOF during negotiation')
- self._log(INFO, 'Opened sftp connection (server version %d)' % server_version)
+ self._log(
+ INFO,
+ 'Opened sftp connection (server version %d)' % server_version)
@classmethod
def from_transport(cls, t, window_size=None, max_packet_size=None):
@@ -111,7 +117,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
OpenSSH and should work adequately for both files transfers and
interactive sessions.
- :param .Transport t: an open `.Transport` which is already authenticated
+ :param .Transport t: an open `.Transport` which is already
+ authenticated
:param int window_size:
optional window size for the `.SFTPClient` session.
:param int max_packet_size:
@@ -136,9 +143,12 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
for m in msg:
self._log(level, m, *args)
else:
- # escape '%' in msg (they could come from file or directory names) before logging
- msg = msg.replace('%','%%')
- super(SFTPClient, self)._log(level, "[chan %s] " + msg, *([self.sock.get_name()] + list(args)))
+ # escape '%' in msg (they could come from file or directory names)
+ # before logging
+ msg = msg.replace('%', '%%')
+ super(SFTPClient, self)._log(
+ level,
+ "[chan %s] " + msg, *([self.sock.get_name()] + list(args)))
def close(self):
"""
@@ -160,7 +170,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
def listdir(self, path='.'):
"""
- Return a list containing the names of the entries in the given ``path``.
+ Return a list containing the names of the entries in the given
+ ``path``.
The list is in arbitrary order. It does not include the special
entries ``'.'`` and ``'..'`` even if they are present in the folder.
@@ -328,7 +339,9 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
if t != CMD_HANDLE:
raise SFTPError('Expected handle')
handle = msg.get_binary()
- self._log(DEBUG, 'open(%r, %r) -> %s' % (filename, mode, hexlify(handle)))
+ self._log(
+ DEBUG,
+ 'open(%r, %r) -> %s' % (filename, mode, hexlify(handle)))
return SFTPFile(self, handle, mode, bufsize)
# Python continues to vacillate about "open" vs "file"...
@@ -480,12 +493,12 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
def utime(self, path, times):
"""
- Set the access and modified times of the file specified by ``path``. If
- ``times`` is ``None``, then the file's access and modified times are set
- to the current time. Otherwise, ``times`` must be a 2-tuple of numbers,
- of the form ``(atime, mtime)``, which is used to set the access and
- modified times, respectively. This bizarre API is mimicked from Python
- for the sake of consistency -- I apologize.
+ Set the access and modified times of the file specified by ``path``.
+ If ``times`` is ``None``, then the file's access and modified times
+ are set to the current time. Otherwise, ``times`` must be a 2-tuple
+ of numbers, of the form ``(atime, mtime)``, which is used to set the
+ access and modified times, respectively. This bizarre API is mimicked
+ from Python for the sake of consistency -- I apologize.
:param str path: path of the file to modify
:param tuple times:
@@ -578,7 +591,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
self._cwd = None
return
if not stat.S_ISDIR(self.stat(path).st_mode):
- raise SFTPError(errno.ENOTDIR, "%s: %s" % (os.strerror(errno.ENOTDIR), path))
+ raise SFTPError(
+ errno.ENOTDIR, "%s: %s" % (os.strerror(errno.ENOTDIR), path))
self._cwd = b(self.normalize(path))
def getcwd(self):
@@ -639,7 +653,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
if confirm:
s = self.stat(remotepath)
if s.st_size != size:
- raise IOError('size mismatch in put! %d != %d' % (s.st_size, size))
+ raise IOError(
+ 'size mismatch in put! %d != %d' % (s.st_size, size))
else:
s = SFTPAttributes()
return s
@@ -663,7 +678,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
whether to do a stat() on the file afterwards to confirm the file
size
- :return: an `.SFTPAttributes` object containing attributes about the given file
+ :return: an `.SFTPAttributes` object containing attributes about the
+ given file
.. versionadded:: 1.4
.. versionchanged:: 1.7.4
@@ -699,7 +715,7 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
reader=fr, writer=fl, file_size=file_size, callback=callback
)
- return size
+ return file_size
def get(self, remotepath, localpath, callback=None):
"""
@@ -721,9 +737,10 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
size = self.getfo(remotepath, fl, callback)
s = os.stat(localpath)
if s.st_size != size:
- raise IOError('size mismatch in get! %d != %d' % (s.st_size, size))
+ raise IOError(
+ 'size mismatch in get! %d != %d' % (s.st_size, size))
- ### internals...
+ # ...internals...
def _request(self, t, *arg):
num = self._async_request(type(None), t, *arg)
@@ -745,7 +762,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
elif isinstance(item, SFTPAttributes):
item._pack(msg)
else:
- raise Exception('unknown type for %r type %r' % (item, type(item)))
+ raise Exception(
+ 'unknown type for %r type %r' % (item, type(item)))
num = self.request_number
self._expecting[num] = fileobj
self.request_number += 1
@@ -765,7 +783,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
self._lock.acquire()
try:
if num not in self._expecting:
- # might be response for a file that was closed before responses came back
+ # might be response for a file that was closed before
+ # responses came back
self._log(DEBUG, 'Unexpected response #%d' % (num,))
if waitfor is None:
# just doing a single check
@@ -780,7 +799,7 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
if t == CMD_STATUS:
self._convert_status(msg)
return t, msg
- if fileobj is not type(None):
+ if fileobj is not None:
fileobj._async_response(t, msg, num)
if waitfor is None:
# just doing a single check