class documentation

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! :param rules: sequence of url rules for this map. :param default_subdomain: The default subdomain for rules without a subdomain defined. :param charset: charset of the url. defaults to ``"utf-8"`` :param strict_slashes: If a rule ends with a slash but the matched URL does not, redirect to the URL with a trailing slash. :param merge_slashes: Merge consecutive slashes when matching or building URLs. Matches will redirect to the normalized URL. Slashes in variable parts are not merged. :param redirect_defaults: This will redirect to the default rule if it wasn't visited that way. This helps creating unique URLs. :param 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. :param sort_parameters: If set to `True` the url parameters are sorted. See `url_encode` for more details. :param sort_key: The sort key function for `url_encode`. :param encoding_errors: the error method to use for decoding :param 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. .. versionchanged:: 1.0 If ``url_scheme`` is ``ws`` or ``wss``, only WebSocket rules will match. .. versionchanged:: 1.0 Added ``merge_slashes``. .. versionchanged:: 0.7 Added ``encoding_errors`` and ``host_matching``. .. versionchanged:: 0.5 Added ``sort_parameters`` and ``sort_key``.

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 Return a new :class:`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.
Method bind_to_environ Like :meth:`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...
Method is_endpoint_expecting 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.
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 _matcher Undocumented
Instance Variable _remap Undocumented
Instance Variable _remap_lock Undocumented
Instance Variable _rules_by_endpoint Undocumented
Property _rules Undocumented
def __init__(self, rules: t.Optional[t.Iterable[RuleFactory]] = None, default_subdomain: str = '', charset: str = 'utf-8', strict_slashes: bool = True, merge_slashes: bool = True, redirect_defaults: bool = True, converters: t.Optional[t.Mapping[str, t.Type[BaseConverter]]] = None, sort_parameters: bool = False, sort_key: t.Optional[t.Callable[[t.Any], t.Any]] = None, encoding_errors: str = 'replace', host_matching: bool = False): (source)

Undocumented

def __repr__(self) -> str: (source)

Undocumented

def add(self, rulefactory: RuleFactory): (source)

Add a new rule or factory to the map and bind it. Requires that the rule is not bound to another map. :param rulefactory: a :class:`Rule` or :class:`RuleFactory`

def bind(self, server_name: str, script_name: t.Optional[str] = None, subdomain: t.Optional[str] = None, url_scheme: str = 'http', default_method: str = 'GET', path_info: t.Optional[str] = None, query_args: t.Optional[t.Union[t.Mapping[str, t.Any], str]] = None) -> MapAdapter: (source)

Return a new :class:`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 :meth:`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. .. versionchanged:: 1.0 If ``url_scheme`` is ``ws`` or ``wss``, only WebSocket rules will match. .. versionchanged:: 0.15 ``path_info`` defaults to ``'/'`` if ``None``. .. versionchanged:: 0.8 ``query_args`` can be a string. .. versionchanged:: 0.7 Added ``query_args``.

def bind_to_environ(self, environ: t.Union[WSGIEnvironment, Request], server_name: t.Optional[str] = None, subdomain: t.Optional[str] = None) -> MapAdapter: (source)

Like :meth:`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 :class:`MapAdapter` so that you don't have to pass the path info to the match method. .. versionchanged:: 1.0.0 If the passed server name specifies port 443, it will match if the incoming scheme is ``https`` without a port. .. versionchanged:: 1.0.0 A warning is shown when the passed server name does not match the incoming WSGI server name. .. versionchanged:: 0.8 This will no longer raise a ValueError when an unexpected server name was passed. .. versionchanged:: 0.5 previously this method accepted a bogus `calculate_subdomain` parameter that did not have any effect. It was removed because of that. :param environ: a WSGI environment. :param server_name: an optional server name hint (see above). :param subdomain: optionally the current subdomain (see above).

def is_endpoint_expecting(self, endpoint: str, *arguments: str) -> bool: (source)

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. :param endpoint: the endpoint to check. :param arguments: this function accepts one or more arguments as positional arguments. Each one of them is checked.

def iter_rules(self, endpoint: t.Optional[str] = None) -> t.Iterator[Rule]: (source)

Iterate over all rules or the rules of an endpoint. :param endpoint: if provided only the rules for that endpoint are returned. :return: an iterator

def update(self): (source)

Called before matching and building to keep the compiled rules in the correct order after things changed.

default_converters = (source)

Undocumented

Undocumented

converters = (source)

Undocumented

default_subdomain = (source)

Undocumented

encoding_errors = (source)

Undocumented

host_matching = (source)

Undocumented

merge_slashes = (source)

Undocumented

redirect_defaults = (source)

Undocumented

sort_key = (source)

Undocumented

sort_parameters = (source)

Undocumented

strict_slashes = (source)

Undocumented

_matcher = (source)

Undocumented

Undocumented

_remap_lock = (source)

Undocumented

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

Undocumented

Undocumented