pyramid_duh.view module¶
Utilities for view configuration
-
class
pyramid_duh.view.
SubpathPredicate
(paths, config)[source]¶ Bases:
object
Generate a custom predicate that matches subpaths
Parameters: *paths : list
List of match specs.
Notes
A match spec may take one of three forms:
'glob' 'name/glob' 'name/glob/flags'
The name is optional, but if you wish to specify flags then you have to include the leading slash:
# A match spec with flags and no name '/foo.*/r'
The names will be accessible from the
request.named_subpaths
attribute.@view_config(context=Root, name='simple', subpath=('package/*', 'version/*/?')) def simple(request) pkg = request.named_subpaths['package'] version = request.named_subpaths.get('version') request.response.body = '<h1>%s</h1>' % package if version is not None: request.response.body += '<h4>version: %s</h4>' % version return request.response
See
match()
for more information on match flags`
-
pyramid_duh.view.
addslash
(fxn)[source]¶ View decorator that adds a trailing slash
Notes
Usage:
@view_config(context=MyCtxt, renderer='json') @addslash def do_view(request): return 'cool data'
-
pyramid_duh.view.
match
(pattern, path, flags)[source]¶ Check if a pattern matches a path
Parameters: pattern : str
Glob or PCRE
path : str or None
The path to check, or None if no path
flags : {‘r’, ‘i’, ‘a’, ‘?’}
Special match flags. These may be combined (e.g. ‘ri?’). See the notes for an explanation of the different values.
Returns: match : bool or SRE_Match
A boolean indicating the match status, or the regex match object if there was a successful PCRE match.
Notes
Flag Description r Match using PCRE (default glob) i Case-insensitive match (must be used with ‘r’) a ASCII-only match (must be used with ‘r’, python 3 only) ? Path is optional (return True if path is None)