[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/VFS - OSFileSystem.py:1.1.2.14

Shane Hathaway shane@cvs.zope.org
Fri, 12 Apr 2002 15:02:25 -0400


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

Modified Files:
      Tag: Zope3-Server-Branch
	OSFileSystem.py 
Log Message:
Simplified away the path_module attribute and simplified path checking


=== Zope3/lib/python/Zope/Server/VFS/OSFileSystem.py 1.1.2.13 => 1.1.2.14 ===
     __implements__ = IPosixFileSystem
 
-    path_module = os.path
-
     copy_bytes = 65536
 
 
@@ -82,19 +80,19 @@
     def exists(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         p = self.translate(path)
-        return self.path_module.exists(p)
+        return os.path.exists(p)
 
 
     def isdir(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         p = self.translate(path)
-        return self.path_module.isdir(p)
+        return os.path.isdir(p)
 
 
     def isfile(self, path):
         'See Zope.Server.VFS.IReadFileSystem.IReadFileSystem'
         p = self.translate(path)
-        return self.path_module.isfile(p)
+        return os.path.isfile(p)
 
 
     def listdir(self, path, with_stats=0, pattern='*'):
@@ -111,7 +109,7 @@
         else:
             result = []
             for file in ld:
-                path = self.path_module.join(p, file)
+                path = os.path.join(p, file)
                 stat = safe_stat(path)
                 if stat is not None:
                     result.append((file, stat))
@@ -182,7 +180,7 @@
                 break
             outstream.write(data)
 
-    def check_writable(self, path, mode):
+    def check_writable(self, path):
         'See Zope.Server.VFS.IWriteFileSystem.IWriteFileSystem'
         p = self.translate(path)
         if os.path.exists(p):
@@ -202,11 +200,13 @@
 
     def normalize (self, path):
         # watch for the ever-sneaky '/+' path element
+        # XXX It is unclear why "/+" is dangerous.  It is definitely
+        # unexpected.
         path = re.sub('/+', '/', path)
-        # Someone is trying to get lower than the permitted root.
-        # We just ignore it.
-        path = self.path_module.normpath(path)
-        if path.startswith('..') or path.startswith('../'):
+        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
 
@@ -220,18 +220,16 @@
            could attempt to a directory below root!
         """
         # Normalize the directory
-        path = os.sep.join(path.split('/'))
-        path = self.normalize(self.path_module.join(path))
+        path = self.normalize(path)
         # Prepare for joining with root
-        if path[0] == '/':
+        while path.startswith('/'):
             path = path[1:]
         # Join path with root
-        path = self.path_module.join(self.root, path)
-        return path
+        return os.path.join(self.root, path)
 
 
     def __repr__ (self):
-        return '<Unix-Style Root:%s>' % self.root
+        return '<OSFileSystem, root=%s>' % self.root