Package WebStack :: Package Resources :: Module Static :: Class DirectoryResource
[show private | hide private]
[frames | no frames]

Class DirectoryResource


A resource serving the contents of a filesystem directory.

Method Summary
  __init__(self, directory, media_types, unrecognised_media_type, content_types, unrecognised_content_type, default_encoding, urlencoding)
Initialise the resource to serve files from the given 'directory'.
  not_found(self, trans, filename)
Send the "not found" response using the given transaction, 'trans', and specifying the given 'filename' (if appropriate).
  respond(self, trans)
Respond to the given transaction, 'trans', by serving a file.

Method Details

__init__(self, directory, media_types=None, unrecognised_media_type='application/data', content_types=None, unrecognised_content_type=None, default_encoding=None, urlencoding='utf-8')
(Constructor)

Initialise the resource to serve files from the given 'directory'.

The optional 'content_types' dictionary can be used to map filename
extensions to content types, where extensions consist of the part of a
name after a "." character (such as "txt", "html"), and where content
types are typically WebStack.Generic.ContentType objects.

The optional 'media_types' dictionary can be used to map filename
extensions to media types, where extensions consist of the part of a
name after a "." character (such as "txt", "html"), and where media
types are the usual content descriptions (such as "text/plain" and
"text/html").

If 'content_types' or 'media_types' contain a mapping from None to a
content or media type, then this mapping is used when no extension is
present on a requested resource name.

Where no content or media type can be found for a resource, a
predefined media type is set which can be overridden by specifying a
value for the optional 'unrecognised_media_type' or for the
'unrecognised_content_type' parameter - the latter overriding the former
if specified.

The optional 'default_encoding' is used to specify the character
encoding used in any content type produced from a media type (or for
the unrecognised media type). If set to None (as is the default), no
encoding declaration is produced for file content associated with media
types.

The optional 'urlencoding' is used to decode "URL encoded" character
values in the request path, and overrides the default encoding wherever
possible.

not_found(self, trans, filename)

Send the "not found" response using the given transaction, 'trans', and
specifying the given 'filename' (if appropriate).

respond(self, trans)

Respond to the given transaction, 'trans', by serving a file.

Generated by Epydoc 2.1 on Thu Mar 1 00:37:14 2007 http://epydoc.sf.net