[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/FTP - FTPServerChannel.py:1.1.2.18 PublisherFTPServer.py:1.1.2.4
Stephan Richter
srichter@cbu.edu
Tue, 9 Apr 2002 12:49:48 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Server/FTP
In directory cvs.zope.org:/tmp/cvs-serv15777/Server/FTP
Modified Files:
Tag: Zope3-Server-Branch
FTPServerChannel.py PublisherFTPServer.py
Log Message:
Okay, I cleaned up some stuff.
Could someone look at PublisherFileSystem._execute() and tell me why the
Request looses the response during the publish process! Any ideas?
=== Zope3/lib/python/Zope/Server/FTP/FTPServerChannel.py 1.1.2.17 => 1.1.2.18 ===
+ def _getFileSystem(self):
+ """Open the filesystem using the username and password."""
+ return self.server.openFileSystem(self.username, self.password)
+
+
############################################################
# Implementation methods for interface
# Zope.Server.FTP.IFTPCommandHandler
@@ -110,7 +115,7 @@
def cmd_cdup(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
path = self._generatePath('../')
- if self.server.openFilesystem(self.username).exists(path):
+ if self._getFilesystem().exists(path):
self.cwd = path
self.reply('SUCCESS_250', 'CDUP')
else:
@@ -120,7 +125,7 @@
def cmd_cwd(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
path = self._generatePath(args)
- if self.server.openFilesystem(self.username).exists(path):
+ if self._getFilesystem().exists(path):
self.cwd = path
self.reply('SUCCESS_250', 'CWD')
else:
@@ -135,7 +140,7 @@
path = self._generatePath(args)
try:
- self.server.openFilesystem(self.username).remove(path)
+ self._getFilesystem().remove(path)
except OSError, err:
self.reply('ERR_DELETE_FILE', str(err))
else:
@@ -170,7 +175,7 @@
def cmd_mdtm(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
path = self._generatePath(args)
- if not self.server.openFilesystem(self.username).isfile(path):
+ if not self._getFilesystem().isfile(path):
self.reply('ERR_IS_NOT_FILE', path)
else:
mtime = time.gmtime(
@@ -188,7 +193,7 @@
return
path = self._generatePath(args)
try:
- self.server.openFilesystem(self.username).mkdir(path)
+ self._getFilesystem().mkdir(path)
except OSError, err:
self.reply('ERR_CREATE_DIR', str(err))
else:
@@ -268,7 +273,7 @@
self.reply('CMD_UNKNOWN', 'RETR')
path = self._generatePath(args)
- if not self.server.openFilesystem(self.username).isfile(path):
+ if not self._getFilesystem().isfile(path):
self.reply('ERR_IS_NOT_FILE', path)
return
@@ -285,7 +290,7 @@
outstream = ApplicationXmitStream(cdc)
try:
- self.server.openFilesystem(self.username).readfile(
+ self._getFilesystem().readfile(
path, mode, outstream, start)
cdc.close_when_done()
except OSError, err:
@@ -312,7 +317,7 @@
return
path = self._generatePath(args)
try:
- self.server.openFilesystem(self.username).rmdir(path)
+ self._getFilesystem().rmdir(path)
except OSError, err:
self.reply('ERR_DELETE_DIR', str(err))
else:
@@ -322,7 +327,7 @@
def cmd_rnfr(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
path = self._generatePath(args)
- if self.server.openFilesystem(self.username).exists(path):
+ if self._getFilesystem().exists(path):
self._rnfr = path
self.reply('READY_FOR_DEST')
else:
@@ -335,7 +340,7 @@
if self._rnfr is None:
self.reply('ERR_RENAME')
try:
- self.server.openFilesystem(self.username).rename(self._rnfr, path)
+ self._getFilesystem().rename(self._rnfr, path)
except OSError, err:
self.reply('ERR_RENAME', (self._rnfr, rnto, str(err)))
else:
@@ -346,7 +351,7 @@
def cmd_size(self, args):
'See Zope.Server.FTP.IFTPCommandHandler.IFTPCommandHandler'
path = self._generatePath(args)
- if not self.server.openFilesystem(self.username).isfile(path):
+ if not self._getFilesystem().isfile(path):
self.reply('ERR_NO_FILE', path)
else:
self.reply('FILE_SIZE', self.server.openFilesystem(
@@ -390,8 +395,7 @@
try:
infile = buffer.getfile()
infile.seek(0)
- self.server.openFilesystem(self.username).writefile(path, mode,
- infile, start)
+ self._getFilesystem().writefile(path, mode, infile, start)
except OSError, err:
self.reply('ERR_OPEN_WRITE', str(err))
except IOError, err:
@@ -466,8 +470,7 @@
def listdir (self, path, long=0):
"""returns a string"""
path = self._generatePath(path)
- file_list = self.server.openFilesystem(self.username).listdir(path,
- long)
+ file_list = self._getFilesystem().listdir(path, long)
if long:
file_list = map(longify, file_list)
return '\r\n'.join(file_list) + '\r\n'
=== Zope3/lib/python/Zope/Server/FTP/PublisherFTPServer.py 1.1.2.3 => 1.1.2.4 ===
$Id$
"""
-import asyncore
-import pwd
from FTPServerChannel import FTPServerChannel
from Zope.Server.ServerBase import ServerBase
-from Zope.StartUp.RequestFactory import RequestFactory
from Zope.Server.VFS.PublisherFileSystem import PublisherFileSystem
-from Zope.Server.Authentication.DictionaryAuthentication import \
- DictionaryAuthentication
-from ZODB import DB
-from ZODB.FileStorage import FileStorage
-from Zope.Publisher.VFS.VFSRequest import VFSRequest
-from Zope.App.ZopePublication.VFS.Publication import VFSPublication
-class FileSystemOpener:
+class PublisherFileSystemOpener:
+ """ """
+
+ filesystem_factory = PublisherFileSystem
def __init__(self, root_dir, request_factory):
self.root_dir = root_dir
- self.filesystem_class = PublisherFileSystem
- self.filesystem_class.request_factory = request_factory
+ self.filesystem_factory.request_factory = request_factory
+
+
+ def __call__(self, username, password):
+ return PublisherFileSystem(self.root_dir, username, password)
- def __call__(self, username):
- persona = pwd.getpwnam(username)[2:4]
- return self.filesystem_class(self.root_dir, persona)
class PublisherFTPServer(ServerBase):
@@ -50,55 +44,13 @@
SERVER_IDENT = 'Zope.Server.FTPServer'
- def __init__(self, request_factory, ip, port, task_dispatcher=None,
- adj=None, start=1, hit_log=None, verbose=0, socket_map=None,
- fs_opener=None, auth_source=None):
+ def __init__(self, request_factory, name='FTP', ip, port,
+ task_dispatcher=None, adj=None, start=1, hit_log=None,
+ verbose=0, socket_map=None):
self.request_factory = request_factory
- self.openFilesystem = fs_opener
- self.auth_source = auth_source
+ self.openFilesystem = PublisherFileSystemOpener('/', request_factory)
super(PublisherFTPServer, self).__init__(ip, port, task_dispatcher,
adj, start, hit_log,
verbose, socket_map)
-
-
-if __name__ == '__main__':
- from Zope.Server.TaskThreads import ThreadedTaskDispatcher
- td = ThreadedTaskDispatcher()
- td.setThreadCount(4)
-
- auth_source = DictionaryAuthentication({'root': 'bar'})
- req = RequestFactory(VFSPublication, VFSRequest)
- db = DB(FileStorage('/opt/Zope3-Branches/Zope-3x-Server/Data.fs'))
- req = req.realize(db)
- fs_opener = FileSystemOpener(dir, req)
-
-
- from Zope.App.OFS.Container.Views.VFS.VFSContainerView import \
- VFSContainerView
- from Zope.App.OFS.Container.ContainerTraverser import ContainerTraverser
- from Zope.Publisher.VFS.IVFSPublisher import IVFSPublisher
- from Zope.App.OFS.Container.IContainer import IContainer
- from Zope.App.OFS.Folder.RootFolder import IRootFolder
- from Zope.ComponentArchitecture import provideView, setDefaultViewName
- setDefaultViewName(IContainer, IVFSPublisher, 'vfs')
- provideView(IContainer, 'vfs', IVFSPublisher, VFSContainerView, '')
- provideView(IContainer, '_traverse', IVFSPublisher, ContainerTraverser, '')
-
- from Zope.App.Security.PrincipalRoleManager import \
- principalRoleManager as principal_role_mgr
- from Zope.App.Security.PrincipalRegistry import principalRegistry
-
- principalRegistry.defineDefaultPrincipal('anybody', 'anybody', 'All')
- principal_role_mgr.assignRoleToPrincipal('Manager', 'anybody')
-
- PublisherFTPServer(req, '', 8021, task_dispatcher=td, fs_opener=fs_opener,
- auth_source=auth_source)
- try:
- while 1:
- asyncore.poll(5)
- print 'active channels:', FTPServerChannel.active_channels
- except KeyboardInterrupt:
- print 'shutting down...'
- td.shutdown()