class Map:
The map class stores all the URL rules and some configuration
parameters. Some of the configuration values are only stored on the
Map
instance since those affect all rules, others are just defaults
and can be overridden for each rule. Note that you have to specify all
arguments besides the rules
as keyword arguments!
Parameters | |
rules | sequence of url rules for this map. |
default_subdomain | The default subdomain for rules without a subdomain defined. |
charset | charset of the url. defaults to "utf-8" |
strict_slashes | If a rule ends with a slash but the matched URL does not, redirect to the URL with a trailing slash. |
merge_slashes | Merge consecutive slashes when matching or building URLs. Matches will redirect to the normalized URL. Slashes in variable parts are not merged. |
redirect_defaults | This will redirect to the default rule if it wasn't visited that way. This helps creating unique URLs. |
converters | A dict of converters that adds additional converters to the list of converters. If you redefine one converter this will override the original one. |
sort_parameters | If set to True the url parameters are sorted.
See url_encode for more details. |
sort_key | The sort key function for url_encode . |
encoding_errors | the error method to use for decoding |
host_matching | if set to True it enables the host matching
feature and disables the subdomain one. If
enabled the host parameter to rules is used
instead of the subdomain one. |
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | add |
Add a new rule or factory to the map and bind it. Requires that the rule is not bound to another map. |
Method | bind |
No summary |
Method | bind_to_environ |
No summary |
Method | is_endpoint_expecting |
No summary |
Method | iter_rules |
Iterate over all rules or the rules of an endpoint. |
Method | update |
Called before matching and building to keep the compiled rules in the correct order after things changed. |
Class Variable | default_converters |
Undocumented |
Instance Variable | charset |
Undocumented |
Instance Variable | converters |
Undocumented |
Instance Variable | default_subdomain |
Undocumented |
Instance Variable | encoding_errors |
Undocumented |
Instance Variable | host_matching |
Undocumented |
Instance Variable | merge_slashes |
Undocumented |
Instance Variable | redirect_defaults |
Undocumented |
Instance Variable | sort_key |
Undocumented |
Instance Variable | sort_parameters |
Undocumented |
Instance Variable | strict_slashes |
Undocumented |
Instance Variable | _remap |
Undocumented |
Instance Variable | _remap_lock |
Undocumented |
Instance Variable | _rules |
Undocumented |
Instance Variable | _rules_by_endpoint |
Undocumented |
Undocumented
Parameters | |
rules:t.Optional[ | Undocumented |
default_subdomain:str | Undocumented |
charset:str | Undocumented |
strict_slashes:bool | Undocumented |
merge_slashes:bool | Undocumented |
redirect_defaults:bool | Undocumented |
converters:t.Optional[ | Undocumented |
sort_parameters:bool | Undocumented |
sort_key:t.Optional[ | Undocumented |
encoding_errors:str | Undocumented |
host_matching:bool | Undocumented |
Parameters | |
rulefactory:RuleFactory | a Rule or RuleFactory |
Return a new MapAdapter
with the details specified to the
call. Note that script_name
will default to '/' if not further
specified or None
. The server_name
at least is a requirement
because the HTTP RFC requires absolute URLs for redirects and so all
redirect exceptions raised by Werkzeug will contain the full canonical
URL.
If no path_info is passed to match
it will use the default path
info passed to bind. While this doesn't really make sense for
manual bind calls, it's useful if you bind a map to a WSGI
environment which already contains the path info.
subdomain
will default to the default_subdomain
for this map if
no defined. If there is no default_subdomain
you cannot use the
subdomain feature.
Parameters | |
server_name:str | Undocumented |
script_name:t.Optional[ | Undocumented |
subdomain:t.Optional[ | Undocumented |
url_scheme:str | Undocumented |
default_method:str | Undocumented |
path_info:t.Optional[ | Undocumented |
query_args:t.Optional[ | Undocumented |
Returns | |
MapAdapter | Undocumented |
Like bind
but you can pass it an WSGI environment and it
will fetch the information from that dictionary. Note that because of
limitations in the protocol there is no way to get the current
subdomain and real server_name
from the environment. If you don't
provide it, Werkzeug will use SERVER_NAME
and SERVER_PORT
(or
HTTP_HOST
if provided) as used server_name
with disabled subdomain
feature.
If subdomain
is None
but an environment and a server name is
provided it will calculate the current subdomain automatically.
Example: server_name
is 'example.com' and the SERVER_NAME
in the wsgi environ
is 'staging.dev.example.com' the calculated
subdomain will be 'staging.dev'.
If the object passed as environ has an environ attribute, the value of
this attribute is used instead. This allows you to pass request
objects. Additionally PATH_INFO
added as a default of the
MapAdapter
so that you don't have to pass the path info to
the match method.
calculate_subdomain
parameter that did not have any effect. It was removed because
of that.Parameters | |
environ:t.Union[ | a WSGI environment. |
server_name:t.Optional[ | an optional server name hint (see above). |
subdomain:t.Optional[ | optionally the current subdomain (see above). |
Returns | |
MapAdapter | Undocumented |
Parameters | |
endpoint:str | the endpoint to check. |
*arguments:str | this function accepts one or more arguments as positional arguments. Each one of them is checked. |
Returns | |
bool | Undocumented |
Parameters | |
endpoint:t.Optional[ | if provided only the rules for that endpoint are returned. |
Returns | |
t.Iterator[ | an iterator |