[Python-Dev] Proposed addition to ftplib
Jeff Epler
jepler at unpythonic.net
Tue Feb 3 20:24:58 EST 2004
Jordan,
It's always good to see people contributing to Python. It's good to
have you here.
I have two suggestions about your submission. Well, three. Zeroeth,
take the advice of another respondant and use the Sourceforge patch
submission interface.
First, when contributing patches to Python, it's most customary to use
the Unix tools 'diff' and 'patch' to generate a listing of the changes
you made. (If you're a Windows user, perhaps someone can be more
helpful than the FAQ entry at
http://www.python.org/dev/devfaq.html#how-to-make-a-patch)
Here's the patch for your change:
--- /usr/lib/python2.2/ftplib.py 2003-02-24 18:24:16.000000000 -0600
+++ ./ftplib.py 2004-02-03 19:03:07.000000000 -0600
@@ -469,6 +469,10 @@
cmd = cmd + (' ' + arg)
self.retrlines(cmd, func)
+ def chmod(self, mode, file):
+ '''Change file permissions for a file on the remote server.'''
+ return self.voidcmd('SITE CHMOD ' + mode + ' ' + file)
+
def rename(self, fromname, toname):
'''Rename a file.'''
resp = self.sendcmd('RNFR ' + fromname)
Second, and this may seem foolish because of how little I know about the
FTP protocol, I wonder if it makes sense to make the SITE command a
method, and have chmod use it. This patch uses that idea, and
makes it even easier for you to use more SITE commands easily (well, if
it works):
>>> f = ftplib.FTP(...)
>>> f.login(...)
>>> print f.site('help')
214-The following SITE commands are recognized.
UMASK GROUPS
IDLE CHECKMETHOD
CHMOD ALIAS CHECKSUM
HELP CDPATH
214 Direct comments to root at localhost.
>>> f.site('chmod', '644', '/etc/shadow')
ftplib.error_perm: 550 /etc/shadow: Operation not permitted.
--- /usr/lib/python2.2/ftplib.py 2003-02-24 18:24:16.000000000 -0600
+++ ./ftplib.py 2004-02-03 19:17:37.000000000 -0600
@@ -469,6 +469,15 @@
cmd = cmd + (' ' + arg)
self.retrlines(cmd, func)
+ def site(self, command, *args):
+ '''Perform a SITE command with the given arguments.'''
+ args = " ".join(('SITE', command.upper()) + args)
+ return self.sendcmd(args)
+
+ def chmod(self, mode, filename):
+ '''Change file permissions for a file on the remote server.'''
+ return self.site('chmod', mode, filename)
+
def rename(self, fromname, toname):
'''Rename a file.'''
resp = self.sendcmd('RNFR ' + fromname)
Jeff
More information about the Python-Dev
mailing list