SVN: r21074 - trunk/quixote
Andrew Kuchling <akuchlin-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 12 Mar 2003 09:44:16 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: akuchlin
Date: 2003-03-12 09:44:16 -0500 (Wed, 12 Mar 2003)
New Revision: 21074
Modified:
trunk/quixote/ACKS
trunk/quixote/CHANGES
trunk/quixote/util.py
Log:
Support setting and guessing the file's encoding
Modified: trunk/quixote/util.py
==============================================================================
--- trunk/quixote/util.py (original)
+++ trunk/quixote/util.py 2003-03-12 09:44:16.000000000 -0500
@@ -65,13 +65,15 @@
Wrapper for a static file on the filesystem.
"""
- def __init__(self, path, follow_symlinks=0, mime_type=None):
+ def __init__(self, path, follow_symlinks=0,
+ mime_type=None, encoding=None):
"""StaticFile(path:string, follow_symlinks:bool)
- Initialize instance with the absolute path to the file.
- 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.
+ Initialize instance with the absolute path to the file. If
+ 'follow_symlinks' is true, symbolic links will be followed.
+ 'mime_type' specifies the MIME type, and 'encoding' the
+ encoding; if omitted, the MIME type will be guessed,
+ defaulting to text/plain.
"""
# Check that the supplied path is absolute and (if a symbolic link) may
@@ -84,13 +86,16 @@
% path)
# 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'
+ guess_mime, guess_enc = mimetypes.guess_type(os.path.basename(path),
+ strict=0)
+ self.mime_type = mime_type or guess_mime or 'text/plain'
+ self.encoding = encoding or guess_enc or None
def __call__(self, request):
# Set the Content-Type for the response and return the file's contents.
request.response.set_content_type(self.mime_type)
+ if self.encoding:
+ request.response.set_header("Content-Encoding", self.encoding)
fsfile = open(self.path, 'rb')
contents = fsfile.read()
fsfile.close()
Modified: trunk/quixote/CHANGES
==============================================================================
--- trunk/quixote/CHANGES (original)
+++ trunk/quixote/CHANGES 2003-03-12 09:44:16.000000000 -0500
@@ -5,6 +5,9 @@
* StaticDirectory's list_folder argument renamed to list_directory.
+ * StaticFile now supports the HTTP encoding for files.
+ (Absence of this feature noted by Jim Dukarm.)
+
0.6b3 (7 Mar 2003):
Modified: trunk/quixote/ACKS
==============================================================================
--- trunk/quixote/ACKS (original)
+++ trunk/quixote/ACKS 2003-03-12 09:44:16.000000000 -0500
@@ -14,6 +14,7 @@
Herman Cuppens
Toby Dickenson
Ray Drew
+Jim Dukarm
Quinn Dunkan
Robin Dunn (original author of fcgi.py)
Jon Dyte