[pyftpdlib] r1237 committed - pep8ify

14 views
Skip to first unread message

pyft...@googlecode.com

unread,
Nov 26, 2013, 9:12:06 AM11/26/13
to pyftpdli...@googlegroups.com
Revision: 1237
Author: g.rodola
Date: Tue Nov 26 14:11:59 2013 UTC
Log: pep8ify
http://code.google.com/p/pyftpdlib/source/detail?r=1237

Modified:
/trunk/pyftpdlib/handlers.py

=======================================
--- /trunk/pyftpdlib/handlers.py Fri Apr 19 01:48:39 2013 UTC
+++ /trunk/pyftpdlib/handlers.py Tue Nov 26 14:11:59 2013 UTC
@@ -54,6 +54,7 @@
from pyftpdlib.authorizers import (DummyAuthorizer, AuthenticationFailed,
AuthorizerError)

+
def _import_sendfile():
# By default attempt to use os.sendfile introduced in Python 3.3:
# http://bugs.python.org/issue10882
@@ -76,103 +77,110 @@


proto_cmds = {
- 'ABOR' : dict(perm=None, auth=True, arg=False,
- help='Syntax: ABOR (abort transfer).'),
- 'ALLO' : dict(perm=None, auth=True, arg=True,
- help='Syntax: ALLO <SP> bytes (noop; allocate
storage).'),
- 'APPE' : dict(perm='a', auth=True, arg=True,
- help='Syntax: APPE <SP> file-name (append data to
file).'),
- 'CDUP' : dict(perm='e', auth=True, arg=False,
- help='Syntax: CDUP (go to parent directory).'),
- 'CWD' : dict(perm='e', auth=True, arg=None,
- help='Syntax: CWD [<SP> dir-name] (change working
directory).'),
- 'DELE' : dict(perm='d', auth=True, arg=True,
- help='Syntax: DELE <SP> file-name (delete file).'),
- 'EPRT' : dict(perm=None, auth=True, arg=True,
- help='Syntax: EPRT <SP> |proto|ip|port| (extended active
mode).'),
- 'EPSV' : dict(perm=None, auth=True, arg=None,
- help='Syntax: EPSV [<SP> proto/"ALL"] (extended passive
mode).'),
- 'FEAT' : dict(perm=None, auth=False, arg=False,
- help='Syntax: FEAT (list all new features supported).'),
- 'HELP' : dict(perm=None, auth=False, arg=None,
- help='Syntax: HELP [<SP> cmd] (show help).'),
- 'LIST' : dict(perm='l', auth=True, arg=None,
- help='Syntax: LIST [<SP> path] (list files).'),
- 'MDTM' : dict(perm='l', auth=True, arg=True,
- help='Syntax: MDTM [<SP> path] (file last modification
time).'),
- 'MLSD' : dict(perm='l', auth=True, arg=None,
- help='Syntax: MLSD [<SP> path] (list directory).'),
- 'MLST' : dict(perm='l', auth=True, arg=None,
- help='Syntax: MLST [<SP> path] (show information about
path).'),
- 'MODE' : dict(perm=None, auth=True, arg=True,
- help='Syntax: MODE <SP> mode (noop; set data transfer
mode).'),
- 'MKD' : dict(perm='m', auth=True, arg=True,
- help='Syntax: MKD <SP> path (create directory).'),
- 'NLST' : dict(perm='l', auth=True, arg=None,
- help='Syntax: NLST [<SP> path] (list path in a compact
form).'),
- 'NOOP' : dict(perm=None, auth=False, arg=False,
- help='Syntax: NOOP (just do nothing).'),
- 'OPTS' : dict(perm=None, auth=True, arg=True,
- help='Syntax: OPTS <SP> cmd [<SP> option] (set option
for command).'),
- 'PASS' : dict(perm=None, auth=False, arg=None,
- help='Syntax: PASS [<SP> password] (set user
password).'),
- 'PASV' : dict(perm=None, auth=True, arg=False,
- help='Syntax: PASV (open passive data connection).'),
- 'PORT' : dict(perm=None, auth=True, arg=True,
- help='Syntax: PORT <sp> h1,h2,h3,h4,p1,p2 (open active
data connection).'),
- 'PWD' : dict(perm=None, auth=True, arg=False,
- help='Syntax: PWD (get current working directory).'),
- 'QUIT' : dict(perm=None, auth=False, arg=False,
- help='Syntax: QUIT (quit current session).'),
- 'REIN' : dict(perm=None, auth=True, arg=False,
- help='Syntax: REIN (flush account).'),
- 'REST' : dict(perm=None, auth=True, arg=True,
- help='Syntax: REST <SP> offset (set file offset).'),
- 'RETR' : dict(perm='r', auth=True, arg=True,
- help='Syntax: RETR <SP> file-name (retrieve a file).'),
- 'RMD' : dict(perm='d', auth=True, arg=True,
- help='Syntax: RMD <SP> dir-name (remove directory).'),
- 'RNFR' : dict(perm='f', auth=True, arg=True,
- help='Syntax: RNFR <SP> file-name (rename (source
name)).'),
- 'RNTO' : dict(perm='f', auth=True, arg=True,
- help='Syntax: RNTO <SP> file-name (rename (destination
name)).'),
- 'SITE' : dict(perm=None, auth=False, arg=True,
- help='Syntax: SITE <SP> site-command (execute SITE
command).'),
- 'SITE HELP' : dict(perm=None, auth=False, arg=None,
- help='Syntax: SITE HELP [<SP> site-command] (show
SITE command help).'),
+ 'ABOR': dict(perm=None, auth=True, arg=False,
+ help='Syntax: ABOR (abort transfer).'),
+ 'ALLO': dict(perm=None, auth=True, arg=True,
+ help='Syntax: ALLO <SP> bytes (noop; allocate storage).'),
+ 'APPE': dict(perm='a', auth=True, arg=True,
+ help='Syntax: APPE <SP> file-name (append data to
file).'),
+ 'CDUP': dict(perm='e', auth=True, arg=False,
+ help='Syntax: CDUP (go to parent directory).'),
+ 'CWD': dict(perm='e', auth=True, arg=None,
+ help='Syntax: CWD [<SP> dir-name] (change working
directory).'),
+ 'DELE': dict(perm='d', auth=True, arg=True,
+ help='Syntax: DELE <SP> file-name (delete file).'),
+ 'EPRT': dict(perm=None, auth=True, arg=True,
+ help='Syntax: EPRT <SP> |proto|ip|port| (extended active
mode).'),
+ 'EPSV': dict(perm=None, auth=True, arg=None,
+ help='Syntax: EPSV [<SP> proto/"ALL"] (extended passive
mode).'),
+ 'FEAT': dict(perm=None, auth=False, arg=False,
+ help='Syntax: FEAT (list all new features supported).'),
+ 'HELP': dict(perm=None, auth=False, arg=None,
+ help='Syntax: HELP [<SP> cmd] (show help).'),
+ 'LIST': dict(perm='l', auth=True, arg=None,
+ help='Syntax: LIST [<SP> path] (list files).'),
+ 'MDTM': dict(perm='l', auth=True, arg=True,
+ help='Syntax: MDTM [<SP> path] (file last modification
time).'),
+ 'MLSD': dict(perm='l', auth=True, arg=None,
+ help='Syntax: MLSD [<SP> path] (list directory).'),
+ 'MLST': dict(perm='l', auth=True, arg=None,
+ help='Syntax: MLST [<SP> path] (show information about
path).'),
+ 'MODE': dict(perm=None, auth=True, arg=True,
+ help='Syntax: MODE <SP> mode (noop; set data transfer
mode).'),
+ 'MKD': dict(perm='m', auth=True, arg=True,
+ help='Syntax: MKD <SP> path (create directory).'),
+ 'NLST': dict(perm='l', auth=True, arg=None,
+ help='Syntax: NLST [<SP> path] (list path in a compact
form).'),
+ 'NOOP': dict(perm=None, auth=False, arg=False,
+ help='Syntax: NOOP (just do nothing).'),
+ 'OPTS': dict(perm=None, auth=True, arg=True,
+ help='Syntax: OPTS <SP> cmd [<SP> option] (set option
for '
+ 'command).'),
+ 'PASS': dict(perm=None, auth=False, arg=None,
+ help='Syntax: PASS [<SP> password] (set user password).'),
+ 'PASV': dict(perm=None, auth=True, arg=False,
+ help='Syntax: PASV (open passive data connection).'),
+ 'PORT': dict(perm=None, auth=True, arg=True,
+ help='Syntax: PORT <sp> h1,h2,h3,h4,p1,p2 (open active
data '
+ 'connection).'),
+ 'PWD': dict(perm=None, auth=True, arg=False,
+ help='Syntax: PWD (get current working directory).'),
+ 'QUIT': dict(perm=None, auth=False, arg=False,
+ help='Syntax: QUIT (quit current session).'),
+ 'REIN': dict(perm=None, auth=True, arg=False,
+ help='Syntax: REIN (flush account).'),
+ 'REST': dict(perm=None, auth=True, arg=True,
+ help='Syntax: REST <SP> offset (set file offset).'),
+ 'RETR': dict(perm='r', auth=True, arg=True,
+ help='Syntax: RETR <SP> file-name (retrieve a file).'),
+ 'RMD': dict(perm='d', auth=True, arg=True,
+ help='Syntax: RMD <SP> dir-name (remove directory).'),
+ 'RNFR': dict(perm='f', auth=True, arg=True,
+ help='Syntax: RNFR <SP> file-name (rename (source
name)).'),
+ 'RNTO': dict(perm='f', auth=True, arg=True,
+ help='Syntax: RNTO <SP> file-name (rename (destination
name)).'),
+ 'SITE': dict(perm=None, auth=False, arg=True,
+ help='Syntax: SITE <SP> site-command (execute SITE
command).'),
+ 'SITE HELP': dict(perm=None, auth=False, arg=None,
+ help='Syntax: SITE HELP [<SP> site-command] (show
SITE '
+ 'command help).'),
'SITE CHMOD': dict(perm='M', auth=True, arg=True,
- help='Syntax: SITE CHMOD <SP> mode path (change
file mode).'),
- 'SIZE' : dict(perm='l', auth=True, arg=True,
- help='Syntax: SIZE <SP> file-name (get file size).'),
- 'STAT' : dict(perm='l', auth=False, arg=None,
- help='Syntax: STAT [<SP> path name] (server stats [list
files]).'),
- 'STOR' : dict(perm='w', auth=True, arg=True,
- help='Syntax: STOR <SP> file-name (store a file).'),
- 'STOU' : dict(perm='w', auth=True, arg=None,
- help='Syntax: STOU [<SP> file-name] (store a file with a
unique name).'),
- 'STRU' : dict(perm=None, auth=True, arg=True,
- help='Syntax: STRU <SP> type (noop; set file
structure).'),
- 'SYST' : dict(perm=None, auth=False, arg=False,
- help='Syntax: SYST (get operating system type).'),
- 'TYPE' : dict(perm=None, auth=True, arg=True,
- help='Syntax: TYPE <SP> [A | I] (set transfer type).'),
- 'USER' : dict(perm=None, auth=False, arg=True,
- help='Syntax: USER <SP> user-name (set username).'),
- 'XCUP' : dict(perm='e', auth=True, arg=False,
- help='Syntax: XCUP (obsolete; go to parent directory).'),
- 'XCWD' : dict(perm='e', auth=True, arg=None,
- help='Syntax: XCWD [<SP> dir-name] (obsolete; change
directory).'),
- 'XMKD' : dict(perm='m', auth=True, arg=True,
- help='Syntax: XMKD <SP> dir-name (obsolete; create
directory).'),
- 'XPWD' : dict(perm=None, auth=True, arg=False,
- help='Syntax: XPWD (obsolete; get current dir).'),
- 'XRMD' : dict(perm='d', auth=True, arg=True,
- help='Syntax: XRMD <SP> dir-name (obsolete; remove
directory).'),
- }
+ help='Syntax: SITE CHMOD <SP> mode path (change
file '
+ 'mode).'),
+ 'SIZE': dict(perm='l', auth=True, arg=True,
+ help='Syntax: SIZE <SP> file-name (get file size).'),
+ 'STAT': dict(perm='l', auth=False, arg=None,
+ help='Syntax: STAT [<SP> path name] (server stats [list '
+ 'files]).'),
+ 'STOR': dict(perm='w', auth=True, arg=True,
+ help='Syntax: STOR <SP> file-name (store a file).'),
+ 'STOU': dict(perm='w', auth=True, arg=None,
+ help='Syntax: STOU [<SP> file-name] (store a file with a '
+ 'unique name).'),
+ 'STRU': dict(perm=None, auth=True, arg=True,
+ help='Syntax: STRU <SP> type (noop; set file
structure).'),
+ 'SYST': dict(perm=None, auth=False, arg=False,
+ help='Syntax: SYST (get operating system type).'),
+ 'TYPE': dict(perm=None, auth=True, arg=True,
+ help='Syntax: TYPE <SP> [A | I] (set transfer type).'),
+ 'USER': dict(perm=None, auth=False, arg=True,
+ help='Syntax: USER <SP> user-name (set username).'),
+ 'XCUP': dict(perm='e', auth=True, arg=False,
+ help='Syntax: XCUP (obsolete; go to parent directory).'),
+ 'XCWD': dict(perm='e', auth=True, arg=None,
+ help='Syntax: XCWD [<SP> dir-name] (obsolete; change
directory).'),
+ 'XMKD': dict(perm='m', auth=True, arg=True,
+ help='Syntax: XMKD <SP> dir-name (obsolete; create
directory).'),
+ 'XPWD': dict(perm=None, auth=True, arg=False,
+ help='Syntax: XPWD (obsolete; get current dir).'),
+ 'XRMD': dict(perm='d', auth=True, arg=True,
+ help='Syntax: XRMD <SP> dir-name (obsolete; remove
directory).'),
+}

