Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/werkzeug/__pycache__/routing.cpython-37.pyc

998 lines
63 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>/<2F>]<5D><00>@s|dZddlZddlZddlZddlZddlZddlmZddlm Z ddl
m Z ddl
m Z ddl
m Z dd l
mZdd
l
mZdd l
mZdd l
mZdd l
mZddl
mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%ddl$m&Z&ddl$m'Z'ddl(m)Z)e<04>*dej+<2B>Z,e<04>*d <20>Z-e<04>*d!ej+ej.B<00>Z/dd"d#d$<24>Z0d%d&<26>Z1d'd(<28>Z2d)d*<2A>Z3Gd+d,<2C>d,e4<65>Z5Gd-d.<2E>d.ee5<65>Z6Gd/d0<64>d0e5<65>Z7Gd1d2<64>d2e5<65>Z8e Gd3d4<64>d4e5e9<65><04>Z:Gd5d6<64>d6e;<3B>Z<Gd7d8<64>d8e=<3D>Z>Gd9d:<3A>d:e><3E>Z?Gd;d<<3C>d<e><3E>Z@Gd=d><3E>d>e><3E>ZAGd?d@<40>d@e=<3D>ZBGdAdB<64>dBe><3E>ZCdCdD<64>ZDdEZEdFZFeDeF<65>ZGeDdG<64>eDdH<64>fZHe GdIdJ<64>dJe><3E><03>ZIGdKdL<64>dLe=<3D>ZJGdMdN<64>dNeJ<65>ZKGdOdP<64>dPeJ<65>ZLGdQdR<64>dReJ<65>ZMGdSdT<64>dTeJ<65>ZNGdUdV<64>dVeN<65>ZOGdWdX<64>dXeN<65>ZPGdYdZ<64>dZeJ<65>ZQeKeKeLeMeOePeQd[<5B>ZRGd\d]<5D>d]e=<3D>ZSGd^d_<64>d_e=<3D>ZTdS)`aj
werkzeug.routing
~~~~~~~~~~~~~~~~
When it comes to combining multiple controller or view functions (however
you want to call them) you need a dispatcher. A simple way would be
applying regular expression tests on the ``PATH_INFO`` and calling
registered callback functions that return the value then.
This module implements a much more powerful system than simple regular
expression matching because it can also convert values in the URLs and
build URLs.
Here a simple example that creates an URL map for an application with
two subdomains (www and kb) and some URL rules:
>>> m = Map([
... # Static URLs
... Rule('/', endpoint='static/index'),
... Rule('/about', endpoint='static/about'),
... Rule('/help', endpoint='static/help'),
... # Knowledge Base
... Subdomain('kb', [
... Rule('/', endpoint='kb/index'),
... Rule('/browse/', endpoint='kb/browse'),
... Rule('/browse/<int:id>/', endpoint='kb/browse'),
... Rule('/browse/<int:id>/<int:page>', endpoint='kb/browse')
... ])
... ], default_subdomain='www')
If the application doesn't use subdomains it's perfectly fine to not set
the default subdomain and not use the `Subdomain` rule factory. The endpoint
in the rules can be anything, for example import paths or unique
identifiers. The WSGI application can use those endpoints to get the
handler for that URL. It doesn't have to be a string at all but it's
recommended.
Now it's possible to create a URL adapter for one of the subdomains and
build URLs:
>>> c = m.bind('example.com')
>>> c.build("kb/browse", dict(id=42))
'http://kb.example.com/browse/42/'
>>> c.build("kb/browse", dict())
'http://kb.example.com/browse/'
>>> c.build("kb/browse", dict(id=42, page=3))
'http://kb.example.com/browse/42/3'
>>> c.build("static/about")
'/about'
>>> c.build("static/index", force_external=True)
'http://www.example.com/'
>>> c = m.bind('example.com', subdomain='kb')
>>> c.build("static/about")
'http://www.example.com/about'
The first argument to bind is the server name *without* the subdomain.
Per default it will assume that the script is mounted on the root, but
often that's not the case so you can provide the real mount point as
second argument:
>>> c = m.bind('example.com', '/applications/example')
The third argument can be the subdomain, if not given the default
subdomain is used. For more details about binding have a look at the
documentation of the `MapAdapter`.
And here is how you can match URLs:
>>> c = m.bind('example.com')
>>> c.match("/")
('static/index', {})
>>> c.match("/about")
('static/about', {})
>>> c = m.bind('example.com', '/', 'kb')
>>> c.match("/")
('kb/index', {})
>>> c.match("/browse/42/23")
('kb/browse', {'id': 42, 'page': 23})
If matching fails you get a `NotFound` exception, if the rule thinks
it's a good idea to redirect (for example because the URL was defined
to have a slash at the end but the request was missing that slash) it
will raise a `RequestRedirect` exception. Both are subclasses of the
`HTTPException` so you can use those errors as responses in the
application.
If matching succeeded but the URL rule was incompatible to the given
method (for example there were only rules for `GET` and `HEAD` and
routing system tried to match a `POST` request) a `MethodNotAllowed`
exception is raised.
:copyright: 2007 Pallets
:license: BSD-3-Clause
<EFBFBD>N)<01>pformat)<01>Lock<63>)<01>implements_to_string)<01> iteritems)<01>
itervalues)<01>native_string_result)<01> string_types)<01> text_type)<01>to_bytes)<01>
to_unicode)<01>wsgi_decoding_dance)<01> _encode_idna)<01> _get_environ)<01> ImmutableDict)<01> MultiDict)<01>BadHost)<01> HTTPException)<01>MethodNotAllowed)<01>NotFound)<01>_fast_url_quote)<01>
url_encode)<01>url_join)<01> url_quote)<01>cached_property)<01> format_string)<01>redirect)<01>get_hostao
(?P<static>[^<]*) # static rule data
<
(?:
(?P<converter>[a-zA-Z_][a-zA-Z0-9_]*) # converter name
(?:\((?P<args>.*?)\))? # converter arguments
\: # variable delimiter
)?
(?P<variable>[a-zA-Z_][a-zA-Z0-9_]*) # variable name
>
z <([^>]+)>z<>
((?P<name>\w+)\s*=\s*)?
(?P<value>
True|False|
\d+.\d+|
\d+.|
\d+|
[\w\d_.]+|
[urUR]?(?P<stringval>"[^"]*?"|'[^']*')
)\s*,
TF)<03>None<6E>True<75>Falsec Csx|tkrt|Sx.ttfD]"}y||<00>Stk
r:YqXqW|dd<01>|dd<00>krp|ddkrp|dd<02>}t|<00>S)Nr<00><><EFBFBD><EFBFBD><EFBFBD>rz"')<05>_PYTHON_CONSTANTS<54>int<6E>float<61>
ValueErrorr
)<02>value<75>convert<72>r(<00>6/tmp/pip-install-c3kgu56x/Werkzeug/werkzeug/routing.py<70>
_pythonize<EFBFBD>s
$ r*cCs||d7}g}i}x^t<00>|<00>D]P}|<03>d<02>}|dkr<|<03>d<03>}t|<04>}|<03>d<04>sZ|<01>|<04>q|<03>d<04>}|||<qWt|<01>|fS)N<>,Z stringvalr&<00>name)<06>_converter_args_re<72>finditer<65>groupr*<00>append<6E>tuple)Zargstr<74>args<67>kwargs<67>itemr&r,r(r(r)<00>parse_converter_args<67>s


 
 r5c
cs<>d}t|<00>}tj}t<03>}x<>||kr<>|||<01>}|dkr6P|<05><04>}|drVdd|dfV|d}|dphd}||kr~td|<00><01>|<04>|<07>||dp<>d|fV|<05><07>}qW||kr<>||d<02>} d | ks<>d
| kr<>td |<00><01>dd| fVdS) z<>Parse a rule and return it as generator. Each iteration yields tuples
in the form ``(converter, arguments, variable)``. If the converter is
`None` it's a static url part, otherwise it's a dynamic one.
:internal:
rNZstatic<69>variable<6C> converter<65>defaultzvariable name %r used twice.r2<00>><3E><zmalformed url rule: %r)<08>len<65>_rule_re<72>match<63>set<65> groupdictr%<00>add<64>end)
<EFBFBD>rule<6C>posrAZdo_matchZ
used_names<EFBFBD>m<>datar6r7<00> remainingr(r(r)<00>
parse_rule<EFBFBD>s.

  
   rGc@seZdZdZdS)<03>RoutingExceptionzxSpecial exceptions that require the application to redirect, notifying
