[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/FTP - FTPServerChannel.py:1.1.4.2 OSEmulators.py:1.1.4.3
Shane Hathaway
shane@cvs.zope.org
Wed, 24 Apr 2002 16:56:54 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Server/FTP
In directory cvs.zope.org:/tmp/cvs-serv5777/FTP
Modified Files:
Tag: Zope-3x-branch
FTPServerChannel.py OSEmulators.py
Log Message:
- Made the FTP LIST command work in a platform independent manner. We now
expect the ST_UID and ST_GID fields in the tuples returned by listdir()
to contain a string if the file list should show the user name of the
owner.
- Made sure the FTP data connection gets closed when the control connection
closes.
- testFTPServer.execute() now only returns the first line of a multi-line
result.
=== Zope3/lib/python/Zope/Server/FTP/FTPServerChannel.py 1.1.4.1 => 1.1.4.2 ===
from Zope.Server.LineReceiver.LineServerChannel import LineServerChannel
from FTPStatusMessages import status_msgs
-from OSEmulators import unix_longify as longify
+from OSEmulators import ls_longify
from IFTPCommandHandler import IFTPCommandHandler
from PassiveAcceptor import PassiveAcceptor
@@ -472,13 +472,13 @@
return self.passive_acceptor
- def listdir (self, path, long=0):
+ def listdir(self, path, long=0):
"""returns a string"""
path = self._generatePath(path)
file_list = self._getFilesystem().listdir(path, long)
if long:
- file_list = map(longify, file_list)
- return '\r\n'.join(file_list) + '\r\n'
+ file_list = map(ls_longify, file_list)
+ return ''.join(map(lambda line: line + '\r\n', file_list))
def getDirectoryList(self, args, long=0):
@@ -529,4 +529,13 @@
self.client_dc = None
if reply_args:
self.reply(*reply_args)
+
+
+ def close(self):
+ LineServerChannel.close(self)
+ # Make sure the client DC gets closed too.
+ cdc = self.client_dc
+ if cdc is not None:
+ self.client_dc = None
+ cdc.close()
=== Zope3/lib/python/Zope/Server/FTP/OSEmulators.py 1.1.4.2 => 1.1.4.3 ===
-def unix_longify((file, stat_info)):
- # for now, only pay attention to the lower bits
+def ls_longify((filename, stat_info)):
+ """Formats a directory entry similarly to the 'ls' command.
+ """
- import pwd, grp
+ # Note that we expect a little deviance from the result of os.stat():
+ # we expect the ST_UID and ST_GID fields to contain user IDs.
+ username = str(stat_info[stat.ST_UID])[:8]
+ grpname = str(stat_info[stat.ST_GID])[:8]
- try: username = pwd.getpwuid(int(stat_info[stat.ST_UID]))[0]
- except: username = stat_info[stat.ST_UID]
-
- try: grpname = grp.getgrgid(int(stat_info[stat.ST_GID]))[0]
- except: grpname = stat_info[stat.ST_GID]
-
-
- mode = ('%o' % stat_info[stat.ST_MODE])[-3:]
- mode = ''.join(map (lambda x: mode_table[x], mode))
+ mode_octal = ('%o' % stat_info[stat.ST_MODE])[-3:]
+ mode = ''.join(map(mode_table.get, mode_octal))
if stat.S_ISDIR (stat_info[stat.ST_MODE]):
dirchar = 'd'
else:
@@ -61,12 +58,12 @@
grpname,
stat_info[stat.ST_SIZE],
date,
- file
+ filename
)
def ls_date (now, t):
- """Emulate the unix 'ls' command's date field. it has two formats
+ """Emulate the 'ls' command's date field. it has two formats
- if the date is more than 180 days in the past, then it's like
this: Oct 19 1995 otherwise, it looks like this: Oct 19 17:33
"""