SVN: r20967 - trunk/quixote

Andrew Kuchling <akuchlin-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 05 Mar 2003 13:47:48 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: akuchlin
Date: 2003-03-05 13:47:48 -0500 (Wed, 05 Mar 2003)
New Revision: 20967

Modified:
   trunk/quixote/util.py
Log:
Rename CGIScript.filepath to .path
Check isabs(path) immediately
Fix except statement


Modified: trunk/quixote/util.py
==============================================================================
--- trunk/quixote/util.py	(original)
+++ trunk/quixote/util.py	2003-03-05 13:47:48.000000000 -0500
@@ -220,9 +220,17 @@
     whether a symbolic link should be followed.
     """
 
-    def __init__(self, filepath, use_cache=0, follow_symlinks=0):
-        self.filepath = filepath
-        self.folder, self.filename = os.path.split(filepath)
+    def __init__(self, path, use_cache=0, follow_symlinks=0):
+        """CGIScript(path:string, use_cache:bool, follow_symlinks:bool)
+        
+        Initialize instance with the absolute path to a CGI script.
+        If 'use_cache' is true, the script's content will be cached in memory.
+        If 'follow_symlinks' is true, symbolic links will be followed.
+        """
+        if not os.path.isabs(path):
+            raise ValueError, "Path %r is not absolute" % path
+        self.path = path
+        self.folder, self.filename = os.path.split(path)
         self.use_cache = use_cache
         self.follow_symlinks = follow_symlinks
         self.cache = None
@@ -236,13 +244,12 @@
             code = self.cache
         else:
             try:
-                assert os.path.isabs(self.filepath)
-                assert os.path.isfile(self.filepath)
-                assert not os.path.islink(self.filepath) or self.follow_symlinks
-                scriptfile = open(self.filepath)
-            except AssertionError, IOError:
+                assert os.path.isfile(self.path)
+                assert not os.path.islink(self.path) or self.follow_symlinks
+                scriptfile = open(self.path)
+            except (AssertionError, IOError), exc:
                 raise errors.TraversalError
-            code = compile(scriptfile.read(), self.filepath, 'exec')
+            code = compile(scriptfile.read(), self.path, 'exec')
             scriptfile.close()
             if self.use_cache:
                 self.cache = code