if not hasattr(os, 'chmod'):
del proto_cmds['SITE CHMOD']

+
def _strerror(err):
if isinstance(err, EnvironmentError):
try:
@@ -185,6 +193,7 @@
else:
return str(err)

+
def _support_hybrid_ipv6():
"""Return True if it is possible to use hybrid IPv6/IPv4 sockets
on this platform.
@@ -206,6 +215,7 @@

SUPPORTS_HYBRID_IPV6 = _support_hybrid_ipv6()

+
class _FileReadWriteError(OSError):
"""Exception raised when reading or writing a file during a
transfer."""

@@ -307,7 +317,7 @@
# The format of 227 response in not standardized.
# This is the most expected:
self.cmd_channel.respond('227 Entering passive mode
(%s,%d,%d).' % (
- ip.replace('.', ','), port // 256, port %
256))
+ ip.replace('.', ','), port // 256, port % 256))
else:
self.cmd_channel.respond('229 Entering extended passive mode '
'(|||%d|).' % port)
@@ -333,14 +343,14 @@
except socket.error:
pass
msg = '425 Rejected data connection from foreign
address %s:%s.' \
- %(addr[0], addr[1])
+ % (addr[0], addr[1])
self.cmd_channel.respond_w_warning(msg)
# do not close listening socket: it couldn't be client's
blame
return
else:
# site-to-site FTP allowed
msg = 'Established data connection with foreign
address %s:%s.'\
- % (addr[0], addr[1])
+ % (addr[0], addr[1])
self.cmd_channel.log(msg, logfun=logger.warning)
# Immediately close the current channel (we accept only one
# connection at time) and avoid running out of max connections
@@ -469,7 +479,8 @@
if self.cmd_channel.connected:
msg = "Can't connect to specified address."
self.cmd_channel.respond("425 " + msg)
- self.cmd_channel.log_cmd(self._cmd, self._normalized_addr,
425, msg)
+ self.cmd_channel.log_cmd(
+ self._cmd, self._normalized_addr, 425, msg)

def handle_error(self):
"""Called to handle any uncaught exceptions."""
@@ -569,8 +580,8 @@
addr = "%s:%s" % self.socket.getpeername()[:2]
except socket.error:
addr = None
- status = [self.__class__.__module__+ "." + self.__class__.__name__]
- status.append("(addr=%s, user=%r, receive=%r, file=%r)" \
+ status = [self.__class__.__module__ + "." +
self.__class__.__name__]
+ status.append("(addr=%s, user=%r, receive=%r, file=%r)"
% (addr, self.cmd_channel.username or '',
self.receive, getattr(self.file_obj, 'name', '')))
return '<%s at %#x>' % (' '.join(status), id(self))
@@ -578,9 +589,9 @@
__str__ = __repr__

def _use_sendfile(self, producer):
- return self.cmd_channel.use_sendfile \
- and isinstance(producer, FileProducer) \
- and producer.type == 'i'
+ return (Uself.cmd_channel.use_sendfile
+ and isinstance(producer, FileProducer)
+ and producer.type == 'i')

def push(self, data):
self._initialized = True
@@ -697,7 +708,7 @@
if p is None:
if not self.ac_out_buffer:
self.producer_fifo.pop()
- #self.close()
+ # self.close()
self.handle_close()
return
elif isinstance(p, str):
@@ -723,7 +734,7 @@
self.tot_bytes_received += len(chunk)
if not chunk:
self.transfer_finished = True
- #self.close() # <-- asyncore.recv() already do that...
+ # self.close() # <-- asyncore.recv() already do that...
return
if self._data_wrapper is not None:
chunk = self._data_wrapper(chunk)
@@ -802,7 +813,7 @@
self._resp = ("226 Transfer complete.", logger.debug)
else:
tot_bytes = self.get_transmitted_bytes()
- self._resp = ("426 Transfer aborted; %d bytes
transmitted." \
+ self._resp = ("426 Transfer aborted; %d bytes
transmitted."
% tot_bytes, logger.debug)
finally:
self.close()
@@ -850,6 +861,7 @@
pass
else:
class _AsyncChatNewStyle(object, AsyncChat):
+
def __init__(self, *args, **kwargs):
super(object, self).__init__(*args, **kwargs) # bypass object

@@ -931,7 +943,7 @@
self.del_channel()
self._cancel_throttler()
self._throttler = self.ioloop.call_later(sleepfor, unsleep,
-
_errback=self.handle_error)
+
_errback=self.handle_error)
self._timenext = now + 1

def close(self):
@@ -1149,7 +1161,7 @@
self._rnfr = None
self._idler = None
self._log_debug =
logging.getLogger('pyftpdlib').getEffectiveLevel() \
- <= logging.DEBUG
+ <= logging.DEBUG

if os.name == 'posix':
self._current_facts.append('unique')
@@ -1197,7 +1209,7 @@
else: # python < 2.5
ip, port = self.socket.getsockname()[:2]
self._af = socket.getaddrinfo(ip, port, socket.AF_UNSPEC,
- socket.SOCK_STREAM)[0][0]
+ socket.SOCK_STREAM)[0][0]

# try to handle urgent data inline
try:
@@ -1223,7 +1235,7 @@

_errback=self.handle_error)

def __repr__(self):
- status = [self.__class__.__module__+ "." + self.__class__.__name__]
+ status = [self.__class__.__module__ + "." +
self.__class__.__name__]
status.append("(addr=%s:%s, user=%r)" % (self.remote_ip,
self.remote_port, self.username or ''))
return '<%s at %#x>' % (' '.join(status), id(self))
@@ -1317,18 +1329,18 @@
self._in_buffer_len = 0

cmd = line.split(' ')[0].upper()
- arg = line[len(cmd)+1:]
+ arg = line[len(cmd) + 1:]
try:
self.pre_process_command(line, cmd, arg)
except UnicodeEncodeError:
- self.respond("501 can't decode path (server filesystem
encoding " \
+ self.respond("501 can't decode path (server filesystem
encoding "
"is %s)" % sys.getfilesystemencoding())

def pre_process_command(self, line, cmd, arg):
kwargs = {}
if cmd == "SITE" and arg:
cmd = "SITE %s" % arg.split(' ')[0].upper()
- arg = line[len(cmd)+1:]
+ arg = line[len(cmd) + 1:]

if cmd != 'PASS':
self.logline("<- %s" % line)
@@ -1409,7 +1421,7 @@

if not self.fs.validpath(arg):
line = self.fs.fs2ftp(arg)
- msg = '"%s" points to a path which is outside ' \
+ msg = '"%s" points to a path which is outside '
"the user's root directory" % line
self.respond("550 %s." % msg)
self.log_cmd(cmd, arg, 550, msg)
@@ -1569,7 +1581,7 @@
"""
# Close accepting DTP only. By closing ActiveDTP DTPHandler
# would receive a closed socket object.
- #self._shutdown_connecting_dtp()
+ # self._shutdown_connecting_dtp()
if self._dtp_acceptor is not None:
self._dtp_acceptor.close()
self._dtp_acceptor = None
@@ -1792,12 +1804,10 @@
number of bytes transmitted.
"""
line = '%s %s completed=%s bytes=%s seconds=%s' % \
- (cmd, filename, completed and 1 or 0, bytes, elapsed)
+ (cmd, filename, completed and 1 or 0, bytes, elapsed)
self.log(line)

-
# --- connection
-
def _make_eport(self, ip, port):
"""Establish an active data channel with remote client which
issued a PORT or EPRT command.
@@ -1818,7 +1828,7 @@
remote_ip = remote_ip[7:]
if not self.permit_foreign_addresses and ip != remote_ip:
msg = "501 Rejected data connection to foreign address %s:%s."
\
- % (ip, port)
+ % (ip, port)
self.respond_w_warning(msg)
return

