morepath.path
– Path registry¶
Registration of routes.
This builds on morepath.traject
.
See also morepath.directive.PathRegistry
-
class
morepath.path.
PathInfo
(path, parameters)¶ Abstract representation of a path.
Parameters: - path – a str representing a path
- parameters – a dict representing URL parameters.
-
url
(prefix, name)¶ Turn a path into a URL.
Parameters: - prefix – the URL prefix to put in front of the path. This
should contain something like
http://localhost
, so the URL without the path or parameter information. - name – additional view name to postfix to the path.
Returns: a URL with the prefix, the name and URL encoded parameters.
- prefix – the URL prefix to put in front of the path. This
should contain something like
-
class
morepath.path.
Path
(path, factory_args, converters, absorb)¶ Registered path for linking purposes.
Parameters: - path – the route.
- factory_args – the arguments for the factory function used to construct this path. This is used to determine the URL parameters for the path.
- converters – converters dictionary that is used to represent variables in the path.
- absorb – bool indicating this is an absorbing path.
-
__call__
(app, model, variables)¶ Get path info given model and variables.
Parameters: - app – the app instance. Not actually used in the implementation but passed if this is registered as a method.
- model – model class. Not actually used in the
implementation but used for dispatch in
GenericApp._class_path()
. - variables – dict with the variables used in the path. each argument to the factory function should be represented.
Returns: PathInfo
instance representing the path.
-
get_variables_and_parameters
(variables, extra_parameters)¶ Get converted variables and parameters.
Parameters: - variables – dict of variables to use in the path.
- extra_parameters – dict of additional parameters to use.
Returns: variables, parameters
tuple with dicts of converted path variables and converted URL parameters.
-
morepath.path.
get_arguments
(callable, exclude)¶ Introspect callable to get callable arguments and their defaults.
Parameters: - callable – callable object such as a function.
- exclude – a set of names not to extract.
Returns: a dict with as keys the argument names and as values the default values (or
None
if no default value was defined).
-
morepath.path.
filter_arguments
(arguments, exclude)¶ Filter arguments.
Given a dictionary with arguments and defaults, filter out arguments in
exclude
.Parameters: - arguments – arguments dict
- exclude – set of argument names to exclude.
Returns: filtered arguments dict
-
morepath.path.
fixed_urlencode
(s, doseq=0)¶ urllib.urlencode
fixed for~
Workaround for Python bug:
https://bugs.python.org/issue16285
tilde should not be encoded according to RFC3986