# HG changeset patch
# User paulb
# Date 1137369260 0
# Node ID 3ff6598f2d943e1caf5bb07e53cc0f8ada49172e
# Parent 57138519c16d4c620ca00132cbbc6bf92312abe4
[project @ 2006-01-15 23:54:20 by paulb]
Added content type parameters to DirectoryResource.
diff -r 57138519c16d -r 3ff6598f2d94 docs/directory-resource.html
--- a/docs/directory-resource.html Sun Jan 15 23:54:16 2006 +0000
+++ b/docs/directory-resource.html Sun Jan 15 23:54:20 2006 +0000
@@ -29,11 +29,11 @@
a file type indicating that the contents of the file are HTML (or some
variant thereof). Instances of DirectoryResource
employ
a special registry mapping filename extensions to file types in order
-to automate the process of deciding what type a file might be.
Using the media_types
parameter (see below), one might choose to serve all files whose names have the .html
extension with the HTML file (or content) type. This would be expressed with the following dictionary:
{"html" : "text/html"}
Note that the .
-character is omitted from the filename extension and that the file type
-(or more correctly, the media type) does not include character set
-information.
The API documentation for the DirectoryResource
class provides more information on the usage of the class.
The DirectoryResource
class (found in the WebStack.Resources.Static
module) accepts the following parameters when being initialised:
directory
media_types
unrecognised_media_type
media_types
parameter.urlencoding
Using the content_types
parameter (see below), one might choose to serve all files whose names have the .html
extension with the HTML file (or content) type. This would be expressed with the following dictionary:
{"html" : WebStack.Generic.ContentType("text/html", "utf-8")}
Note that the .
+character is omitted from the filename extension. Where it is tedious
+to create content type objects and where the same character encoding
+applies for all types of files, it is possible to use the media_types
and default_encoding
parameters instead.
The API documentation for the DirectoryResource
class provides more information on the usage of the class.
The DirectoryResource
class (found in the WebStack.Resources.Static
module) accepts the following parameters when being initialised:
directory
media_types
unrecognised_media_type
media_types
parameter.content_types
WebStack.Generic.ContentType
).unrecognised_content_type
content_types
parameter.default_encoding
media_types
and unrecognised_media_type
parameters. If not specified, no character encoding will be stated for content associated with such media types.urlencoding
One might combine MapResource
with DirectoryResource
to provide stylesheet and script file directories for an application as follows:
from WebStack.Resources.ResourceMap import MapResource
from WebStack.Resources.Static import DirectoryResource
# This is where the application's resources would be obtained.
app_resource = ...
# Here is where we combine MapResource and DirectoryResource.
# Note that one would not necessarily hard-code directory paths into the application.
top_resource = MapResource({
"styles" : DirectoryResource("/usr/share/apps/MyApp/styles", {"css" : "text/css"}),
"scripts" : DirectoryResource("/usr/share/apps/MyApp/scripts", {"js" : "text/javascript"}),
"" : app_resource
})
In the above example, any file in the styles
directory whose name ends with .css
is served as text/css
. Similarly, any file in the scripts
directory whose name ends with .js
is served as text/javascript
.