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

Shane Hathaway shane@cvs.zope.org
Fri, 12 Apr 2002 16:51:13 -0400


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

Modified Files:
      Tag: Zope3-Server-Branch
	PublisherFileSystem.py 
Log Message:
Functioning, tested VFS publication


=== Zope3/lib/python/Zope/Server/VFS/PublisherFileSystem.py 1.1.2.9 => 1.1.2.10 ===
 
 
+
+class NoOutput:
+    """An output stream lookalike that warns you if you try to
+    dump anything into it."""
+
+    def write(self, data):
+        raise RuntimeError, "Not a writable stream"
+
+    def flush(self):
+        pass
+
+    close = flush
+
+
+
 class PublisherFileSystem:
     """Generic Publisher FileSystem implementation.
     """
 
     __implements__ = IReadFileSystem, IWriteFileSystem
 
-    path_module = os.path
-
     def __init__ (self, credentials, request_factory):
         self.credentials = credentials
         self.request_factory = request_factory
@@ -48,7 +61,8 @@
         env['command'] = command
         env['path'] = path
         env['credentials'] = self.credentials
-        request = self.request_factory(StringIO(''), StringIO(), env)
+        # NoOutput avoids creating a black hole.
+        request = self.request_factory(StringIO(''), NoOutput(), env)
         # Note that publish() calls close() on request, which deletes the
         # response from the request, so that we need to keep track of it.
         response = request.getResponse()
@@ -73,7 +87,7 @@
     def isdir(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         path = self.translate(path)
-        return self._execute(path, 'isdir', env)
+        return self._execute(path, 'isdir')
 
 
     def isfile(self, path):
@@ -158,10 +172,11 @@
         return self._execute(path, 'writefile', env)
 
 
-    def check_writable(self, path, mode):
+    def check_writable(self, path):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
         path = self.translate(path)
-        env = {'mode': mode}
+        path, name = os.path.split(path)
+        env = {'name'      : name}
         return self._execute(path, 'check_writable', env)
 
     #
@@ -169,34 +184,12 @@
 
     # utility methods
 
-    def normalize(self, path):
-        # watch for the ever-sneaky '/+' path element
-        path = re.sub('/+', '/', path)
-        # Someone is trying to get lower than the permitted root.
-        # We just ignore it.
+    def translate (self, path):
+        # Normalize
         path = os.path.normpath(path)
         if path.startswith('..'):
+            # Someone is trying to get lower than the permitted root.
+            # We just ignore it.
             path = '/'
         return path
 
-
-    def translate(self, path):
-        """We need to join together three separate path components,
-           and do it safely.  <real_root>/<path>
-           use the operating system's path separator.
-
-           We need to be extremly careful to include the cases where a hacker
-           could attempt to a directory below root!
-        """
-        # Normalize the directory
-        path = os.sep.join(path.split('/'))
-        path = self.normalize(self.path_module.join(path))
-        # Prepare for joining with root
-        if not path.startswith('/'):
-            path = '/' + path
-
-        return path
-
-
-    def __repr__(self):
-        return '<Publisher-FileSystem Root:Data.fs>'