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, path_encoding, 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.

Class Variable Summary
str path_encoding = 'utf-8'

Method Details

__init__(self, mapping, pass_through=0, directory_redirects=1, path_encoding=None, urlencoding=None)
(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 'path_encoding' (for which 'urlencoding' is a synonym) 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.

Class Variable Details

path_encoding

Type:
str
Value:
'utf-8'                                                                

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