class documentation

class Map:

View In Hierarchy

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!

Changed in version 1.0: If url_scheme is ws or wss, only WebSocket rules will match.
Changed in version 1.0: Added merge_slashes.
Changed in version 0.7: Added encoding_errors and host_matching.
Changed in version 0.5: Added sort_parameters and sort_key.
Parameters
rulessequence of url rules for this map.
default​_subdomainThe default subdomain for rules without a subdomain defined.
charsetcharset of the url. defaults to "utf-8"
strict​_slashesIf a rule ends with a slash but the matched URL does not, redirect to the URL with a trailing slash.
merge​_slashesMerge consecutive slashes when matching or building URLs. Matches will redirect to the normalized URL. Slashes in variable parts are not merged.
redirect​_defaultsThis will redirect to the default rule if it wasn't visited that way. This helps creating unique URLs.
convertersA dict of converters that adds additional converters to the list of converters. If you redefine one converter this will override the original one.
sort​_parametersIf set to True the url parameters are sorted. See url_encode for more details.
sort​_keyThe sort key function for url_encode.
encoding​_errorsthe error method to use for decoding
host​_matchingif 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
def __init__(self, rules=None, default_subdomain='', charset='utf-8', strict_slashes=True, merge_slashes=True, redirect_defaults=True, converters=None, sort_parameters=False, sort_key=None, encoding_errors='replace', host_matching=False):

Undocumented

Parameters
rules:t.Optional[t.Iterable[RuleFactory]]Undocumented
default​_subdomain:strUndocumented
charset:strUndocumented
strict​_slashes:boolUndocumented
merge​_slashes:boolUndocumented
redirect​_defaults:boolUndocumented
converters:t.Optional[t.Mapping[str, t.Type[BaseConverter]]]Undocumented
sort​_parameters:boolUndocumented
sort​_key:t.Optional[t.Callable[[t.Any], t.Any]]Undocumented
encoding​_errors:strUndocumented
host​_matching:boolUndocumented
def __repr__(self):

Undocumented

Returns
strUndocumented
def add(self, rulefactory):
Add a new rule or factory to the map and bind it. Requires that the rule is not bound to another map.
Parameters
rulefactory:RuleFactorya Rule or RuleFactory
def bind(self, server_name, script_name=None, subdomain=None, url_scheme='http', default_method='GET', path_info=None, query_args=None):

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.

Changed in version 1.0: If url_scheme is ws or wss, only WebSocket rules will match.
Changed in version 0.15: path_info defaults to '/' if None.
Changed in version 0.8: query_args can be a string.
Changed in version 0.7: Added query_args.
Parameters
server​_name:strUndocumented
script​_name:t.Optional[str]Undocumented
subdomain:t.Optional[str]Undocumented
url​_scheme:strUndocumented
default​_method:strUndocumented
path​_info:t.Optional[str]Undocumented
query​_args:t.Optional[t.Union[t.Mapping[str, t.Any], str]]Undocumented
Returns
MapAdapterUndocumented
def bind_to_environ(self, environ, server_name=None, subdomain=None):

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.

Changed in version 1.0.0: If the passed server name specifies port 443, it will match if the incoming scheme is https without a port.
Changed in version 1.0.0: A warning is shown when the passed server name does not match the incoming WSGI server name.
Changed in version 0.8: This will no longer raise a ValueError when an unexpected server name was passed.
Changed in version 0.5: previously this method accepted a bogus calculate_subdomain parameter that did not have any effect. It was removed because of that.
Parameters
environ:t.Union[WSGIEnvironment, Request]a WSGI environment.
server​_name:t.Optional[str]an optional server name hint (see above).
subdomain:t.Optional[str]optionally the current subdomain (see above).
Returns
MapAdapterUndocumented
def is_endpoint_expecting(self, endpoint, *arguments):
Iterate over all rules and check if the endpoint expects the arguments provided. This is for example useful if you have some URLs that expect a language code and others that do not and you want to wrap the builder a bit so that the current language code is automatically added if not provided but endpoints expect it.
Parameters
endpoint:strthe endpoint to check.
*arguments:strthis function accepts one or more arguments as positional arguments. Each one of them is checked.
Returns
boolUndocumented
def iter_rules(self, endpoint=None):
Iterate over all rules or the rules of an endpoint.
Parameters
endpoint:t.Optional[str]if provided only the rules for that endpoint are returned.
Returns
t.Iterator[Rule]an iterator
def update(self):
Called before matching and building to keep the compiled rules in the correct order after things changed.
default_converters =

Undocumented

charset =

Undocumented

converters =

Undocumented

default_subdomain =

Undocumented

encoding_errors =

Undocumented

host_matching =

Undocumented

merge_slashes =

Undocumented

redirect_defaults =

Undocumented

sort_key =

Undocumented

sort_parameters =

Undocumented

strict_slashes =

Undocumented

_remap: bool =

Undocumented

_remap_lock =

Undocumented

_rules: t.List[Rule] =

Undocumented

_rules_by_endpoint: t.Dict[str, t.List[Rule]] =

Undocumented