Package WebStack :: Package Resources :: Module ResourceMap :: Class MapResource
[show private | hide private]
[frames | no frames]

Class MapResource


A resource mapping names to other resources.
Method Summary
  __init__(self, mapping, pass_through, directory_redirects, urlencoding)
Initialise the resource with a 'mapping' of names to resources.
  respond(self, trans)
Using the path information from the given transaction 'trans', invoke mapped resources.
  send_error(self, trans)
Send the error using the given 'trans'.
  send_redirect(self, trans)
Send a redirect using the given 'trans', adding a "/" character to the end of the request path.

Method Details

__init__(self, mapping, pass_through=0, directory_redirects=1, urlencoding='utf-8')
(Constructor)

Initialise the resource with a 'mapping' of names to resources. The 'mapping' should be a dictionary-like object employing simple names without "/" characters; the special value None is used to specify a "catch all" resource which receives all requests whose virtual path info does not match any of the names in the mapping. For example:

mapping is {"mammals" : ..., "reptiles" : ..., None : ...}

/mammals/cat -> matches "mammals" /reptiles/python -> matches "reptiles" /creatures/goblin -> no match, handled by None

When this resource matches a name in the virtual path info to one of the names in the mapping, it removes the section of the virtual path info corresponding to that name before dispatching to the corresponding resource. For example:

/mammals/dog -> match with "mammals" in mapping -> /dog

By default, where the first part of the virtual path info does not correspond to any of the names in the mapping, the first piece of the virtual path info is removed before dispatching to the "catch all" resource. For example:

/creatures/unicorn -> no match -> /unicorn

However, the optional 'pass_through' parameter, if set to a true value (which is not the default setting), changes the above behaviour in cases where no matching name is found: in such cases, no part of the virtual path info is removed, and the request is dispatched to the "catch all" resource unchanged. For example:

/creatures/unicorn -> no match -> /creatures/unicorn

With 'pass_through' set to a true value, care must be taken if this resource is set as its own "catch all" resource. For example:

map_resource = MapResource(...) map_resource.mapping[None] = map_resource

The optional 'directory_redirects' parameter, if set to a true value (as is the default setting), causes a redirect adding a trailing "/" character if the request path does not end with such a character.

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

respond(self, trans)

Using the path information from the given transaction 'trans', invoke mapped resources. Otherwise return an error condition.

send_error(self, trans)

Send the error using the given 'trans'.

send_redirect(self, trans)

Send a redirect using the given 'trans', adding a "/" character to the end of the request path.

Generated by Epydoc 2.1 on Sat Nov 26 02:16:39 2005 http://epydoc.sf.net