about missing urls, etc.
:internal:
N)<04>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r(r(r(r)rH<00>srHc@s$eZdZdZdZdd<04>Zdd<06>ZdS)<08>RequestRedirectz<74>Raise if the map requests a redirect. This is for example the case if
`strict_slashes` are activated and an url that requires a trailing slash.
The attribute `new_url` contains the absolute destination url.
i4cCst<00>||<01>||_dS)N)rH<00>__init__<5F>new_url)<02>selfrOr(r(r)rN<00>s zRequestRedirect.__init__cCst|j|j<02>S)N)rrO<00>code)rP<00>environr(r(r)<00> get_response<73>szRequestRedirect.get_responseN)rIrJrKrLrQrNrSr(r(r(r)rM<00>srMc@seZdZdZdS)<03> RequestSlashzInternal exception.N)rIrJrKrLr(r(r(r)rT<00>srTc@seZdZdZdd<03>ZdS)<05>RequestAliasRedirectzAThis rule is an alias and wants to redirect to the canonical URL.cCs
||_dS)N)<01>matched_values)rPrVr(r(r)rNszRequestAliasRedirect.__init__N)rIrJrKrLrNr(r(r(r)rUsrUc@s6eZdZdZd dd<04>Zedd<06><00>Zdd<08>Zd d
<EFBFBD>ZdS) <0C>
BuildErrorz_Raised if the build system cannot find a URL for an endpoint with the
values provided.
NcCs,t<00>||||<03>||_||_||_||_dS)N)<06> LookupErrorrN<00>endpoint<6E>values<65>method<6F>adapter)rPrYrZr[r\r(r(r)rNs
zBuildError.__init__cCs |<00>|j<01>S)N)<02> closest_ruler\)rPr(r(r)<00> suggestedszBuildError.suggestedcs,<00>fdd<02>}|r(|jjr(t|jj|d<03>SdS)NcsTtdt<01>d|j<03>j<03><03><04>dtt<06>jp(d<03><01>|j <09><01>dt|j
oJ<EFBFBD>j |j
k<06>g<03>S)Ng\<5C><><EFBFBD>(\<5C>?g{<14>G<EFBFBD>z<EFBFBD>?r() <0C>sum<75>difflibZSequenceMatcherrYZratio<69>boolr>rZ<00>issubset<65> arguments<74>methodsr[)rB)rPr(r)<00> _score_rules z,BuildError.closest_rule.<locals>._score_rule)<01>key)<03>map<61>_rules<65>max)rPr\rer()rPr)r]s zBuildError.closest_rulecCs<>g}|<01>d|j<00>|jr*|<01>d|j<00>|jrH|<01>dt|j<03><05><00><00>|<01>d<04>|jr<>|j|jjkr<>|jr<>|j|jjkr<>|<01>dt|jj<07><00>|jj<08> t
|jj p<>d<06><01>t
|j<03><05><00>}|r<>|<01>dt|<02><00>n|<01>d|jj<00>d <09> |<01>S)
Nz#Could not build url for endpoint %rz (%r)z with values %r<>.z Did you mean to use methods %r?r(z% Did you forget to specify values %r?z Did you mean %r instead?<3F>) r0rYr[rZ<00>sorted<65>keysr^rdrc<00>unionr><00>defaults<74>join)rP<00>messageZmissing_valuesr(r(r)<00>__str__+s*
zBuildError.__str__)N) rIrJrKrLrNrr^r]rrr(r(r(r)rW
s

 rWc@seZdZdZdS)<03>ValidationErrorz<72>Validation error. If a rule converter raises this exception the rule
does not match the current URL and the next URL is tried.
N)rIrJrKrLr(r(r(r)rsFsrsc@seZdZdZdd<03>ZdS)<05> RuleFactoryz<79>As soon as you have more complex URL setups it's a good idea to use rule
factories to avoid repetitive tasks. Some of them are builtin, others can
be added by subclassing `RuleFactory` and overriding `get_rules`.
cCs
t<00><00>dS)zaSubclasses of `RuleFactory` have to override this method and return
an iterable of rules.N)<01>NotImplementedError)rPrgr(r(r)<00> get_rulesRszRuleFactory.get_rulesN)rIrJrKrLrvr(r(r(r)rtLsrtc@s eZdZdZdd<03>Zdd<05>ZdS)<07> Subdomaina<6E>All URLs provided by this factory have the subdomain set to a
specific domain. For example if you want to use the subdomain for
the current language this can be a good setup::
url_map = Map([
Rule('/', endpoint='#select_language'),
Subdomain('<string(length=2):lang_code>', [
Rule('/', endpoint='index'),
Rule('/about', endpoint='about'),
Rule('/help', endpoint='help')
])
])
All the rules except for the ``'#select_language'`` endpoint will now
listen on a two letter long subdomain that holds the language code
for the current request.
cCs||_||_dS)N)<02> subdomain<69>rules)rPrxryr(r(r)rNkszSubdomain.__init__ccs>x8|jD].}x(|<02>|<01>D]}|<03><02>}|j|_|VqWqWdS)N)ryrv<00>emptyrx)rPrg<00> rulefactoryrBr(r(r)rvos
 zSubdomain.get_rulesN)rIrJrKrLrNrvr(r(r(r)rwXsrwc@s eZdZdZdd<03>Zdd<05>ZdS)<07>Submounta}Like `Subdomain` but prefixes the URL rule with a given string::