@@ -2087,7 +2097,7 @@
perms = self.authorizer.get_perms(self.username)
try:
iterator = self.run_as_current_user(self.fs.format_mlsx,
basedir,
- [basename], perms, self._current_facts,
ignore_err=False)
+ [basename], perms,
self._current_facts, ignore_err=False)
data = b('').join(iterator)
except (OSError, FilesystemError):
err = sys.exc_info()[1]
@@ -2122,7 +2132,7 @@
else:
perms = self.authorizer.get_perms(self.username)
iterator = self.fs.format_mlsx(path, listing, perms,
- self._current_facts)
+ self._current_facts)
producer = BufferedIteratorProducer(iterator)
self.push_dtp_data(producer, isproducer=True, cmd="MLSD")
return path
@@ -2188,7 +2198,7 @@
except (EnvironmentError, FilesystemError):
err = sys.exc_info()[1]
why = _strerror(err)
- self.respond('550 %s.' %why)
+ self.respond('550 %s.' % why)
return

if rest_pos:
@@ -2224,7 +2234,6 @@
self._in_dtp_queue = (fd, cmd)
return file

-
def ftp_STOU(self, line):
"""Store a file on the server with a unique name.
On success return the file path, else None.
@@ -2313,8 +2322,9 @@
def ftp_ABOR(self, line):
"""Abort the current data transfer."""
# ABOR received while no data channel exists
- if (self._dtp_acceptor is None) and (self._dtp_connector is None) \
- and (self.data_channel is None):
+ if (self._dtp_acceptor is None
+ and self._dtp_connector is None
+ and self.data_channel is None):
self.respond("225 No transfer to abort.")
return
else:
@@ -2343,9 +2353,7 @@
resp = "225 ABOR command successful; data channel
closed."
self.respond(resp)

-
# --- authentication
-
def ftp_USER(self, line):
"""Set the username for the current session."""
# RFC-959 specifies a 530 response to the USER command if the
@@ -2416,9 +2424,9 @@
raise ValueError('type(home) != text')
else:
warnings.warn(
- '%s.get_home_dir returned a non-unicode string;
now ' \
+ '%s.get_home_dir returned a non-unicode string;
now '
'casting to unicode' %
self.authorizer.__class__.__name__,
- RuntimeWarning)
+ RuntimeWarning)
home = home.decode('utf8')

if len(msg_login) <= 75:
@@ -2448,9 +2456,7 @@
# code to be given in this case, but this is wrong...
self.respond("230 Ready for new user.")

-
# --- filesystem operations
-
def ftp_PWD(self, line):
"""Return the name of the current working directory to the
client."""
# The 257 response is supposed to include the directory
@@ -2514,7 +2520,7 @@
line = self.fs.fs2ftp(path)
if self._current_type == 'a':
why = "SIZE not allowed in ASCII mode"
- self.respond("550 %s." %why)
+ self.respond("550 %s." % why)
return
if not self.fs.isfile(self.fs.realpath(path)):
why = "%s is not retrievable" % line
@@ -2568,7 +2574,7 @@
except (OSError, FilesystemError):
err = sys.exc_info()[1]
why = _strerror(err)
- self.respond('550 %s.' %why)
+ self.respond('550 %s.' % why)
else:
# The 257 response is supposed to include the directory
# name and in case it contains embedded double-quotes
@@ -2638,9 +2644,7 @@
self.respond("250 Renaming ok.")
return (src, path)

-
# --- others
-
def ftp_TYPE(self, line):
"""Set current type data type to binary/ascii"""
type = line.upper().replace(' ', '')
@@ -2739,7 +2743,7 @@
except (OSError, FilesystemError):
err = sys.exc_info()[1]
why = _strerror(err)
- self.respond('550 %s.' %why)
+ self.respond('550 %s.' % why)
else:
self.push('213-Status of "%s":\r\n' % line)
self.push_with_producer(BufferedIteratorProducer(iterator))
@@ -2749,7 +2753,7 @@
def ftp_FEAT(self, line):
"""List all new features supported as defined in RFC-2398."""
features = set(['UTF8', 'TVFS'])
- features.update([feat for feat in ('EPRT', 'EPSV', 'MDTM', 'SIZE')
\
+ features.update([feat for feat in ('EPRT', 'EPSV', 'MDTM', 'SIZE')
if feat in self.proto_cmds])
features.update(self._extra_feats)
if 'MLST' in self.proto_cmds or 'MLSD' in self.proto_cmds:
@@ -2820,7 +2824,8 @@
# provide a compact list of recognized commands
def formatted_help():
cmds = []
- keys = [x for x in self.proto_cmds.keys() if not
x.startswith('SITE ')]
+ keys = [x for x in self.proto_cmds.keys()
+ if not x.startswith('SITE ')]
keys.sort()
while keys:
elems = tuple((keys[0:8]))
@@ -2907,11 +2912,9 @@
return self.ftp_RMD(line)


-
# ===================================================================
# --- FTP over SSL
# ===================================================================
-
# requires PyOpenSSL - http://pypi.python.org/pypi/pyOpenSSL
try:
from OpenSSL import SSL
@@ -2926,8 +2929,7 @@
help='Syntax: PBSZ <SP> 0 (negotiate TLS buffer).'),
'PROT': dict(perm=None, auth=False, arg=True,
help='Syntax: PROT <SP> [C|P] (set up un/secure data
channel).'),
- })
-
+ })

class SSLConnection(_AsyncChatNewStyle):
"""An AsyncChat subclass supporting TLS/SSL."""
@@ -3139,7 +3141,6 @@
self._ssl_closing = False
super(SSLConnection, self).close()

-
class TLS_DTPHandler(SSLConnection, DTPHandler):
"""A DTPHandler subclass supporting TLS/SSL."""

@@ -3160,7 +3161,6 @@
self.cmd_channel.log_cmd("PROT", "P", 522, "SSL handshake
failed.")
self.close()

-
class TLS_FTPHandler(SSLConnection, FTPHandler):
"""A FTPHandler subclass supporting TLS/SSL.
Implements AUTH, PBSZ and PROT commands (RFC-2228 and RFC-4217).
@@ -3286,7 +3286,7 @@
# From RFC-4217: "As the SSL/TLS protocols self-negotiate
# their levels, there is no need to distinguish between SSL
# and TLS in the application layer".
- self.respond('234 AUTH %s successful.' %arg)
+ self.respond('234 AUTH %s successful.' % arg)
self.secure_connection(self.ssl_context)
else:
self.respond("502 Unrecognized encryption type (use TLS or
SSL).")
@@ -3297,7 +3297,8 @@
Any other value is accepted but ignored.
"""
if not isinstance(self.socket, SSL.Connection):
- self.respond("503 PBSZ not allowed on insecure control
connection.")
+ self.respond(
+ "503 PBSZ not allowed on insecure control connection.")
else:
self.respond('200 PBSZ=0 successful.')
self._pbsz = True
@@ -3306,7 +3307,8 @@
"""Setup un/secure data channel."""
arg = line.upper()
if not isinstance(self.socket, SSL.Connection):
- self.respond("503 PROT not allowed on insecure control
connection.")
+ self.respond(
+ "503 PROT not allowed on insecure control connection.")
elif not self._pbsz:
self.respond("503 You must issue the PBSZ command prior to
PROT.")
elif arg == 'C':
@@ -3316,6 +3318,6 @@
self.respond('200 Protection set to Private')
self._prot = True
elif arg in ('S', 'E'):
- self.respond('521 PROT %s unsupported (use C or P).' %arg)
+ self.respond('521 PROT %s unsupported (use C or P).' % arg)
else:
self.respond("502 Unrecognized PROT type (use C or P).")
Reply all
Reply to author
Forward
0 new messages