SVN: r25257 - trunk/quixote

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Tue, 5 Oct 2004 12:29:30 -0400
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2004-10-05 12:28:23 -0400 (Tue, 05 Oct 2004)
New Revision: 25257

Modified:
   trunk/quixote/CHANGES
   trunk/quixote/util.py
Log:
add 'index_filenames' keyword option to StaticDirectory


Modified: trunk/quixote/CHANGES
===================================================================
--- trunk/quixote/CHANGES	2004-10-05 16:03:38 UTC (rev 25256)
+++ trunk/quixote/CHANGES	2004-10-05 16:28:23 UTC (rev 25257)
@@ -15,6 +15,10 @@
 
   * Convert tests to Sancho's utest framework.
 
+  * Simplify propagation of HTTP headers for Medusa server.
+
+  * add 'index_filenames' keyword option to StaticDirectory.
+
   Form2 library:
 
     * Don't parse empty POSTs.
@@ -22,7 +26,9 @@
     * Fix a subtle bug in the multiple select widget.  If nothing
       is selected then the value should be None, not [None].
 
+    * Add Widget.set_title().
 
+
 1.0 (2004-07-01) r24581:
 
   * No changes from 1.0c1.

Modified: trunk/quixote/util.py
===================================================================
--- trunk/quixote/util.py	2004-10-05 16:03:38 UTC (rev 25256)
+++ trunk/quixote/util.py	2004-10-05 16:28:23 UTC (rev 25257)
@@ -196,10 +196,10 @@
     FILE_CLASS = StaticFile
 
     def __init__(self, path, use_cache=0, list_directory=0, follow_symlinks=0,
-                 cache_time=None, file_class=None):
+                 cache_time=None, file_class=None, index_filenames=None):
         """StaticDirectory(path:string, use_cache:bool, list_directory:bool,
                            follow_symlinks:bool, cache_time:int,
-                           file_class=None)
+                           file_class=None, index_filenames:[string])
 
         Initialize instance with the absolute path to the file.
         If 'use_cache' is true, StaticFile instances will be cached in memory.
@@ -208,6 +208,10 @@
 
         Optional parameter cache_time allows setting of Expires header in
         response object (see note for StaticFile for more detail).
+
+        Optional parameter 'index_filenames' specifies a list of
+        filenames to be used as index files in the directory. First
+        file found searching left to right is returned.
         """
 
         # Check that the supplied path is absolute
@@ -224,6 +228,7 @@
             self.file_class = file_class
         else:
             self.file_class = self.FILE_CLASS
+        self.index_filenames = index_filenames
 
     def _q_index(self, request):
         """
@@ -232,6 +237,15 @@
         if the item is a subdirectory, place a '/' after it. If not allowed,
         return a page to that effect.
         """
+        if self.index_filenames:
+            for name in self.index_filenames:
+                try:
+                    obj = self._q_lookup(request, name)
+                except errors.TraversalError:
+                    continue
+                if not isinstance(obj, StaticDirectory) and callable(obj):
+                    return obj(request)
+        # FIXME: this is not a valid HTML document!
         out = StringIO()
         if self.list_directory:
             template = html.htmltext('<a href="%s">%s</a>%s')
@@ -274,10 +288,15 @@
                     item_filepath = os.path.join(self.path, dest)
 
             if os.path.isdir(item_filepath):
+                # avoid passing post 1.0 keyword arguments to subclasses that
+                # may not support them
+                kwargs = {}
+                if self.index_filenames is not None:
+                    kwargs['index_filenames'] = self.index_filenames
                 item = self.__class__(item_filepath, self.use_cache,
                                       self.list_directory,
                                       self.follow_symlinks, self.cache_time,
-                                      self.file_class)
+                                      self.file_class, **kwargs)
             elif os.path.isfile(item_filepath):
                 item = self.file_class(item_filepath, self.follow_symlinks,
                                        cache_time=self.cache_time)