SVN: r20988 - in trunk/quixote: . doc

Andrew Kuchling <akuchlin-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 06 Mar 2003 11:15:40 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: akuchlin
Date: 2003-03-06 11:15:39 -0500 (Thu, 06 Mar 2003)
New Revision: 20988

Modified:
   trunk/quixote/doc/static-files.txt
   trunk/quixote/util.py
Log:
Remove caching from StaticFile
Open static files in binary mode


Modified: trunk/quixote/util.py
==============================================================================
--- trunk/quixote/util.py	(original)
+++ trunk/quixote/util.py	2003-03-06 11:15:40.000000000 -0500
@@ -65,12 +65,10 @@
     Wrapper for a static file on the filesystem.
     """
 
-    def __init__(self, path, use_cache=0, follow_symlinks=0,
-                 mime_type=None):
-        """StaticFile(path:string, use_cache:bool, follow_symlinks:bool)
+    def __init__(self, path, follow_symlinks=0, mime_type=None):
+        """StaticFile(path:string, follow_symlinks:bool)
         
         Initialize instance with the absolute path to the file.
-        If 'use_cache' is true, the file's contents will be cached in memory.
         If 'follow_symlinks' is true, symbolic links will be followed.
         'mime_type' specifies the MIME type; if omitted, the MIME
         type will be guessed, defaulting to text/plain.
@@ -85,26 +83,17 @@
             raise errors.TraversalError(private_msg="Path %r is a symlink"
                                         % path)
 
-        self.use_cache = use_cache
-        self.cache = None
-
         # Decide the Content-Type of the file
         self.mime_type = mime_type or \
                 mimetypes.guess_type(os.path.basename(path), strict=0)[0] \
                 or 'text/plain'
 
     def __call__(self, request):
-        # Set the Content-Type for the response and return the file's contents;
-        # use caching if enabled.
+        # Set the Content-Type for the response and return the file's contents.
         request.response.set_header('Content-Type', self.mime_type)
-        if self.cache:
-            contents = self.cache
-        else:
-            fsfile = open(self.path)
-            contents = fsfile.read()
-            fsfile.close()
-            if self.use_cache:
-                self.cache = contents
+        fsfile = open(self.path, 'rb')
+        contents = fsfile.read()
+        fsfile.close()
         return contents
 
 
@@ -185,8 +174,7 @@
                 item = StaticDirectory(item_filepath, self.use_cache,
                         self.list_folder, self.follow_symlinks)
             elif os.path.isfile(item_filepath):
-                item = StaticFile(item_filepath, self.use_cache,
-                        self.follow_symlinks)
+                item = StaticFile(item_filepath, self.follow_symlinks)
             else:
                 raise errors.TraversalError
             if self.use_cache:

Modified: trunk/quixote/doc/static-files.txt
==============================================================================
--- trunk/quixote/doc/static-files.txt	(original)
+++ trunk/quixote/doc/static-files.txt	2003-03-06 11:15:40.000000000 -0500
@@ -8,9 +8,9 @@
 A single file
 -------------
 
-Map an individual filesystem file (possibly a symbolic link) and cache
-its contents. Because 'stylesheet.css' isn't a valid identifier name, we need 
-to use setattr to set it as an attribute of the current module.)
+Map an individual filesystem file (possibly a symbolic link). Because
+'stylesheet.css' isn't a valid identifier name, we need to use setattr
+to set it as an attribute of the current module.)
 
 ::
     this_module = sys.modules[__name__]
@@ -19,7 +19,6 @@
         "stylesheet.css", 
         StaticFile(
             "/htdocs/legacy_app/stylesheet.css",
-            use_cache=1,
             follow_symlinks=1
         )
     )