[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/VFS - PublisherFileSystem.py:1.1.2.7 PublisherVFSTask.py:NONE

Stephan Richter srichter@cbu.edu
Wed, 10 Apr 2002 05:30:58 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Server/VFS
In directory cvs.zope.org:/tmp/cvs-serv23463/lib/python/Zope/Server/VFS

Modified Files:
      Tag: Zope3-Server-Branch
	PublisherFileSystem.py 
Removed Files:
      Tag: Zope3-Server-Branch
	PublisherVFSTask.py 
Log Message:
Okay, it finally works! We have a Publisher FTP server again. All the basic
functionalitry is there, from dir listing, file transfer to security.

I punted for now on recognizing file endings, since Jim wants to write a 
proposal for that next week. Also, I did not solve the statistical file
information problem, since this takes some more research.


=== Zope3/lib/python/Zope/Server/VFS/PublisherFileSystem.py 1.1.2.6 => 1.1.2.7 ===
 from IWriteFileSystem import IWriteFileSystem
 
+from Zope.App.Security.PrincipalRegistry import principalRegistry
 from Zope.Publisher.Publish import publish
 from ListProducer import ListProducer
 
@@ -45,6 +46,13 @@
         self.password = password
 
 
+
+    def _create_request(self, env):
+        env['username'] = self.username
+        env['password'] = self.password
+        request = self.request_factory(StringIO(''), StringIO(), env)
+        return request
+
     def _execute(self, path, command, env=None):
 
         if env is None:
@@ -53,15 +61,23 @@
         env['command'] = command
         env['path'] = path
 
-        # XXX integrate security somehow into the request 
-
-        request = self.request_factory(StringIO(''), StringIO(), env)
-        # XXX **** WHY IS THE REQUEST LOOSING ITS RESPONSE DURING PUBLISH? ***
-        resp = request._response
+        request = self._create_request(env)
+        # Note that publish() calls close() on request, which deletes the 
+        # response from the request, so that we need to keep trakc of it.
+        response = request.getResponse()
         publish(request)
-        print resp.getResult()
-        return resp.getResult()
+        return response.getResult()
+
 
+    def _authenticate(self):
+        request = self._create_request({})
+        id = principalRegistry.authenticate(request)
+        if id is None:
+            return 0
+        else:
+            return 1
+        
+        
 
     ############################################################
     # Implementation methods for interface
@@ -70,6 +86,8 @@
     def exists(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         path = self.translate(path)
+        if path == '/':
+            return 1
         path, file = os.path.split(path)
         env = {'name': file}
         return self._execute(path, 'exists', env)
@@ -129,7 +147,7 @@
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
         path = self.translate(path)
         path, name = os.path.split(path)
-        env = {'name': file}
+        env = {'name': name}
         return self._execute(path, 'remove', env)
 
 
@@ -155,11 +173,12 @@
     def writefile(self, path, mode, instream, start=0):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
         path = self.translate(path)
-        env = {'mode'      : mode,
-               'outstream' : outstream,
-               'start'     : start,
-               'end'       : end}
-        return self._execute(path, 'write', env)
+        path, name = os.path.split(path)
+        env = {'name'      : name,
+               'mode'      : mode,
+               'instream'  : instream,
+               'start'     : start}
+        return self._execute(path, 'writefile', env)
 
 
     def check_writable(self, path, mode):
@@ -196,8 +215,8 @@
         path = os.sep.join(path.split('/'))
         path = self.normalize(self.path_module.join(path))
         # Prepare for joining with root
-        if path[0] == '/':
-            path = path[1:]
+        if not path.startswith('/'):
+            path = '/' + path
 
         return path
 

=== Removed File Zope3/lib/python/Zope/Server/VFS/PublisherVFSTask.py ===