/usr/local/lib/python3.6/site-packages/werkzeug/__pycache__
NameSizeModeActions
datastructures.cpython-36.pyc1077480644editdlrm
exceptions.cpython-36.pyc306390644editdlrm
filesystem.cpython-36.pyc20250644editdlrm
formparser.cpython-36.pyc138140644editdlrm
http.cpython-36.pyc379050644editdlrm
local.cpython-36.pyc226910644editdlrm
routing.cpython-36.pyc729310644editdlrm
security.cpython-36.pyc80400644editdlrm
serving.cpython-36.pyc304780644editdlrm
test.cpython-36.pyc389610644editdlrm
testapp.cpython-36.pyc95490644editdlrm
urls.cpython-36.pyc364140644editdlrm
useragents.cpython-36.pyc74170644editdlrm
user_agent.cpython-36.pyc17200644editdlrm
utils.cpython-36.pyc329600644editdlrm
wsgi.cpython-36.pyc301020644editdlrm
_internal.cpython-36.pyc182680644editdlrm
_reloader.cpython-36.pyc118990644editdlrm
__init__.cpython-36.pyc3100644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/werkzeug/__pycache__/routing.cpython-36.pyc (72931B)
3 _TBgeJ@s&UdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl m#Z#ddl m$Z$ddl m%Z%ddl&m'Z'ddl&m(Z(ddl)m*Z*ej+rddl,Z-ddl.m/Z/ddl.m0Z0ddl1m2Z2ddl3m4Z4ej5d ej6Z7ej5d!Z8ej5d"ej6Z9dd#d$d%Z:e;eje?e;fd&d'd(Z@e;ejAejAejBe;ejCffd)d*d+ZDe;ejEejAejFe;ejFe;e;fd,d-d.ZGGd/d0d0eHZIGd1d2d2eeIZJGd3d4d4eIZKGd5d6d6eIZLGd7d8d8eIeMZNGd9d:d:eZOGd;d<dd>ZRGd?d@d@eRZSGdAdBdBeRZTGdCdDdDeRZUGdEdFdFZVGdGdHdHeRZWe;ejXdIdJdKZYdLZZdMZ[eYe[Z\eYdNeYdOfZ]GdPdQdQeRZ^GdRdSdSZ_GdTdUdUe_Z`GdVdWdWe_ZaGdXdYdYe_ZbGdZd[d[e_ZcGd\d]d]ecZdGd^d_d_ecZeGd`dadae_Zfe`e`eaebedeeefdbZgejhe;ejie_fgGdcddddZjGdedfdfZkdS)gaq 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 a URL map for an application with two subdomains (www and kb) and some URL rules: .. code-block:: python 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//', endpoint='kb/browse'), Rule('/browse//', 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: .. code-block:: python 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: .. code-block:: python 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: .. code-block:: python 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 ``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`` but routing tried to match a ``POST`` request) a ``MethodNotAllowed`` exception is raised. N)pformat)Template)Lock)CodeType) _encode_idna) _get_environ) _to_bytes)_to_str)_wsgi_decoding_dance) ImmutableDict) MultiDict)BadHost) BadRequest) HTTPException)MethodNotAllowed)NotFound)_fast_url_quote) url_encode)url_join) url_quote) url_unquote)cached_property)redirect)get_host)WSGIApplication)WSGIEnvironment)Request)Responseao (?P[^<]*) # static rule data < (?: (?P[a-zA-Z_][a-zA-Z0-9_]*) # converter name (?:\((?P.*?)\))? # converter arguments \: # variable delimiter )? (?P[a-zA-Z_][a-zA-Z0-9_]*) # variable name > z <([^>]+)>z ((?P\w+)\s*=\s*)? (?P True|False| \d+.\d+| \d+.| \d+| [\w\d_.]+| [urUR]?(?P"[^"]*?"|'[^']*') )\s*, TF)NoneTrueFalse)valuereturnc Csx|tkrt|Sx.ttfD]"}y||Stk r:YqXqW|dd|ddkrp|ddkrp|dd}t|S)Nrrz"'r$)_PYTHON_CONSTANTSintfloat ValueErrorstr)r"convertr+4/tmp/pip-build-0s3hx122/Werkzeug/werkzeug/routing.py _pythonizes $ r-)argstrr#cCs||d7}g}i}x^tj|D]P}|jd}|dkr<|jd}t|}|jdsZ|j|q|jd}|||<qWt||fS)N,Z stringvalr"name)_converter_args_refinditergroupr-appendtuple)r.argskwargsitemr"r0r+r+r,parse_converter_argss      r9)ruler#c csd}t|}tj}t}x||kr|||}|dkr6P|j}|drVdd|dfV|d}|dphd}||krtd|d|j|||d pd|fV|j}qW||kr||d} d | ksd | krtd |dd| fVdS) zParse 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: rNZstaticvariable converterdefaultzvariable name z used twice.r6>._score_rule)key)r'map_rulesmax)rUrlrvr+)rUr,rn<s zBuildError.closest_rulecCsd|jg}|jr(|jd|jd|jrD|jdt|j|jd|jr|j|jjkr|jr|jjdk r|j|jjkr|jdt|jjd|jjjt |jj pft |jj }|r|jdt|dn|jd |jjd d j |S) Nz!Could not build url for endpoint z ()z with values .z Did you mean to use methods ?z" Did you forget to specify values z Did you mean z instead?) rirkr4rjsortedrorurtunionrCdefaultskeysjoin)rUmessageZmissing_valuesr+r+r,__str__Ns*  zBuildError.__str__)N)rMrNrOrPr)r[rerfr\rTrrornrr_r+r+)rVr,rg&s"rgc@seZdZdZdS)WebsocketMismatchzThe only matched rule is either a WebSocket and the request is HTTP, or the rule is HTTP and the request is a WebSocket. N)rMrNrOrPr+r+r+r,rlsrc@seZdZdZdS)ValidationErrorzValidation error. If a rule converter raises this exception the rule does not match the current URL and the next URL is tried. N)rMrNrOrPr+r+r+r,rrsrc@s&eZdZdZdejddddZdS) RuleFactoryzAs 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`. Maprm)rxr#cCs tdS)zaSubclasses of `RuleFactory` have to override this method and return an iterable of rules.N)NotImplementedError)rUrxr+r+r, get_rules~szRuleFactory.get_rulesN)rMrNrOrPr[Iterablerr+r+r+r,rxsrc@s>eZdZdZeejeddddZdej ddd d Z dS) SubdomainaAll 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('', [ 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. N) subdomainrulesr#cCs||_||_dS)N)rr)rUrrr+r+r,rTszSubdomain.__init__rrm)rxr#ccs>x8|jD].}x(|j|D]}|j}|j|_|VqWqWdS)N)rremptyr)rUrx rulefactoryr:r+r+r,rs  zSubdomain.get_rules) rMrNrOrPr)r[rrrTIteratorrr+r+r+r,rsrc@s>eZdZdZeejeddddZdej ddd d Z dS) 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/', endpoint='blog/show') ]) ]) Now the rule ``'blog/show'`` matches ``/blog/entry/``. N)pathrr#cCs|jd|_||_dS)N/)rstriprr)rUrrr+r+r,rTs zSubmount.__init__rrm)rxr#ccsDx>|jD]4}x.|j|D] }|j}|j|j|_|VqWqWdS)N)rrrrr:)rUrxrr:r+r+r,rs  zSubmount.get_rules) rMrNrOrPr)r[rrrTrrr+r+r+r,rs rc@s>eZdZdZeejeddddZdej ddd d Z dS) EndpointPrefixaPrefixes 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/', endpoint='show') ])]) ]) N)prefixrr#cCs||_||_dS)N)rr)rUrrr+r+r,rTszEndpointPrefix.__init__rrm)rxr#ccsDx>|jD]4}x.|j|D] }|j}|j|j|_|VqWqWdS)N)rrrrri)rUrxrr:r+r+r,rs  zEndpointPrefix.get_rules) rMrNrOrPr)r[rrrTrrr+r+r+r,rs rc@s<eZdZdZejdddddZejejddd d ZdS) 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/', 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. rmN)rr#cCst||_dS)N)listr)rUrr+r+r,rTszRuleTemplate.__init__RuleTemplateFactory)r6r7r#cOst|jt||S)N)rrr^)rUr6r7r+r+r,__call__szRuleTemplate.__call__) rMrNrOrPr[rrTrfrr+r+r+r,rsrc@sJeZdZdZejeejeej fddddZ dej ddd d Z dS) rzsA factory that fills in template variables into rules. Used by `RuleTemplate` internally. :internal: N)rcontextr#cCs||_||_dS)N)rr)rUrrr+r+r,rTszRuleTemplateFactory.__init__rrm)rxr#c csx|jD]}x|j|D]}d}}|jrhi}x8|jjD]*\}}t|tr\t|j|j}|||<q:W|j dk rt|j j|j}|j }t|trt|j|j}t t|j j|j|||j |j||jVqWqWdS)N)rrritems isinstancer)r substituterrrirmr:ru build_onlystrict_slashes) rUrxrr:Z new_defaultsrrwr"Z new_endpointr+r+r,rs,     zRuleTemplateFactory.get_rules) rMrNrOrPr[rrDictr)rfrTrrr+r+r+r,rsr)srcr#cCsTtj|jd}t|tjr"|j}x,tj|D]}t|tjr.d|j|_q.W|S)zEast parse and prefix names with `.` to avoid collision with user varsrr|) astparsebodyrZExprr"walkNameid)rtreenoder+r+r, _prefix_namess  rz#self._converters[{elem!r}].to_url()z^if kwargs: q = '?' params = self._encode_query_vars(kwargs) else: q = params = '' qparamsc@seZdZdZd=eejejeejfejeejej ee ejeeje eje ejej eej deffe ejee dd ddZ ddd d Zejeejfdd d Zd ejddddZddddZd>d e ddddZeeejejeejfddddZejeejfedddZddddZd?eejeejejeejfdd d!Zeeeej dejeeffd"d#d$Zd@e ej dejeeffd&d'd(ZdAejeejfe ejejeefd)d*d+Zde d,d-d.ZdBejeejfejee d/d0d1Z eje e!ej eje!e!fe!ej e!fdd2d3Z"eje!e!e!fdd4d5Z#e$e d6d7d8Z%dZ&edd9d:Z'edd;d<Z(dS)CrmaA 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 ```` 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/', 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='', endpoint='user/homepage'), Rule('/stats', subdomain='', 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. `strict_slashes` Override the `Map` setting for `strict_slashes` only for this rule. If not specified the `Map` setting is used. `merge_slashes` Override :attr:`Map.merge_slashes` for this rule. `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 f'foo/{Foo.get_slug_for_id(id)}' url_map = Map([ Rule('/foo/', endpoint='foo'), Rule('/some/old/url/', redirect_to='foo/'), Rule('/other/old/url/', 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. `websocket` If ``True``, this rule is only matches for WebSocket (``ws://``, ``wss://``) requests. By default, rules will only match for HTTP requests. .. versionadded:: 1.0 Added ``websocket``. .. versionadded:: 1.0 Added ``merge_slashes``. .. versionadded:: 0.7 Added ``alias`` and ``host``. .. versionchanged:: 0.6.1 ``HEAD`` is added to ``methods`` if ``GET`` is present. NF.) stringrrrurrir merge_slashes redirect_toaliashost websocketr#c Cs|jdstd||_|jd |_d|_||_||_||_| |_ ||_ ||_ | |_ | |_ |dk rt|trvtddd|D}d|krd|kr|jd| r|dddhrtd ||_||_| |_|rttt||_nt|_g|_dS) Nrz$urls must start with a leading slashz&'methods' should be a list of strings.cSsh|] }|jqSr+)upper).0xr+r+r, sz Rule.__init__..HEADGETOPTIONSzBWebSocket rules can only use 'GET', 'HEAD', and 'OPTIONS' methods.) startswithr(r:endswithis_leafrxrrrrrrrrrr) TypeErrorrErurirrCrt_trace) rUrrrrurrirrrrrrr+r+r,rTs:   z Rule.__init__)r#cCst||jf|jS)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. )typer:get_empty_kwargs)rUr+r+r,rsz Rule.emptyc Cs>d}|jrt|j}t||j|j|j|j|j|j|j|j d 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) rrrurrirrrr) rr^rrurrirrrr)rUrr+r+r,rs  zRule.get_empty_kwargsr)rxr#ccs |VdS)Nr+)rUrxr+r+r,rszRule.get_rulescCs|j|jdddS)zqRebinds and refreshes the URL. Call this if you modified the rule in place. :internal: T)rebindN)bindrx)rUr+r+r,refresh sz Rule.refresh)rxrr#cCsn|jdk r&| r&td|d|j||_|jdkr>|j|_|jdkrP|j|_|jdkrb|j|_|jdS)zBind 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 z already bound to map )rx RuntimeErrorrrrdefault_subdomaincompile)rUrxrr+r+r,rs   z Rule.bind BaseConverter) variable_nameconverter_namer6r7r#cCs6||jjkrtd|d|jj||jf||S)zWLooks up the converter for the given parameter. .. versionadded:: 0.9 zthe converter z does not exist)rx converters LookupError)rUrrr6r7r+r+r, get_converter"s zRule.get_converter) query_varsr#cCst||jj|jj|jjdS)N)charsetsortrw)rrxrsort_parameterssort_key)rUrr+r+r,_encode_query_vars1s zRule._encode_query_varscs>jdk stdjjr&jp"d}n jp.d}g_i_g_g_gt ddfdd }||j djj d|j rj n j j d j sjj djdjd_jd jd_jrdSj ojsjrd nd }d|d}nd}ddj|d}tj|_dS)z.Compiles the regular expression and stores it.Nzrule not boundr~)r:r#c sPd}xDt|D]6\}}}|dkrxtjd|D]}|jd}|jdrjrhjdjjd q2j|jjd|fq2jjd|fjtj||r2j j|t | fq2Wn||rt |\}}nf}i}j ||||} jd|d| j d| j|<jjd |fjj| jjjt||d }qWdS) Nrz/+|[^/]+rz/+?Fz(?Pr{Tr)Fr)rKrer2r3rrr4rescape_static_weightsr@r9rregex _converters_argument_weightsweightrtrEr)) r:indexr<rtr;rBpartZc_argsZc_kwargsZconvobj) regex_partsrUr+r, _build_regexHs6     z"Rule.compile.._build_regexz\|F|rT*r}z(?/r{^$)Fr)Fr)rxAssertionError host_matchingrrrrrrr)r4rr:r_compile_builder__get___build_build_unknownrrrrrr_regex)rUZ domain_rulerZrepstailrr+)rrUr,r9s:        z Rule.compile)rrkr#c Csz|jsvd}|jj|}|dk rv|j}|jrn|j rn|jd rn|dks`|jdks`||jkrn|d7}d}n |jsz|d=i}xJ|jD]>\}}y|j |j |}Wnt k rdSX||t |<qW|j r|j|j |jr:dj|j|d} |jdr| jd r| d7} | jd|jdkr:t| }d}|rX|jddd}t||jrr|jjrrt||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: FNZ __suffix__rTrr)rrsearchrDrrpoprurr to_pythonrr)rupdaterrbuildrcountrsplitr`rrxredirect_defaultsrc) rUrrkrequire_redirectrHgroupsresultr0r"new_pathr+r+r,rBsH     z Rule.match)rYr0r#cCsi}i}t|||||S)N)exec)rYr0ZglobsZlocsr+r+r,_get_func_codes zRule._get_func_codeT)append_unknownr#csl|jpig}g}|}x|jD]\}}|dkr<||kr<|}q|rl|krl|j|j|}|jd|fq|s|jdtt||jjddfq|jd|fqWt t j dddt j t jtt ft j t jd fd d }||}||} |sg} ntg} | jtt j t jt jd d d} | jt jt j| || | gt jfdd||D} ddD} td}d|jd|_|jjjt jddx(| | D]}|jjjt j|dqWt jdd|j_x"| D]}|jjjt jdqW| |_t jd}|g|_x8t j|D]*}d|j kr:d|_!d|j kr$d|_"q$Wt#|dd}|j$||jS)NrFz/:|+)safeT)elemr#cSs,ttj|d}tjt|tjg|_|S)N)r)r_CALL_CONVERTER_CODE_FMTformatrrr)Loadr6)rretr+r+r,_convertsz'Rule._compile_builder.._convert)opsr#csfdd|D}|p tjdg}|dg}xV|ddD]F}t|tjrvt|dtjrvtj|dj|j|d<q:|j|q:W|S) Ncs(g|] \}}|r|n tj|dqS))s)rStr)r is_dynamicr)rr+r, sz9Rule._compile_builder.._parts..r~rrr$r$r$)rrrrr4)rpartsrp)rr+r,_partss  z%Rule._compile_builder.._parts)rr#cSst|dkr|dStj|S)Nrr)r@rZ JoinedStr)rr+r+r,_joins z$Rule._compile_builder.._joincs g|]\}}|r|kr|qSr+r+)rrr)rr+r,rsz)Rule._compile_builder..cSsg|] }t|qSr+)r))rkr+r+r,rsz def _(): passz z.selfz.kwargsr~linenor col_offsetrzr)%rrrto_urlr4rr rxrr)rstmtr[ZListTuplerrAST_IF_KWARGS_URL_ENCODE_ASTextend_URL_ENCODE_AST_NAMESZReturnrrr:r0r6argZkwargrrrr _attributesr rrr)rUrZdom_opsZurl_opsZoplrrIr Z dom_partsZ url_partsrr ZpargsZkargsZfunc_astr_modulerrYr+)rrr,rs^  , $        zRule._compile_builder)rjrr#c Cs:y |r|jf|S|jf|SWntk r4dSXdS)zAssembles the relative url for that rule and the subdomain. If building doesn't work for some reasons `None` is returned. :internal: N)rrr)rUrjrr+r+r,r/s  z Rule.build)r:r#cCs2t|j o.|jo.|j|jko.||ko.|j|jkS)zNCheck if this rule has defaults for a given rule. :internal: )rrrrrirt)rUr:r+r+r,provides_defaults_for?s  zRule.provides_defaults_for)rjrkr#cCs|dk r |jdk r ||jkr dS|jp(f}x"|jD]}||kr2||kr2dSq2W|rx,|jD] \}}||kr\|||kr\dSq\WdS)z\Check if the dict of values has enough data for url generation. :internal: NFT)rurrtr)rUrjrkrrwr"r+r+r, suitable_forLs     zRule.suitable_forcCs(t|jt|j |jt|j |jfS)aThe 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: )rrrtr@rr)rUr+r+r,match_compare_keyms   zRule.match_compare_keycCs(|jr dndt|j t|jp f fS)z?The build compare key for sorting. :internal: rr)rr@rtr)rUr+r+r,build_compare_keyszRule.build_compare_key)otherr#cCst|t|o|j|jkS)N)rrr)rUrr+r+r,__eq__sz Rule.__eq__cCs|jS)N)r:)rUr+r+r,rsz Rule.__str__cCs|jdkrdt|jdSg}x4|jD]*\}}|rH|jd|dq(|j|q(Wdj|jd}|jdk rddj|jdnd}dt|jd ||d |jdS) Nr?z (unbound)>r>r~rz (z, r{ z -> ) rxrrMrr4rlstripruri)rUrrrIrur+r+r,__repr__s "z Rule.__repr__) NNNFNNNNFNF)F)N)T)T)N))rMrNrOrPr)r[r\rerfrrrr]CallablerTrrrrrrrrrrMutableMappingrB staticmethodrrrrrrr&rrobjectr__hash__rr"r+r+r+r,rm.sTzp)  J  D("_!4rmc@sTeZdZdZdZdZdejejddddZe ejd d d Z eje d d d Z dS)rzBase class for all converters.z[^/]+drN)rxr6r7r#cOs ||_dS)N)rx)rUrxr6r7r+r+r,rTszBaseConverter.__init__)r"r#cCs|S)Nr+)rUr"r+r+r,rszBaseConverter.to_pythoncCs,t|ttfrt|Stt|j|jjS)N)rbytes bytearrayrr)encoderxr)rUr"r+r+r,rszBaseConverter.to_url) rMrNrOrPrrr[rfrTr)rrr+r+r+r,rs rcs<eZdZdZddeejeejeddfdd ZZS) 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/'), Rule('/') :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. rNr)rx minlength maxlengthlengthr#csftj||dk r&dt|d}n0|dkr4d}n tt|}dt|d|d}d||_dS)N{}r~r/z[^/])rSrTr&r)r)rUrxr-r.r/Z length_regexZmaxlength_value)rVr+r,rTs  zUnicodeConverter.__init__)rNN) rMrNrOrPr&r[r\rTr_r+r+)rVr,r,s r,cs*eZdZdZdeddfdd ZZS) AnyConvertera3Matches one of the items provided. Items can either be Python identifiers or strings:: Rule('/') :param map: the :class:`Map`. :param items: this function accepts the possible items as positional arguments. rN)rxrr#cs.tj|ddjdd|Dd|_dS)Nz(?:rcSsg|]}tj|qSr+)rr)rrr+r+r,rsz)AnyConverter.__init__..r{)rSrTrr)rUrxr)rVr+r,rTs zAnyConverter.__init__)rMrNrOrPr)rTr_r+r+)rVr,r2s r2c@seZdZdZdZdZdS) PathConverterzLike the default :class:`UnicodeConverter`, but it also matches slashes. This is useful for wikis and similar applications:: Rule('/') Rule('//edit') :param map: the :class:`Map`. z[^/].*?N)rMrNrOrPrrr+r+r+r,r3sr3cseZdZUdZdZeZejddeej eej ee ddfdd Z e ej d d d Zej e d d dZee dddZZS)NumberConverterzKBaseclass for `IntegerConverter` and `FloatConverter`. :internal: 2rNFr)rx fixed_digitsminrzsignedr#cs4|r |j|_tj|||_||_||_||_dS)N) signed_regexrrSrTr7r8rzr9)rUrxr7r8rzr9)rVr+r,rTs zNumberConverter.__init__)r"r#cCsV|jrt||jkrt|j|}|jdk r8||jksL|jdk rR||jkrRt|S)N)r7r@r num_convertr8rz)rUr"r+r+r,rs zNumberConverter.to_pythoncCs$t|j|}|jr |j|j}|S)N)r)r;r7zfill)rUr"r+r+r,rs zNumberConverter.to_url)r#cCs d|jS)Nz-?)r)rUr+r+r,r:$szNumberConverter.signed_regex)rNNF)rMrNrOrPrr&r;r[r#r\rrrTr)rfrrpropertyr:r_r+r+)rVr,r5s    r5c@seZdZdZdZdS)IntegerConverteraThis converter only accepts integer values:: Rule("/page/") By default it only accepts unsigned, positive values. The ``signed`` parameter will enable signed, negative values. :: Rule("/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)rMrNrOrPrr+r+r+r,r>)sr>csDeZdZdZdZeZd dejeejee ddfdd Z Z S) FloatConverteraThis converter only accepts floating point values:: Rule("/probability/") By default it only accepts unsigned, positive values. The ``signed`` parameter will enable signed, negative values. :: Rule("/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+NFr)rxr8rzr9r#cstj||||ddS)N)r8rzr9)rSrT)rUrxr8rzr9)rVr+r,rTXszFloatConverter.__init__)NNF) rMrNrOrPrr'r;r[r\rrrTr_r+r+)rVr,r?Bsr?c@s8eZdZdZdZeejdddZejedddZ dS) UUIDConverterzThis converter only accepts UUID strings:: Rule('/object/') .. 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})r"r#cCs tj|S)N)uuidUUID)rUr"r+r+r,rqszUUIDConverter.to_pythoncCst|S)N)r))rUr"r+r+r,rtszUUIDConverter.to_urlN) rMrNrOrPrr)rArBrrr+r+r+r,r@bsr@)r=ranyrr&r'rAc@sJeZdZdZeeZeZd$e j e j e e e eeee j e je e jefee j e je jge jfe edd d d Ze e ed d d Zd%e j e e jedddZe ddddZd&e e j e e j e e e e j e e j e je je e jfe fddddZd'e jd(e j e e j e ddddZddd d!Ze dd"d#ZdS))raThe 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``. Nr~utf-8TFreplace) rrrrrrrrrencoding_errorsrr#c Csg|_i|_d|_|j|_||_||_| |_||_||_ ||_ | |_ |j j |_|rb|jj|||_| |_x|pvfD]} |j| qxWdS)NT)ry_rules_by_endpoint_remap lock_class _remap_lockrrrFrrrrdefault_converterscopyrrrrrE) rUrrrrrrrrrrFrrr+r+r,rTs$   z Map.__init__)rirtr#cGs8|jt|}x"|j|D]}|j|jrdSqWdS)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)rrCrGrsrt)rUrirtr:r+r+r,is_endpoint_expectings  zMap.is_endpoint_expecting)rir#cCs(|j|dk rt|j|St|jS)zIterate 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)riterrGry)rUrir+r+r, iter_rulesszMap.iter_rules)rr#cCsJx>|j|D]0}|j||jj||jj|jgj|q Wd|_dS)zAdd 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)rrryr4rG setdefaultrirH)rUrr:r+r+r,rEs   zMap.addhttprrh) server_name script_namer url_schemedefault_methodra query_argsr#c Cs|j}|jr |dk r.tdn|dkr.|j}|dkr:d}|dkrFd}y t|}Wn*tk r|}zt|WYdd}~XnXt||||||||S)aReturn 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``. Nz2host matching enabled and a subdomain was providedr)lowerrrrr UnicodeErrorrrh) rUrRrSrrTrUrarVer+r+r,r s.'  zMap.bindrr)rWrRrr#c st|tj}d}tddjddjjdD}|rhjddjdkrh|d krdd nd }|d krv|}nF|j}|d kr|jdr|d d!}n|d"kr|jdr|d d#}|d koʈj r6|jd}|jd}t| } || d |krt j d|d|ddd}ndj t d |d | }t tjt dfdd } | d} | d} | d} tj|| ||d| | dS)$aLike :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). zwsgi.url_schemecss|]}|jdkVqdS)upgradeN)strip)rvr+r+r, sz&Map.bind_to_environ..ZHTTP_CONNECTIONr~r/Z HTTP_UPGRADErhttpswsswsNrQz:80z:443r|zCurrent server name z& doesn't match configured server name ) stacklevelz )r0r#cs"j|}|dk rt|jSdS)N)getr r)r0val)envrUr+r,_get_wsgi_strings  z-Map.bind_to_environ.._get_wsgi_stringZ SCRIPT_NAMEZ PATH_INFO QUERY_STRINGREQUEST_METHOD)rV>r`rQ>r_r^)rrrWrCrerrrr@warningswarnrfilterr)r[r\rr)rUrWrRrZwsgi_server_nameschemerZZcur_server_nameZreal_server_nameoffsetrhrSrarVr+)rgrUr,bind_to_environLsL/     zMap.bind_to_environ)r#c Csf|js dS|jL|jsdS|jjdddx"|jjD]}|jdddq:Wd|_WdQRXdS)zzCalled before matching and building to keep the compiled rules in the correct order after things changed. NcSs|jS)N)r)rr+r+r,szMap.update..)rwcSs|jS)N)r)rr+r+r,rssF)rHrJryrrGrj)rUrr+r+r,rsz Map.updatecCs&|j}t|jdtt|dS)N(r{)rOrrMrr)rUrr+r+r,r"sz Map.__repr__) Nr~rDTTTNFNrEF)N)NNrQrNN)NN)rr)rMrNrOrPr DEFAULT_CONVERTERSrKrrIr[r\rrr)rrreTyperr#rfrTrMrrmrOrEr]rrrrr"r+r+r+r,rs<+P ><hrc @s\eZdZdZd.eeeejeeeeejejej eej fefdddZ d/ej eej eej fgdfejeejee ddd d Zejd0ejeejed ejejej eej fefeje ejeej eej ffd d dZejd1ejeejedejejej eej fefeje ejeej eej ffd ddZd2ejeejee ejejej eej fefeje ejejeefej eej ffd ddZd3ejeejee dddZd4ejeejedddZejeedddZeeejeej fejej eej fefejedddZejej eej fefedd d!Zd5eejejej eej fefejeed"d#d$Zeeej eej feejej eej fefed%d&d'Zeej eej fejee ejejeee fd(d)d*Zd6eejej eej fejee e ejeed+d,d-ZdS)7rhzReturned by :meth:`Map.bind` or :meth:`Map.bind_to_environ` and does the URL matching and building based on runtime information. N)rxrRrSrrTrarUrVc Csn||_t||_t|}|jds*|d7}||_t||_t||_t||_t||_||_ |jdk|_ dS)Nrr`r_>r_r`) rxr rRrrSrrTrarUrVr) rUrxrRrSrrTrarUrVr+r+r,rTs       zMapAdapter.__init__Fr) view_funcrarkcatch_http_exceptionsr#cCsry@y|j||\}}Wn tk r6}z|Sd}~XnX|||Stk rl}z|rZ|SWYdd}~XnXdS)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)rBrQr)rUrwrarkrxrir6rYr+r+r,dispatchs1 zMapAdapter.dispatchzte.Literal[False])rark return_rulerVrr#cCsdS)Nr+)rUrarkrzrVrr+r+r,rB(s zMapAdapter.matchTzte.Literal[True]cCsdS)Nr+)rUrarkrzrVrr+r+r,rB3s cs|jj|dkr|j}nt||jj}|dkr:|jp8i}|pB|jj}|dkrV|j}d}|jj rh|j n|j }|rd|j dnd}|d|} t } d} x|jjD]yj| |Wntk r} z(t|jt| j|jjdd|dWYdd} ~ Xn@tk rD} z"t|j| j| j||dWYdd} ~ XnXdkrRqjdk rx|jkrx| jjqj|krd} q|jjr|j||} | dk rt| jdk rRtjtrtjttd fd d }t j!|j} nj|f} |j r&|j d |j }n|j }tt"|j#p:d d||j$| |rvt|jt||jjdd||rfSjfSqW| rt%t&| d| rt't(dS)aThe 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 receive a ``WebsocketMismatch`` exception if the only match is a WebSocket rule but the bind is an HTTP request, or if the match is an HTTP rule but the bind is a WebSocket request. - 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/', 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. :param websocket: Match WebSocket instead of HTTP requests. A websocket request has a ``ws`` or ``wss`` :attr:`url_scheme`. This overrides that detection. .. versionadded:: 1.0 Added ``websocket``. .. versionchanged:: 0.8 ``query_args`` can be a string. .. versionadded:: 0.7 Added ``query_args``. .. versionadded:: 0.6 Added ``return_rule``. NFrr~rz/:|+)rT)rBr#cs$|jd}j|jdj|S)Nr)r3rr)rBr")r:rvr+r, _handle_matchsz'MapAdapter.match.._handle_matchr|rQz://) valid_methods))rxrrar rrVrUrrrrRrr!rCryrBr`rQmake_redirect_urlrrcmake_alias_redirect_urlrirdrurget_default_redirectrrr)r[ZMatch_simple_rule_resubrrTrSrrrr)rUrarkrzrVrr domain_partZ path_partrZhave_match_forZwebsocket_mismatchrYZ redirect_urlr|netlocr+)r:r{r,rB>s_        )rarkr#c Cs<y|j||Wn&tk r$Yntk r6dSXdS)aTest 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)rBrQr)rUrarkr+r+r,tests zMapAdapter.test)rar#cCsLy|j|ddWn4tk r4}z|jSd}~Xntk rFYnXgS)z^Returns the valid methods that match for a given path. .. versionadded:: 0.7 z--)rkN)rBrr}r)rUrarYr+r+r,allowed_methodsszMapAdapter.allowed_methods)rr#cCs\|jjr |dkr|jSt|dS|}|dkr4|j}n t|d}|rR|d|jS|jSdS)zFigures 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. Nasciir|)rxrrRr r)rUrrr+r+r,rs  zMapAdapter.get_host)r:rkrjrVr#cCsr|jjs tx`|jj|jD]N}||kr*P|j|r|j||r|j|j|j |\}}|j |||dSqWdS)zA helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: )rN) rxrrrGrirrrrrr~)rUr:rkrjrVrrrr+r+r,r0s  zMapAdapter.get_default_redirect)rVr#cCst|tst||jjS|S)N)rr)rrxr)rUrVr+r+r,encode_query_argsIs zMapAdapter.encode_query_args)rarVrr#cCs`|rd|j|}nd}|jp"d}|j|}tj|jjd|jd}|d|d||S)z4Creates a redirect URL. :internal: r}r~rQrz://)rrTr posixpathrrSr[r!)rUrarVrsuffixrprrr+r+r,r~Ns   zMapAdapter.make_redirect_url)rrirjrkrVr#cCs@|j|||ddd}|r,|d|j|7}||ks>> m = Map([ ... Rule('/', endpoint='index'), ... Rule('/downloads/', endpoint='downloads/index'), ... Rule('/downloads/', 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 bytes back. Non ASCII characters are urlencoded with the charset defined on the map instance. Additional values are converted to strings 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. :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. :param url_scheme: Scheme to use in place of the bound :attr:`url_scheme`. .. versionchanged:: 2.0 Added the ``url_scheme`` parameter. .. versionadded:: 0.6 Added the ``append_unknown`` parameter. NcSsg|]}|dk r|qS)Nr+)rr\r+r+r,rsz$MapAdapter.build..rrr^r_Tr`rQr:r~z//>r_r^r$)rxrrr r^rrr5r@rrgrrTrrRrrSrr!)rUrirjrkrrrTZ temp_valuesZ always_listrwr"r{rrrrsecurerpr+r+r,rsFP      zMapAdapter.build)N)NNF)NNFNN)NNTNN)NNFNN)NN)N)NN)NNFTN)rMrNrOrPrr)r[r\r]rerfrTr#rrrytypingZoverloadrrBrmrrrrr$rrr~rrrr+r+r+r,rhsr @06:&:&:.9 &*  &,rh)lrPrrqrrrr[rArmpprintrrr threadingrtypesrZ _internalrrr r r Zdatastructuresr r exceptionsrrrrrurlsrrrrrutilsrrZwsgirZ TYPE_CHECKINGZtyping_extensionsteZ_typeshed.wsgirrZwrappers.requestrZwrappers.responserrVERBOSErArr1r%r)r]rrr&r'r-rrrfr9rr\rK ExceptionrLrQr`rcrrgrr(rrrrrrrrrrZ_IF_KWARGS_URL_ENCODE_CODErrrmrr,r2r3r5r>r?r@rurervrrhr+r+r+r,ks                                 (.  F ' |%. L