url_map = Map([
Rule('/', endpoint='index'),
Submount('/blog', [
Rule('/', endpoint='blog/index'),
Rule('/entry/<entry_slug>', endpoint='blog/show')
])
])
Now the rule ``'blog/show'`` matches ``/blog/entry/<entry_slug>``.
cCs|<01>d<01>|_||_dS)N<>/)<03>rstrip<69>pathry)rPrryr(r(r)rN<00>s zSubmount.__init__ccsDx>|jD]4}x.|<02>|<01>D] }|<03><02>}|j|j|_|VqWqWdS)N)ryrvrzrrB)rPrgr{rBr(r(r)rv<00>s
 zSubmount.get_rulesN)rIrJrKrLrNrvr(r(r(r)r|ws r|c@s eZdZdZdd<03>Zdd<05>ZdS)<07>EndpointPrefixa<78>Prefixes all endpoints (which must be strings for this factory) with
another string. This can be useful for sub applications::
url_map = Map([
Rule('/', endpoint='index'),
EndpointPrefix('blog/', [Submount('/blog', [
Rule('/', endpoint='index'),
Rule('/entry/<entry_slug>', endpoint='show')
])])
])
cCs||_||_dS)N)<02>prefixry)rPr<>ryr(r(r)rN<00>szEndpointPrefix.__init__ccsDx>|jD]4}x.|<02>|<01>D] }|<03><02>}|j|j|_|VqWqWdS)N)ryrvrzr<>rY)rPrgr{rBr(r(r)rv<00>s
 zEndpointPrefix.get_rulesN)rIrJrKrLrNrvr(r(r(r)r<><00>s r<>c@s eZdZdZdd<03>Zdd<05>ZdS)<07> RuleTemplateaXReturns copies of the rules wrapped and expands string templates in
the endpoint, rule, defaults or subdomain sections.
Here a small example for such a rule template::
from werkzeug.routing import Map, Rule, RuleTemplate
resource = RuleTemplate([
Rule('/$name/', endpoint='$name.list'),
Rule('/$name/<int:id>', endpoint='$name.show')
])
url_map = Map([resource(name='user'), resource(name='page')])
When a rule template is called the keyword arguments are used to
replace the placeholders in all the string parameters.
cCst|<01>|_dS)N)<02>listry)rPryr(r(r)rN<00>szRuleTemplate.__init__cOst|jt||<02><01>S)N)<03>RuleTemplateFactoryry<00>dict)rPr2r3r(r(r)<00>__call__<5F>szRuleTemplate.__call__N)rIrJrKrLrNr<>r(r(r(r)r<><00>sr<>c@s eZdZdZdd<03>Zdd<05>ZdS)r<>zsA factory that fills in template variables into rules. Used by
`RuleTemplate` internally.
:internal:
cCs||_||_dS)N)ry<00>context)rPryr<>r(r(r)rN<00>szRuleTemplateFactory.__init__c
cs<>x<>|jD]<5D>}x<>|<02>|<01>D]<5D>}d}}|jrdi}x4t|j<02>D]&\}}t|t<05>rXt||j<07>}|||<q:W|jdk r|t|j|j<07>}|j }t|t<05>r<>t||j<07>}t
t|j |j<07>|||j |j ||j<0E>VqWqWdS)N)ryrvror<00>
isinstancer rr<>rxrY<00>RulerBrd<00>
build_only<EFBFBD>strict_slashes) rPrgr{rBZ new_defaultsrxrfr&Z new_endpointr(r(r)rv<00>s, 
  

  zRuleTemplateFactory.get_rulesN)rIrJrKrLrNrvr(r(r(r)r<><00>sr<>cCsRt<00>|<00>jd}t|tj<04>r"|j}x*t<00>|<01>D]}t|tj<07>r.d|j|_q.W|S)zEast parse and prefix names with `.` to avoid collision with user varsrrj) <09>ast<73>parse<73>bodyr<79>ZExprr&<00>walk<6C>Name<6D>id)<03>src<72>tree<65>noder(r(r)<00> _prefix_names<65>s  r<>z#self._converters[{elem!r}].to_url()z^if kwargs:
q = '?'
params = self._encode_query_vars(kwargs)
else:
q = params = ''
<EFBFBD>q<>paramsc @s<>eZdZdZd/dd<05>Zdd<07>Zdd <09>Zd
d <0B>Zd d <0A>Zd0dd<0F>Z dd<11>Z
dd<13>Z dd<15>Z d1dd<17>Z edd<19><00>Zd2dd<1C>Zd3dd<1E>Zdd <20>Zd4d!d"<22>Zd#d$<24>Zd%d&<26>Zd'd(<28>ZdZd)d*<2A>Zd+d,<2C>Zed-d.<2E><00>ZdS)5r<35>a<>A Rule represents one URL pattern. There are some options for `Rule`
that change the way it behaves and are passed to the `Rule` constructor.
Note that besides the rule-string all arguments *must* be keyword arguments
in order to not break the application on Werkzeug upgrades.
`string`
Rule strings basically are just normal URL paths with placeholders in
the format ``<converter(arguments):name>`` where the converter and the
arguments are optional. If no converter is defined the `default`
converter is used which means `string` in the normal configuration.
URL rules that end with a slash are branch URLs, others are leaves.
If you have `strict_slashes` enabled (which is the default), all
branch URLs that are matched without a trailing slash will trigger a
redirect to the same URL with the missing slash appended.
The converters are defined on the `Map`.
`endpoint`
The endpoint for this rule. This can be anything. A reference to a
function, a string, a number etc. The preferred way is using a string
because the endpoint is used for URL generation.
`defaults`
An optional dict with defaults for other rules with the same endpoint.
This is a bit tricky but useful if you want to have unique URLs::
url_map = Map([
Rule('/all/', defaults={'page': 1}, endpoint='all_entries'),
Rule('/all/page/<int:page>', endpoint='all_entries')
])
If a user now visits ``http://example.com/all/page/1`` he will be
redirected to ``http://example.com/all/``. If `redirect_defaults` is
disabled on the `Map` instance this will only affect the URL
generation.
`subdomain`
The subdomain rule string for this rule. If not specified the rule
only matches for the `default_subdomain` of the map. If the map is
not bound to a subdomain this feature is disabled.
Can be useful if you want to have user profiles on different subdomains
and all subdomains are forwarded to your application::
url_map = Map([
Rule('/', subdomain='<username>', endpoint='user/homepage'),
Rule('/stats', subdomain='<username>', endpoint='user/stats')
])
`methods`
A sequence of http methods this rule applies to. If not specified, all
methods are allowed. For example this can be useful if you want different
endpoints for `POST` and `GET`. If methods are defined and the path
matches but the method matched against is not in this list or in the
list of another rule for that path the error raised is of the type
`MethodNotAllowed` rather than `NotFound`. If `GET` is present in the
list of methods and `HEAD` is not, `HEAD` is added automatically.
.. versionchanged:: 0.6.1
`HEAD` is now automatically added to the methods if `GET` is
present. The reason for this is that existing code often did not
work properly in servers not rewriting `HEAD` to `GET`
automatically and it was not documented how `HEAD` should be
treated. This was considered a bug in Werkzeug because of that.
`strict_slashes`
Override the `Map` setting for `strict_slashes` only for this rule. If
not specified the `Map` setting is used.
`build_only`
Set this to True and the rule will never match but will create a URL
that can be build. This is useful if you have resources on a subdomain
or folder that are not handled by the WSGI application (like static data)
`redirect_to`
If given this must be either a string or callable. In case of a
callable it's called with the url adapter that triggered the match and
the values of the URL as keyword arguments and has to return the target
for the redirect, otherwise it has to be a string with placeholders in
rule syntax::
def foo_with_slug(adapter, id):
# ask the database for the slug for the old id. this of
# course has nothing to do with werkzeug.
return 'foo/' + Foo.get_slug_for_id(id)
url_map = Map([
Rule('/foo/<slug>', endpoint='foo'),
Rule('/some/old/url/<slug>', redirect_to='foo/<slug>'),
Rule('/other/old/url/<int:id>', redirect_to=foo_with_slug)
])
When the rule is matched the routing system will raise a
`RequestRedirect` exception with the target for the redirect.
Keep in mind that the URL will be joined against the URL root of the
script so don't use a leading slash on the target URL unless you
really mean root of that domain.
`alias`
If enabled this rule serves as an alias for another rule with the same
endpoint and arguments.
`host`
If provided and the URL map has host matching enabled this can be
used to provide a match rule for the whole host. This also means
that the subdomain feature is disabled.
.. versionadded:: 0.7
The `alias` and `host` parameters were added.
NFc Cs<>|<01>d<01>std<02><01>||_|<01>d<01> |_d|_||_||_|
|_||_ ||_
| |_ |dkr`d|_ nFt |t<0E>rrtd<03><01>tdd<05>|D<00><01>|_ d|j kr<>d|j kr<>|j <0C>d<06>||_||_|r<>ttt|<02><02>|_nt<10>|_d|_|_|_|_dS)Nr}z$urls must start with a leading slashz4param `methods` should be `Iterable[str]`, not `str`cSsg|] }|<01><00><00>qSr()<01>upper)<02>.0<EFBFBD>xr(r(r)<00>
<listcomp><3E>sz!Rule.__init__.<locals>.<listcomp><3E>HEAD<41>GET)<19>
startswithr%rB<00>endswith<74>is_leafrgr<>rx<00>hostror<><00>aliasrdr<><00>str<74> TypeErrorr>r@rY<00> redirect_torc<00>_trace<63> _converters<72>_regex<65>_argument_weights) rP<00>stringrorxrdr<>rYr<>r<>r<>r<>r(r(r)rNss0

 z Rule.__init__cCst|<00>|jf|<00><02><00>S)z<>
Return an unbound copy of this rule.
This can be useful if want to reuse an already bound URL for another
map. See ``get_empty_kwargs`` to override what keyword arguments are
provided to the new copy.
)<03>typerB<00>get_empty_kwargs)rPr(r(r)rz<00>sz
Rule.emptyc Cs>d}|jrt|j<00>}t||j|j|j|j|j|j|j|j d<02> S)a
Provides kwargs for instantiating empty copy with empty()
Use this method to provide custom keyword arguments to the subclass of
``Rule`` when calling ``some_rule.empty()``. Helpful when the subclass
has custom keyword arguments that are needed at instantiation.
Must return a ``dict`` that will be provided as kwargs to the new
instance of ``Rule``, following the initial ``self.rule`` value which
is always provided as the first, required positional argument.
N) rorxrdr<>rYr<>r<>r<>r<>)
ror<>rxrdr<>rYr<>r<>r<>r<>)rPror(r(r)r<><00>s 
zRule.get_empty_kwargsccs
|VdS)Nr()rPrgr(r(r)rv<00>szRule.get_rulescCs|j|jdd<02>dS)zqRebinds and refreshes the URL. Call this if you modified the
rule in place.
:internal:
T)<01>rebindN)<02>bindrg)rPr(r(r)<00>refresh<73>sz Rule.refreshcCsV|jdk r |s td||jf<00><01>||_|jdkr8|j|_|jdkrJ|j|_|<00><05>dS)z<>Bind the url to a map and create a regular expression based on
the information from the rule itself and the defaults from the map.
:internal:
Nz#url rule %r already bound to map %r)rg<00> RuntimeErrorr<72>rx<00>default_subdomain<69>compile)rPrgr<>r(r(r)r<><00>s

z Rule.bindcCs2||jjkrtd|<00><01>|jj||jf|<03>|<04>S)zWLooks up the converter for the given parameter.
.. versionadded:: 0.9
zthe converter %r does not exist)rg<00>
convertersrX)rPZ variable_nameZconverter_namer2r3r(r(r)<00> get_converter<65>s  zRule.get_convertercCst||jj|jj|jjd<01>S)N)<03>charset<65>sortrf)rrgr<><00>sort_parameters<72>sort_key)rPZ
query_varsr(r(r)<00>_encode_query_vars<72>s
zRule._encode_query_varscs<00>jdk std<02><01><01>jjr&<26>jp"d}n
<EFBFBD>jp.d}g<00>_i<00>_g<00>_g<00>_g<00><00><00>fdd<05>}||<01><00><00> d<06><00>j<05> d<07>|<02>j
r<EFBFBD><EFBFBD>j n
<EFBFBD>j <0B> d<08><01><00>j
s<EFBFBD><EFBFBD>j<05> d <09><00><01> d
<EFBFBD><01><0E>d<01><02>_<0F><01> d <0B><01><0E>d<01><02>_<10>jr<>dSd d<03><12><00><01>j
s<><73>j r<>d p<>df}t<14>|tj<16><02>_dS)z.Compiles the regular expression and stores it.Nzrule not boundrkc s<>d}x<>t|<00>D]<5D>\}}}|dkrp<72><00>t<02>|<04><01><00>j<04>d|f<02>x<>|<04>d<03>D]}|rL<72>j<06>|t|<05> f<02>qLWnv|r<>t|<03>\}}nd}i}<07><01> ||||<07>}<08><00>d||j
f<00>|<08>j |<<00>j<04>d|f<02><00>j <0C>|j <0A><00>j<0E>t|<04><01>|d}qWdS)NrFr}r(z
(?P<%s>%s)Tr)rGr0<00>re<72>escaper<65><00>split<69>_static_weightsr;r5r<><00>regexr<78>r<><00>weightrcr@r<>) rB<00>indexr7rcr6<00>partZc_argsZc_kwargsZconvobj)<02> regex_partsrPr(r)<00> _build_regex<65>s&
z"Rule.compile.<locals>._build_regexz\|)F<>|r})Fr}FTz^%s%s$z(?<!/)(?P<__suffix__>/?))rg<00>AssertionError<6F> host_matchingr<67>rxr<>r<>r<>r<>r0r<>rBr~<00>_compile_builder<65>__get__<5F>_build<6C>_build_unknownr<6E>rpr<>r<>r<><00>UNICODEr<45>)rPZ domain_ruler<65>r<>r()r<>rPr)r<><00>s4 

  z Rule.compilec Cs<>|js<>|j<01>|<01>}|dk r<>|<03><03>}|jr\|js\|<04>d<02>s\|dksT|jdksT||jkr\t<08><00>n |jsh|d=i}xJt |<04>D]>\}}y|j
|<00> |<07>}Wnt k
r<EFBFBD>dSX||t |<06><qvW|jr<>|<05>|j<0E>|jr<>|jjr<>t|<05><01>|SdS)auCheck if the rule matches a given path. Path is a string in the
form ``"subdomain|/path"`` and is assembled by the map. If
the map is doing host matching the subdomain part will be the host
instead.
If the rule matches a dict with the converted values is returned,
otherwise the return value is `None`.
:internal:
NZ
__suffix__)r<>r<><00>searchr?r<>r<><00>poprdrTrr<><00> to_pythonrsr<>ro<00>updater<65>rg<00>redirect_defaultsrU)rPrr[rD<00>groups<70>resultr,r&r(r(r)r='s.  
 z
Rule.matchcCsii}}t|||<03>||S)N)<01>exec)rQr,ZglobsZlocsr(r(r)<00>_get_func_codeWs
 zRule._get_func_codeTc s<>|jpi<00>g}g}|}x<>|jD]<5D>\}}|dkr<||kr<|}q|rl|<06>krl|j|<00><03>|<00>}|<04>d|f<02>q|s<>|<04>dtt||jj<08>dd<04>f<02>q|<04>d|f<02>qWdd<07><00><00>fdd <09>}||<02>}||<03>} |s<>g}
nt g}
| <09>
t <0B>d
d <0B>} |
<EFBFBD>t <0C> t <0C>| |<08>| | <09>gt <0C><0F><00><02><01><00>fd d <0A>||D<00>} dd <0A><00>D<00>} td<0F>}d<10>|j<12>|_tt d<11><02>r<>|jj<15>t <0C>dd<00><02>x(| | D]}|jj<15>t <0C>|d<00><02><00>qxWt <0C>dd<00>|j_nP|jj<15>t <0C>dt <0C><19><00><02>x,| | D] }|jj<15>t <0C>|t <0C><19><00><02><00>q<>Wd|j_x"| D]}|jj<00>t <0C>d<14><01><00>qW|
|_t <0C>d<14>}|g|_x8t <0C>|<11>D]*}d|jk<06>rXd|_d|jk<06>rBd|_ <20>qBWt!|dd<1A>}|<00>"||j<13>S)Nr<4E>Fz/:|+)<01>safeTcSs,ttj|d<01><01>}t<03>t|<00>t<03><06><00>g|_|S)N)<01>elem)r<><00>_CALL_CONVERTER_CODE_FMT<4D>formatr<74>r<>r<><00>Loadr2)r<><00>retr(r(r)<00>_converttsz'Rule._compile_builder.<locals>._convertcs<><00>fdd<02>|D<00>}|p t<00>d<03>g}|dg}xV|dd<00>D]F}t|tj<01>rvt|dtj<01>rvt<00>|dj|j<00>|d<q:|<02>|<03>q:W|S)Ncs(g|] \}}|r<18>|<02>n
tj|d<00><01>qS))<01>s)r<><00>Str)r<><00>
is_dynamicr<EFBFBD>)r<>r(r)r<>{sz9Rule._compile_builder.<locals>._parts.<locals>.<listcomp>rkrrr!)r<>r<>r<>r<>r0)<04>ops<70>partsr<73><00>p)r<>r(r)<00>_partsys

z%Rule._compile_builder.<locals>._partscSsLt|<00>dkr|dSttd<03>r(t<02>|<00>Std<04>}t<02>|t<02><06><00>g|_|SdS)Nrr<00> JoinedStrz "".join())r;<00>hasattrr<72>r<>r<><00>Tupler<65>r2)r<><00>callr(r(r)<00>_join<69>s 

z$Rule._compile_builder.<locals>._joincs$g|]\}}|r|<02>krt|<02><01>qSr()r<>)r<>r<>r<>)ror(r)r<><00>sz)Rule._compile_builder.<locals>.<listcomp>cSsg|] }t|<01><01>qSr()r<>)r<><00>kr(r(r)r<><00>sz def _(): passz<builder:{!r}><3E>argz.selfz.kwargsrk<00>linenor<00>
col_offsetrz<werkzeug routing>r<>)#ror<>r<><00>to_urlr0rr rgr<><00>_IF_KWARGS_URL_ENCODE_AST<53>extend<6E>_URL_ENCODE_AST_NAMESr<53>ZReturnr<6E>r<>r<>r<>rBr,r<>r2r<><00>kwargr<67>ZParamr<6D>r<>r<>r<><00> _attributesr<73>r<>r<>r<>)rP<00>append_unknownZdom_opsZurl_opsZoplr<6C>rEr<>Z dom_partsZ url_partsr<73>r<>ZpargsZkargsZfunc_astr<74><00>_<>moduler<65>rQr()r<>ror)r<>]sh
  

$
   

    zRule._compile_buildercCs:y |r|jf|<01>S|jf|<01>SWntk
r4dSXdS)z<>Assembles the relative url for that rule and the subdomain.
If building doesn't work for some reasons `None` is returned.
:internal:
N)r<>r<>rs)rPrZr<>r(r(r)<00>build<6C>s  z
Rule.buildcCs.|j o,|jo,|j|jko,||ko,|j|jkS)zNCheck if this rule has defaults for a given rule.
:internal:
)r<>rorYrc)rPrBr(r(r)<00>provides_defaults_for<6F>s
 zRule.provides_defaults_forcCs<>|dk r |jdk r ||jkr dS|jp(d}x"|jD]}||kr2||kr2dSq2W|r<>x,t|<03>D] \}}||kr\|||kr\dSq\WdS)z\Check if the dict of values has enough data for url generation.
:internal:
NFr(T)rdrorcr)rPrZr[rorfr&r(r(r)<00> suitable_for<6F>s


 zRule.suitable_forcCs(t|j<01>t|j<03> |jt|j<04> |jfS)a<>The match compare key for sorting.
Current implementation:
1. rules without any arguments come first for performance
reasons only as we expect them to match faster and some
common ones usually don't have any arguments (index pages etc.)
2. rules with more static parts come first so the second argument
is the negative length of the number of the static weights.
3. we order by static weights, which is a combination of index
and length
4. The more complex rules come first so the next argument is the
negative length of the number of argument weights.
5. lastly we order by the actual argument weights.
:internal:
)rarcr;r<>r<>)rPr(r(r)<00>match_compare_keys


zRule.match_compare_keycCs(|jr
dndt|j<02> t|jp d<03> fS)z?The build compare key for sorting.
:internal:
rrr()r<>r;rcro)rPr(r(r)<00>build_compare_keyszRule.build_compare_keycCs|j|jko|j|jkS)N)<02> __class__r<5F>)rP<00>otherr(r(r)<00>__eq__"sz Rule.__eq__cCs |<00>|<01> S)N)r<>)rPr<>r(r(r)<00>__ne__'sz Rule.__ne__cCs|jS)N)rB)rPr(r(r)rr*sz Rule.__str__cCs<>|jdkrd|jjSg}x0|jD]&\}}|r>|<01>d|<00>q"|<01>|<03>q"Wd|jjtd<04>|<01><01>d<05><01><01>d<06>|jdk r<>dd<08>|j<08>p<>d|j fS) Nz<%s (unbound)>z<%s>z<%s %s%s -> %s>rkr<><00>uz (%s)z, )
rgr<>rIr<>r0<00>reprrp<00>lstriprdrY)rP<00>tmpr<70>rEr(r(r)<00>__repr__-s
 z Rule.__repr__) NNNFNNNFN)F)N)T)T)N)rIrJrKrLrNrzr<>rvr<>r<>r<>r<>r<>r=<00> staticmethodr<64>r<>r<>r<>r<>r<>r<>r<><00>__hash__r<5F>rrrrr(r(r(r)r<>s>q


 :
0 
j

r<>c@s0eZdZdZdZdZdd<05>Zdd<07>Zdd <09>Zd
S) <0B> BaseConverterzBase class for all converters.z[^/]+<2B>dcCs
||_dS)N)rg)rPrgr(r(r)rNEszBaseConverter.__init__cCs|S)Nr()rPr&r(r(r)r<>HszBaseConverter.to_pythoncCs,t|ttf<02>rt|<01>Stt|<01><01>|jj<07><01>S)N)r<><00>bytes<65> bytearrayrr
<00>encodergr<>)rPr&r(r(r)r<>KszBaseConverter.to_urlN) rIrJrKrLr<>r<>rNr<>r<>r(r(r(r)r?s rc@seZdZdZddd<05>ZdS)<07>UnicodeConverteraThis converter is the default converter and accepts any string but
only one path segment. Thus the string can not include a slash.
This is the default validator.
Example::
Rule('/pages/<page>'),
Rule('/<string(length=2):lang_code>')
:param map: the :class:`Map`.
:param minlength: the minimum length of the string. Must be greater
or equal 1.
:param maxlength: the maximum length of the string.
:param length: the exact length of the string.
rNcCsVt<00>||<01>|dk r"dt|<04>}n&|dkr0d}nt|<03>}dt|<02>|f}d||_dS)Nz{%d}rkz{%s,%s}z[^/])rrNr#r<>)rPrgZ minlengthZ maxlength<74>lengthr(r(r)rNcs zUnicodeConverter.__init__)rNN)rIrJrKrLrNr(r(r(r)r
Qsr
c@seZdZdZdd<03>ZdS)<05> AnyConvertera3Matches one of the items provided. Items can either be Python
identifiers or strings::
Rule('/<any(about, help, imprint, class, "foo,bar"):page_name>')
:param map: the :class:`Map`.
:param items: this function accepts the possible items as positional
arguments.
cGs*t<00>||<01>dd<02>dd<04>|D<00><01>|_dS)Nz(?:%s)r<>cSsg|]}t<00>|<01><01>qSr()r<>r<>)r<>r<>r(r(r)r<>}sz)AnyConverter.__init__.<locals>.<listcomp>)rrNrpr<>)rPrg<00>itemsr(r(r)rN{s zAnyConverter.__init__N)rIrJrKrLrNr(r(r(r)r ps r c@seZdZdZdZdZdS)<05> PathConverterz<72>Like the default :class:`UnicodeConverter`, but it also matches
slashes. This is useful for wikis and similar applications::
Rule('/<path:wikipage>')
Rule('/<path:wikipage>/edit')
:param map: the :class:`Map`.
z[^/].*?<3F><>N)rIrJrKrLr<>r<>r(r(r(r)r<00>src@s:eZdZdZdZddd<07>Zdd <09>Zd
d <0B>Zed d <0A><00>Z dS)<0F>NumberConverterzKBaseclass for `IntegerConverter` and `FloatConverter`.
:internal:
<20>2rNFcCs4|r |j|_t<02>||<01>||_||_||_||_dS)N)<08> signed_regexr<78>rrN<00> fixed_digits<74>minri<00>signed)rPrgrrrirr(r(r)rN<00>s zNumberConverter.__init__cCsV|jrt|<01>|jkrt<02><00>|<00>|<01>}|jdk r8||jksL|jdk rR||jkrRt<02><00>|S)N)rr;rs<00> num_convertrri)rPr&r(r(r)r<><00>s
zNumberConverter.to_pythoncCs&|<00>|<01>}|jrd|j|}t|<01>S)Nz%%0%sd)rrr<>)rPr&r(r(r)r<><00>s
zNumberConverter.to_urlcCs
d|jS)Nz-?)r<>)rPr(r(r)r<00>szNumberConverter.signed_regex)rNNF)
rIrJrKrLr<>rNr<>r<><00>propertyrr(r(r(r)r<00>s 

rc@seZdZdZdZeZdS)<04>IntegerConvertera<72>This converter only accepts integer values::
Rule("/page/<int:page>")
By default it only accepts unsigned, positive values. The ``signed``
parameter will enable signed, negative values. ::
Rule("/page/<int(signed=True):page>")
:param map: The :class:`Map`.
:param fixed_digits: The number of fixed digits in the URL. If you
set this to ``4`` for example, the rule will only match if the
URL looks like ``/0001/``. The default is variable length.
:param min: The minimal value.
:param max: The maximal value.
:param signed: Allow signed (negative) values.
.. versionadded:: 0.15
The ``signed`` parameter.
z\d+N)rIrJrKrLr<>r#rr(r(r(r)r<00>src@s"eZdZdZdZeZddd<06>ZdS)<08>FloatConvertera<72>This converter only accepts floating point values::
Rule("/probability/<float:probability>")
By default it only accepts unsigned, positive values. The ``signed``
parameter will enable signed, negative values. ::
Rule("/offset/<float(signed=True):offset>")
:param map: The :class:`Map`.
:param min: The minimal value.
:param max: The maximal value.
:param signed: Allow signed (negative) values.
.. versionadded:: 0.15
The ``signed`` parameter.
z\d+\.\d+NFcCstj|||||d<01>dS)N)rrir)rrN)rPrgrrirr(r(r)rN<00>szFloatConverter.__init__)NNF)rIrJrKrLr<>r$rrNr(r(r(r)r<00>src@s$eZdZdZdZdd<04>Zdd<06>ZdS)<08> UUIDConverterz<72>This converter only accepts UUID strings::
Rule('/object/<uuid:identifier>')
.. versionadded:: 0.10
:param map: the :class:`Map`.
zK[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}cCs
t<00>|<01>S)N)<02>uuid<69>UUID)rPr&r(r(r)r<><00>szUUIDConverter.to_pythoncCst|<01>S)N)r<>)rPr&r(r(r)r<><00>szUUIDConverter.to_urlN)rIrJrKrLr<>r<>r<>r(r(r(r)r<00>sr)r8r<><00>anyrr#r$rc
@s`eZdZdZee<05>Zddd <09>Zd
d <0B>Zdd d <0A>Z dd<0F>Z
ddd<13>Z ddd<15>Z dd<17>Z dd<19>ZdS)<1E>Mapa<70>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: Take care of trailing slashes.
: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.
.. versionadded:: 0.5
`sort_parameters` and `sort_key` was added.
.. versionadded:: 0.7
`encoding_errors` and `host_matching` was added.
Nrk<00>utf-8TF<54>replacec Cs<>g|_i|_d|_t<03>|_||_||_| |_||_||_ |
|_
|j <0B> <0C>|_ |rZ|j <0A>|<06>||_||_x|pndD]} |<00>| <0B>qpWdS)NTr()rh<00>_rules_by_endpoint<6E>_remapr<00> _remap_lockr<6B>r<><00>encoding_errorsr<73>r<>r<><00>default_converters<72>copyr<79>r<>r<>r<>r@) rPryr<>r<>r<>r<>r<>r<>r<>r$r<>r{r(r(r)rN/s"   z Map.__init__cGs8|<00><00>t|<02>}x"|j|D]}|<02>|j<04>rdSqWdS)aQIterate 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.
TF)r<>r>r!rbrc)rPrYrcrBr(r(r)<00>is_endpoint_expectingRs  zMap.is_endpoint_expectingcCs(|<00><00>|dk rt|j|<00>St|j<03>S)z<>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
N)r<><00>iterr!rh)rPrYr(r(r)<00>
iter_rulesfszMap.iter_rulescCsJx>|<01>|<00>D]0}|<02>|<00>|j<02>|<02>|j<04>|jg<00><02>|<02>q Wd|_dS)z<>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`
TN)rvr<>rhr0r!<00>
setdefaultrYr")rPr{rBr(r(r)r@rs

 zMap.add<64>httpr<70>c Cs<>|<01><00>}|jr |dk r.td<02><01>n|dkr.|j}|dkr:d}|dkrFd}y t|<01>}Wntk
rlt<06><00>YnXt||||||||<07>S)a>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.
.. versionadded:: 0.7
`query_args` added
.. versionadded:: 0.8
`query_args` can now also be a string.
.. versionchanged:: 0.15
``path_info`` defaults to ``'/'`` if ``None``.
Nz2host matching enabled and a subdomain was providedr})<08>lowerr<72>r<>r<>r<00> UnicodeErrorr<00>
MapAdapter)rP<00> server_name<6D> script_namerx<00>
url_scheme<EFBFBD>default_method<6F> path_info<66>
query_argsr(r(r)r<>~s.#
  zMap.bindc
s<>t<00><00><01>t<01><00><01><02>}|dkr"|}n|<02><02>}|dkr<><72>js<>|<04>d<02>}|<02>d<02>}t|<06> }||d<01>|krld}nd<02>td|d|<07><00><02>}<03><00>fdd<05>}|d<06>} |d<07>}
|d<08>} tj <09>|| |<03>d <00>d
|
| d <0B>S) a<>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:: 0.5
previously this method accepted a bogus `calculate_subdomain`
parameter that did not have any effect. It was removed because
of that.
.. versionchanged:: 0.8
This will no longer raise a ValueError when an unexpected server
name was passed.
:param environ: a WSGI environment.
:param server_name: an optional server name hint (see above).
:param subdomain: optionally the current subdomain (see above).
Nrjz <invalid>cs"<00><00>|<00>}|dk rt|<01>j<02>SdS)N)<03>getr r<>)r,<00>val)rRrPr(r)<00>_get_wsgi_string<6E>s
z-Map.bind_to_environ.<locals>._get_wsgi_stringZ SCRIPT_NAMEZ PATH_INFO<46> QUERY_STRINGzwsgi.url_scheme<6D>REQUEST_METHOD)r4)
rrr,r<>r<>r;rp<00>filterrr<>) rPrRr/rxZwsgi_server_nameZcur_server_nameZreal_server_name<6D>offsetr7r0r3r4r()rRrPr)<00>bind_to_environ<6F>s2" 


zMap.bind_to_environc Csf|js
dS|j<01>L|jsdS|jjdd<03>d<04>x"t|j<05>D]}|jdd<03>d<04>q:Wd|_WdQRXdS)zzCalled before matching and building to keep the compiled rules
in the correct order after things changed.
NcSs|<00><00>S)N)r<>)r<>r(r(r)<00><lambda><00>zMap.update.<locals>.<lambda>)rfcSs|<00><00>S)N)r<>)r<>r(r(r)r=r>F)r"r#rhr<>rr!)rPryr(r(r)r<>sz
Map.updatecCs |<00><00>}d|jjtt|<01><01>fS)Nz%s(%s))r)r<>rIrr<>)rPryr(r(r)rsz Map.__repr__)
NrkrTTNFNr F)N)NNr+r<>NN)NN)rIrJrKrLr<00>DEFAULT_CONVERTERSr%rNr'r)r@r<>r<r<>rr(r(r(r)r
s0 


4
Lrc@s~eZdZdZddd<04>Zddd<07>Zddd <09>Zd d
d <0B>Zd!d d <0A>Zdd<0F>Z dd<11>Z
dd<13>Z d"dd<15>Z dd<17>Z dd<19>Zd#dd<1C>ZdS)$r.z<>Returned by :meth:`Map.bind` or :meth:`Map.bind_to_environ` and does
the URL matching and building based on runtime information.
Nc Csb||_t|<02>|_t|<03>}|<03>d<01>s*|d7}||_t|<04>|_t|<05>|_t|<06>|_t|<07>|_||_ dS)Nr})
rgr r/r<>r0rxr1r3r2r4) rPrgr/r0rxr1r3r2r4r(r(r)rN!s 





zMapAdapter.__init__Fc
CstyBy|<00>||<03>\}}Wn"tk
r8}z|Sd}~XYnX|||<06>Stk
rn}z|r\|S<00>Wdd}~XYnXdS)a3Does the complete dispatching process. `view_func` is called with
the endpoint and a dict with the values for the view. It should
look up the view function, call it, and return a response object
or WSGI application. http exceptions are not caught by default
so that applications can display nicer error messages by just
catching them by hand. If you want to stick with the default
error messages you can pass it ``catch_http_exceptions=True`` and
it will catch the http exceptions.
Here a small example for the dispatch usage::
from werkzeug.wrappers import Request, Response
from werkzeug.wsgi import responder
from werkzeug.routing import Map, Rule
def on_index(request):
return Response('Hello from the index')
url_map = Map([Rule('/', endpoint='index')])
views = {'index': on_index}
@responder
def application(environ, start_response):
request = Request(environ)
urls = url_map.bind_to_environ(environ)
return urls.dispatch(lambda e, v: views[e](request, **v),
catch_http_exceptions=True)
Keep in mind that this method might return exception objects, too, so
use :class:`Response.force_type` to get a response object.
:param view_func: a function that is called with the endpoint as
first argument and the value dict as second. Has
to dispatch to the actual view function with this
information. (see above)
:param path_info: the path info to use for matching. Overrides the
path info specified on binding.
:param method: the HTTP method used for matching. Overrides the
method specified on binding.
:param catch_http_exceptions: set to `True` to catch any of the
werkzeug :class:`HTTPException`\s.
N)r=rMr)rPZ view_funcr3r[Zcatch_http_exceptionsrYr2<00>er(r(r)<00>dispatch8s-
zMapAdapter.dispatchc
s$|j<00><01>|dkr|j}nt||jj<04>}|dkr6|j}|p>|j<06><07>}d|jjrT|j pX|j
|ohd|<01> d<04>f}t <0C>}<06>x<>|jj D<00>]<5D><>y<10><00>||<02><02>Wnrtk
r<EFBFBD>t|<00>t||jjdd<06>d|<04><02><01>Yn>tk
<EFBFBD>r}zt|<00>|<05>j|j||<04><05><01>Wdd}~XYnX<00>dk<08>rq<><71>jdk <09>r<|<02>jk<07>r<|<06><01>j<17>q<>|jj<18>rh|<00><19>|<02>|<04>}|dk <09>rht|<08><01><01>jdk <09>r<>t<1B>jt<1C><02>r<><72><00>fdd<08>} t<1D>| <09>j<1A>}n<0E>j|f<01><01>}ttt d |j!<21>p<>d
|j
<EFBFBD>r<>|j
d nd |j |j"f|<08><02><01><01>|<03>r<><72><00>fS<00>j<15>fSq<>W|<06>rt#t$|<06>d <0A><01>t%<25><00>dS)a
The usage is simple: you just pass the match method the current
path info as well as the method (which defaults to `GET`). The
following things can then happen:
- you receive a `NotFound` exception that indicates that no URL is
matching. A `NotFound` exception is also a WSGI application you
can call to get a default page not found page (happens to be the
same object as `werkzeug.exceptions.NotFound`)
- you receive a `MethodNotAllowed` exception that indicates that there
is a match for this URL but not for the current request method.
This is useful for RESTful applications.
- you receive a `RequestRedirect` exception with a `new_url`
attribute. This exception is used to notify you about a request
Werkzeug requests from your WSGI application. This is for example the
case if you request ``/foo`` although the correct URL is ``/foo/``
You can use the `RequestRedirect` instance as response-like object
similar to all other subclasses of `HTTPException`.
- you get a tuple in the form ``(endpoint, arguments)`` if there is
a match (unless `return_rule` is True, in which case you get a tuple
in the form ``(rule, arguments)``)
If the path info is not passed to the match method the default path
info of the map is used (defaults to the root URL if not defined
explicitly).
All of the exceptions raised are subclasses of `HTTPException` so they
can be used as WSGI responses. They will all render generic error or
redirect pages.
Here is a small example for matching:
>>> m = Map([
... Rule('/', endpoint='index'),
... Rule('/downloads/', endpoint='downloads/index'),
... Rule('/downloads/<int:id>', endpoint='downloads/show')
... ])
>>> urls = m.bind("example.com", "/")
>>> urls.match("/", "GET")
('index', {})
>>> urls.match("/downloads/42")
('downloads/show', {'id': 42})
And here is what happens on redirect and missing URLs:
>>> urls.match("/downloads")
Traceback (most recent call last):
...
RequestRedirect: http://example.com/downloads/
>>> urls.match("/missing")
Traceback (most recent call last):
...
NotFound: 404 Not Found
:param path_info: the path info to use for matching. Overrides the
path info specified on binding.
:param method: the HTTP method used for matching. Overrides the
method specified on binding.
:param return_rule: return the rule that matched instead of just the
endpoint (defaults to `False`).
:param query_args: optional query arguments that are used for
automatic redirects as string or dictionary. It's
currently not possible to use the query arguments
for URL matching.
.. versionadded:: 0.6
`return_rule` was added.
.. versionadded:: 0.7
`query_args` was added.
.. versionchanged:: 0.8
`query_args` can now also be a string.
Nz%s|%sz/%sr}z/:|+)r<>cs$<00>|<00>d<01>}<01>j|<00>d<01><00>|<01>S)Nr)r/r<>r<>)r=r&)rB<00>rvr(r)<00> _handle_match<63>sz'MapAdapter.match.<locals>._handle_matchz %s://%s%s%sr+rjrk)<01> valid_methods)&rgr<>r3r r<>r4r2r<>r<>r/rxrr>rhr=rTrM<00>make_redirect_urlrrU<00>make_alias_redirect_urlrYrVrdr<><00>get_default_redirectr<74>r<>r <00>_simple_rule_re<72>subr<62>rr1r0rr<>r)
rPr3r[Z return_ruler4rZhave_match_forr@Z redirect_urlrCr()rBrBr)r=pshM
 &
 

 

zMapAdapter.matchcCs<y|<00>||<02>Wn&tk
r$Yntk
r6dSXdS)a<>Test if a rule would match. Works like `match` but returns `True`
if the URL matches, or `False` if it does not exist.
:param path_info: the path info to use for matching. Overrides the
path info specified on binding.
:param method: the HTTP method used for matching. Overrides the
method specified on binding.
FT)r=rMr)rPr3r[r(r(r)<00>test s zMapAdapter.testc
CsNy|j|dd<02>Wn6tk
r6}z|jSd}~XYntk
rHYnXgS)z^Returns the valid methods that match for a given path.
.. versionadded:: 0.7
z--)r[N)r=rrDr)rPr3r@r(r(r)<00>allowed_methodsszMapAdapter.allowed_methodscCsT|jjr |dkr|jSt|d<02>S|}|dkr4|j}n
t|d<02>}|rJ|dnd|jS)z<>Figures out the full host name for the given domain part. The
domain part is a subdomain in case host matching is disabled or
a full host name.
N<>asciirjrk)rgr<>r/r rx)rP<00> domain_partrxr(r(r)r's

zMapAdapter.get_hostcCsr|jjs t<02>x`|jj|jD]N}||kr*P|<05>|<01>r|<05>||<02>r|<03>|j<08>|<05> |<03>\}}|j
|||d<01>SqWdS)z<>A helper that returns the URL to redirect to if it finds one.
This is used for default redirecting only.
:internal:
)rMN) rgr<>r<>r!rYr<>r<>r<>ror<>rE)rPrBr[rZr4<00>rrMrr(r(r)rG7s  zMapAdapter.get_default_redirectcCst|t<01>st||jj<04>}|S)N)r<>r rrgr<>)rPr4r(r(r)<00>encode_query_argsIs
zMapAdapter.encode_query_argsc
CsTd}|rd|<00>|<02>}td|jp"d|<00>|<03>t<04>|jdd<06><00>d<07>|<01>d<07><01>|f<00>S)z4Creates a redirect URL.
:internal:
rk<00>?z %s://%s/%s%sr+Nr!r})rOr<>r1r<00> posixpathrpr0r)rPr3r4rM<00>suffixr(r(r)rENszMapAdapter.make_redirect_urlcCs>|j|||ddd<03>}|r*|d|<00>|<05>7}||ks:td<05><01>|S)z0Internally called to make an alias redirect URL.FT)r<><00>force_externalrPz6detected invalid alias setting. No canonical URL found)r<>rOr<>)rPrrYrZr[r4<00>urlr(r(r)rFbs z"MapAdapter.make_alias_redirect_urlcCsh|dkr&|<00>|||j|<04>}|dk r&|Sx<|jj<03>|d<02>D](}|<06>||<03>r8|<06>||<04>}|dk r8|Sq8WdS)z<>Helper for :meth:`build`. Returns subdomain and path for the
rule that accepts this endpoint, values and method.
:internal:
Nr()<07>_partial_buildr2rgr!r5r<>r<>)rPrYrZr[r<>rBrBr(r(r)rUls  zMapAdapter._partial_buildTc Cs2|j<00><01>|r~t|t<03>rfi}xBtt|<02>D]4\}}|s6q(t|<08>dkrT|d}|dkrTq(|||<q(W|}q<>tdd<05>t|<02>D<00><01>}ni}|<00>||||<05>} | dkr<>t||||<00><04>| \}
} |<00> |
<EFBFBD>} |s<>|jj
r<EFBFBD>| |j ks<>|jj
s<EFBFBD>|
|j kr<>d|j <0A>d<07>| <0B>d<07>fStd|j<11>r|jd nd
| |j dd <0B>| <0B>d<07>f<00>S) a<> Building URLs works pretty much the other way round. Instead of
`match` you call `build` and pass it the endpoint and a dict of
arguments for the placeholders.
The `build` function also accepts an argument called `force_external`
which, if you set it to `True` will force external URLs. Per default
external URLs (include the server name) will only be used if the
target URL is on a different subdomain.
>>> m = Map([
... Rule('/', endpoint='index'),
... Rule('/downloads/', endpoint='downloads/index'),
... Rule('/downloads/<int:id>', endpoint='downloads/show')
... ])
>>> urls = m.bind("example.com", "/")
>>> urls.build("index", {})
'/'
>>> urls.build("downloads/show", {'id': 42})
'/downloads/42'
>>> urls.build("downloads/show", {'id': 42}, force_external=True)
'http://example.com/downloads/42'
Because URLs cannot contain non ASCII data you will always get
bytestrings back. Non ASCII characters are urlencoded with the
charset defined on the map instance.
Additional values are converted to unicode and appended to the URL as
URL querystring parameters:
>>> urls.build("index", {'q': 'My Searchstring'})
'/?q=My+Searchstring'
When processing those additional values, lists are furthermore
interpreted as multiple values (as per
:py:class:`werkzeug.datastructures.MultiDict`):
>>> urls.build("index", {'q': ['a', 'b', 'c']})
'/?q=a&q=b&q=c'
Passing a ``MultiDict`` will also add multiple values:
>>> urls.build("index", MultiDict((('p', 'z'), ('q', 'a'), ('q', 'b'))))
'/?p=z&q=a&q=b'
If a rule does not exist when building a `BuildError` exception is
raised.
The build method accepts an argument called `method` which allows you
to specify the method you want to have an URL built for if you have
different methods for the same endpoint specified.
.. versionadded:: 0.6
the `append_unknown` parameter was added.
:param endpoint: the endpoint of the URL to build.
:param values: the values for the URL to build. Unhandled values are
appended to the URL as query parameters.
:param method: the HTTP method for the rule if there are different
URLs for different methods on the same endpoint.
:param force_external: enforce full canonical external URLs. If the URL
scheme is not provided, this will generate
a protocol-relative URL.
:param append_unknown: unknown parameters are appended to the generated
URL as query string argument. Disable this
if you want the builder to ignore those.
rrNcss|]}|ddk r|VqdS)rNr()r<><00>ir(r(r)<00> <genexpr><3E>sz#MapAdapter.build.<locals>.<genexpr>z%s/%sr}z %s//%s%s/%s<>:rkr!)rgr<>r<>rrr<>r;rUrWrr<>r/rxr0r~rr<>r1) rPrYrZr[rSr<>Z temp_valuesrfr&rBrMrr<>r(r(r)r<><00>s<J

  
 zMapAdapter.build)N)NNF)NNFN)NN)N)NN)NNFT)rIrJrKrLrNrAr=rJrKrrGrOrErFrUr<>r(r(r(r)r.s"

7




r.)UrLr<>r`rQr<>r<00>pprintr<00> threadingr<00>_compatrrrrr r
r r r <00> _internalrrZdatastructuresrr<00>
exceptionsrrrr<00>urlsrrrr<00>utilsrrrZwsgirr<><00>VERBOSEr<rHr<>r-r"r*r5rG<00> ExceptionrHrMrTrUrXrWr%rs<00>objectrtrwr|r<>r<>r<>r<>r<>Z_IF_KWARGS_URL_ENCODE_CODEr<45>r<>r<>rr
r rrrrrr?rr.r(r(r(r)<00><module>as<>                            
     
; %  B&