__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.
-
|