zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
U
Þ=®d’ã@s¬ddlmZddlZddlZddlmZddlmZddl    m
Z
ddl    m Z ddl    m Z dd    l mZdd
l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%ddl&m'Z'ddl&m(Z(ej)rŒddl*m+Z+ddl*m,Z,dd lm-Z-dd!l&m.Z.dd"l/m0Z0Gd#d$„d$ƒZ1Gd%d&„d&ƒZ2dS)'é)Ú annotationsN)Úpformat)ÚLock)Úquote)Úurljoin)Ú
urlunsplité)Ú _get_environ)Ú_wsgi_decoding_dance)Ú ImmutableDict)Ú    MultiDict)ÚBadHost)Ú HTTPException)ÚMethodNotAllowed)ÚNotFound)Ú
_urlencode)Úget_hosté)ÚDEFAULT_CONVERTERS)Ú
BuildError)ÚNoMatch)ÚRequestAliasRedirect)Ú RequestPath)ÚRequestRedirect)ÚWebsocketMismatch)ÚStateMachineMatcher)Ú_simple_rule_re)ÚRule)ÚWSGIApplication)ÚWSGIEnvironment)Ú BaseConverter)Ú RuleFactory)ÚRequestc@sØeZdZdZeeƒZeZd.dddd    d    d    d
d    d dd    d d œ dd„Z    ddd    dœdd„Z
e ddœdd„ƒZ d/dddœdd„Z dd dœdd„Zd0ddddddd!d"d#œd$d%„Zd1d&ddd"d'œd(d)„Zd dœd*d+„Zddœd,d-„ZdS)2ÚMapa_    The map class stores all the URL rules and some configuration
    parameters.  Some of the configuration values are only stored on the
    `Map` instance since those affect all rules, others are just defaults
    and can be overridden for each rule.  Note that you have to specify all
    arguments besides the `rules` as keyword arguments!
 
    :param rules: sequence of url rules for this map.
    :param default_subdomain: The default subdomain for rules without a
                              subdomain defined.
    :param charset: charset of the url. defaults to ``"utf-8"``
    :param strict_slashes: If a rule ends with a slash but the matched
        URL does not, redirect to the URL with a trailing slash.
    :param merge_slashes: Merge consecutive slashes when matching or
        building URLs. Matches will redirect to the normalized URL.
        Slashes in variable parts are not merged.
    :param redirect_defaults: This will redirect to the default rule if it
                              wasn't visited that way. This helps creating
                              unique URLs.
    :param converters: A dict of converters that adds additional converters
                       to the list of converters. If you redefine one
                       converter this will override the original one.
    :param sort_parameters: If set to `True` the url parameters are sorted.
                            See `url_encode` for more details.
    :param sort_key: The sort key function for `url_encode`.
    :param encoding_errors: the error method to use for decoding
    :param host_matching: if set to `True` it enables the host matching
                          feature and disables the subdomain one.  If
                          enabled the `host` parameter to rules is used
                          instead of the `subdomain` one.
 
    .. versionchanged:: 2.3
        The ``charset`` and ``encoding_errors`` parameters are deprecated and will be
        removed in Werkzeug 3.0.
 
    .. versionchanged:: 1.0
        If ``url_scheme`` is ``ws`` or ``wss``, only WebSocket rules will match.
 
    .. versionchanged:: 1.0
        The ``merge_slashes`` parameter was added.
 
    .. versionchanged:: 0.7
        The ``encoding_errors`` and ``host_matching`` parameters were added.
 
    .. versionchanged:: 0.5
        The ``sort_parameters`` and ``sort_key``  paramters were added.
    NÚTFzt.Iterable[RuleFactory] | NoneÚstrú
str | NoneÚboolz*t.Mapping[str, type[BaseConverter]] | Nonez!t.Callable[[t.Any], t.Any] | NoneÚNone) ÚrulesÚdefault_subdomainÚcharsetÚstrict_slashesÚ merge_slashesÚredirect_defaultsÚ
convertersÚsort_parametersÚsort_keyÚencoding_errorsÚ host_matchingÚreturnc CsÊt|ƒ|_i|_d|_| ¡|_||_|dk    r@tjdt    ddnd}||_
|
dk    rdtjdt    ddnd}
|
|_ ||_ ||_ ||_| |_|j ¡|_|r¢|j |¡||_|    |_|p´dD]} | | ¡q¶dS)    NTzJThe 'charset' parameter is deprecated and will be removed in Werkzeug 3.0.r©Ú
stacklevelzutf-8zRThe 'encoding_errors' parameter is deprecated and will be removed in Werkzeug 3.0.Úreplace©)rÚ_matcherÚ_rules_by_endpointÚ_remapÚ
lock_classÚ _remap_lockr*ÚwarningsÚwarnÚDeprecationWarningr+r2r,r-r.r3Údefault_convertersÚcopyr/Úupdater0r1Úadd) Úselfr)r*r+r,r-r.r/r0r1r2r3Ú rulefactoryr8r8úKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\werkzeug/routing/map.pyÚ__init__`s@
 
üü   z Map.__init__)ÚendpointÚ    argumentsr4cGs6| ¡t|ƒ}|j|D]}| |j¡rdSqdS)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)rCÚsetr:ÚissubsetrJ)rErIrJÚruler8r8rGÚis_endpoint_expecting›s  zMap.is_endpoint_expectingz
list[Rule])r4cCsdd„|j ¡DƒS)NcSsg|]}|D]}|‘q qSr8r8)Ú.0r)rMr8r8rGÚ
<listcomp>±szMap._rules.<locals>.<listcomp>)r:Úvalues)rEr8r8rGÚ_rules¯sz
Map._ruleszt.Iterator[Rule])rIr4cCs(| ¡|dk    rt|j|ƒSt|jƒ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)rCÚiterr:rR)rErIr8r8rGÚ
iter_rules³szMap.iter_rulesr!)rFr4cCsL| |¡D]6}| |¡|js*|j |¡|j |jg¡ |¡q
d|_    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)
Z    get_rulesÚbindZ
build_onlyr9rDr:Ú
setdefaultrIÚappendr;)rErFrMr8r8rGrD¿s 
 zMap.addÚhttpÚGETú"t.Mapping[str, t.Any] | str | NoneÚ
MapAdapter)Ú server_nameÚ script_nameÚ    subdomainÚ
url_schemeÚdefault_methodÚ    path_infoÚ
query_argsr4c
Cs¸| ¡}|jr |dk    r.tdƒ‚n|dkr.|j}|dkr:d}|dkrFd}| d¡\}}}    z| d¡ d¡}Wn*tk
r”}
z tƒ|
‚W5d}
~
XYnXt    ||›|›|    ›||||||ƒ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.
 
        .. 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 providedú/ú:ÚidnaÚascii)
Úlowerr3Ú RuntimeErrorr*Ú    partitionÚencodeÚdecodeÚ UnicodeErrorr r[) rEr\r]r^r_r`rarbZport_sepÚportÚer8r8rGrUÌs2'
øzMap.bindzWSGIEnvironment | Request)Úenvironr\r^r4c
s‚t|ƒ‰tˆƒ ¡}ˆd}tdd„ˆ dd¡ ¡ d¡Dƒƒ}|rhˆ dd¡ ¡dkrh|d    krdd
nd }|d krv|}nF| ¡}|d krž| d¡rž|d d…}n|dkr¼| d¡r¼|d d…}|d kr6ˆjs6| d¡}| d¡}t|ƒ }    ||    d …|krt    j
d|›d|›ddd}nd  t d |d |    …ƒ¡}dddœ‡‡fdd„ }
|
dƒ} |
dƒ} |
d ƒ} t jˆ|| ||ˆd!| | d"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:: 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|]}| ¡dkVqdS)ÚupgradeN)Ústrip)rOÚvr8r8rGÚ    <genexpr>Csÿz&Map.bind_to_environ.<locals>.<genexpr>ZHTTP_CONNECTIONr$ú,Z HTTP_UPGRADEÚ    websocketÚhttpsÚwssÚwsN>rXrxz:80éýÿÿÿ>rvrwz:443éüÿÿÿÚ.zCurrent server name z& doesn't match configured server name rr5z    <invalid>r%r&)Únamer4cs"ˆ |¡}|dk    rt|ˆjƒSdS©N)Úgetr
r+)r|Úval©ÚenvrEr8rGÚ_get_wsgi_stringjs
 z-Map.bind_to_environ.<locals>._get_wsgi_stringZ SCRIPT_NAMEZ    PATH_INFOÚ QUERY_STRINGÚREQUEST_METHOD)rb)r    rrgÚanyr~ÚsplitÚendswithr3Úlenr>r?ÚjoinÚfilterr#rU)rEror\r^Zwsgi_server_nameÚschemerpZcur_server_nameZreal_server_nameÚoffsetr‚r]rarbr8r€rGÚbind_to_environsP/ þ 
 
 
ýøzMap.bind_to_environc    Csd|js
dS|jJ|js&W5QR£dS|j ¡|j ¡D]}|jdd„dq:d|_W5QRXdS)zzCalled before matching and building to keep the compiled rules
        in the correct order after things changed.
        NcSs| ¡Sr})Zbuild_compare_key)Úxr8r8rGÚ<lambda>‹ózMap.update.<locals>.<lambda>)ÚkeyF)r;r=r9rCr:rQÚsort©rEr)r8r8rGrC~s
z
Map.updatecCs&| ¡}t|ƒj›dtt|ƒƒ›dS)Nú(ú))rTÚtypeÚ__name__rÚlistr“r8r8rGÚ__repr__Žsz Map.__repr__) Nr$NTTTNFNNF)N)NNrXrYNN)NN)r—Ú
__module__Ú __qualname__Ú__doc__r rrArr<rHrNÚpropertyrRrTrDrUrrCr™r8r8r8rGr#(s@0ô&; øHümr#c
@s\eZdZdZd?dddddddddœdd    „Zd@d ddd d dœdd„ZejdAdddddddœdd„ƒZejdBdddddddœdd„ƒZdCddd ddddœdd„ZdDddd dœdd„Z    dEdd d!œd"d#„Z
ddd$œd%d&„Z d'dd(d)dd*œd+d,„Z d)dd-œd.d/„Z dFddddd0œd1d2„Zddd3dd)dd4œd5d6„Zdd3dd d7d8œd9d:„ZdGdd;dd d ddd<œd=d>„ZdS)Hr[z‰Returned by :meth:`Map.bind` or :meth:`Map.bind_to_environ` and does
    the URL matching and building based on runtime information.
    Nr#r%r&rZ)Úmapr\r]r^r_rar`rbc        CsR||_||_| d¡s|d7}||_||_||_||_||_||_|jdk|_    dS)Nrc>rwrx)
ržr\r‡r]r^r_rar`rbru)    rEržr\r]r^r_rar`rbr8r8rGrH™s 
zMapAdapter.__init__Fz9t.Callable[[str, t.Mapping[str, t.Any]], WSGIApplication]r'r)Ú    view_funcraÚmethodÚcatch_http_exceptionsr4c
CsˆzNz| ||¡\}}Wn,tk
rB}z|WY¢WSd}~XYnX|||ƒWStk
r‚}z|rp|WY¢S‚W5d}~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©Úmatchrr)rErŸrar r¡rIÚargsrnr8r8rGÚdispatch²s1  zMapAdapter.dispatchzt.Literal[False]z bool | Nonez!tuple[str, t.Mapping[str, t.Any]])rar Ú return_rulerbrur4cCsdSr}r8©rErar r¦rbrur8r8rGr£îs    zMapAdapter.matchTzt.Literal[True]z"tuple[Rule, t.Mapping[str, t.Any]]cCsdSr}r8r§r8r8rGr£ùs    z(tuple[str | Rule, t.Mapping[str, t.Any]]c sd|j ¡|dkr|j}|dkr*|jp(i}|p2|j ¡}|dkrF|j}|j}|jjsd|j    dk    rd|j    }|rxd| 
d¡›nd}z|jj   ||||¡}Wnèt k
rÞ}    z*t|    jd|jjd}
t| |
|¡ƒd‚W5d}    ~    XYn‚tk
r(}    z*t| |›d|›|    j|    j||¡ƒd‚W5d}    ~    XYn8tk
r|}    z6|    jrTtt|    jƒdd‚|    jrdtƒd‚tƒd‚W5d}    ~    XYnäX|\‰‰|jjr²| ˆ|ˆ|¡} | dk    r²t| ƒ‚ˆjdk    rHt ˆjt!ƒròdd    d
œ‡‡fd d „ } t" #| ˆj¡} nˆj|fˆŽ} |j    r|j    ›d |j›} n|j} tt$|j%p0d›d| ›|j&›| ƒƒ‚|rVˆˆfSˆjˆfSdS)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 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/<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.
        :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``.
        Nrcr$z!$&'()*+,/:;=@)ÚsafeÚencodingú|)Ú valid_methodsz t.Match[str]r%)r£r4cs$ˆ| d¡}ˆj| d¡ |¡S)Nr)ÚgroupÚ _convertersZto_url)r£Úvalue©rMÚrvr8rGÚ _handle_match›sz'MapAdapter.match.<locals>._handle_matchr{rXz://)'ržrCrarbr`Úupperrur\r3r^Úlstripr9r£rrr+rÚmake_redirect_urlrÚmake_alias_redirect_urlrIZmatched_valuesrZhave_match_forrr˜Zwebsocket_mismatchrrr.Úget_default_redirectZ redirect_toÚ
isinstancer%rÚsubrr_r])rErar r¦rbruÚ domain_partZ    path_partÚresultrnÚnew_pathZ redirect_urlr±Únetlocr8r¯rGr£s‚_
 
ÿ
ÿþ ûÿø    
 
 þÿ)rar r4cCs>z| ||¡Wn(tk
r$Yntk
r8YdSXdS)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.
        FTr¢)rErar r8r8rGÚtest´s    zMapAdapter.testzt.Iterable[str])rar4c
CsVz|j|ddWn>tk
r>}z|jWY¢Sd}~XYntk
rPYnXgS)z^Returns the valid methods that match for a given path.
 
        .. versionadded:: 0.7
        z--)r N)r£rr«r)rErarnr8r8rGÚallowed_methodsÅszMapAdapter.allowed_methods)r¹r4cCsL|jjr|dkr|jS|S|dkr*|j}n|}|rB|›d|j›S|jSdS)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.
        Nr{)ržr3r\r^)rEr¹r^r8r8rGrÒszMapAdapter.get_hostrzt.MutableMapping[str, t.Any]zt.Mapping[str, t.Any] | str)rMr rQrbr4cCst|jjs t‚|jj|jD]T}||kr*qp| |¡r| ||¡r| |j¡|     |¡\}}|j
|||dSqdS)zA helper that returns the URL to redirect to if it finds one.
        This is used for default redirecting only.
 
        :internal:
        )r¹N) ržr.ÚAssertionErrorr:rIZprovides_defaults_forÚ suitable_forrCÚdefaultsÚbuildr´)rErMr rQrbÚrr¹Úpathr8r8rGr¶çs  zMapAdapter.get_default_redirect)rbr4cCst|tƒst||jjdS|S)N)r©)r·r%rržr+)rErbr8r8rGÚencode_query_argss
zMapAdapter.encode_query_args)rarbr¹r4cCsd|dkr|j}|r| |¡}nd}|jp*d}| |¡}d |j d¡| d¡f¡}t||||dfƒS)z4Creates a redirect URL.
 
        :internal:
        NrXrc)    rbrÅr_rr‰r]rqr³r)rErarbr¹Z    query_strr‹ÚhostrÄr8r8rGr´s
 
 
zMapAdapter.make_redirect_urlzt.Mapping[str, t.Any])rÄrIrQr rbr4cCs@|j|||ddd}|r,|d| |¡›7}||ks<tdƒ‚|S)z0Internally called to make an alias redirect URL.FT)Úappend_unknownÚforce_externalú?z6detected invalid alias setting. No canonical URL found)rÂrÅr¿)rErÄrIrQr rbÚurlr8r8rGrµs    ÿz"MapAdapter.make_alias_redirect_urlztuple[str, str, bool] | None)rIrQr rÇr4c    Cs¬|dkr&| |||j|¡}|dk    r&|Sd}|jj |d¡D]l}| ||¡r:| ||¡}|dk    r:|d|d|jf}|jjrž|d|j    kr|S|dkr¦|}q:|Sq:|S)z–Helper for :meth:`build`.  Returns subdomain and path for the
        rule that accepts this endpoint, values and method.
 
        :internal:
        Nr8rr)
Ú_partial_buildr`ržr:r~rÀrÂrur3r\)    rErIrQr rÇr°Z first_matchrMZbuild_rvr8r8rGrË-s, ÿ  
zMapAdapter._partial_buildzt.Mapping[str, t.Any] | None)rIrQr rÈrÇr_r4cCsB|j ¡|rBt|tƒr.dd„t |¡Dƒ}qFdd„| ¡Dƒ}ni}| ||||¡}|dkrlt||||ƒ‚|\}}    }
| |¡} |dkrŽ|j    }|dk} |
r¬d}| r¦dnd}n|r¼| r¸d    nd
}|s|jj
rÔ| |j ksê|jj
s||j kr|j  d ¡›d |     d ¡›S|r|›d nd } | ›d| ›|j dd…›d |     d ¡›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
        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.
        cSs6i|].\}}t|ƒdkr|t|ƒdkr.|dn|“qS)rr)rˆ©rOÚkrrr8r8rGÚ
<dictcomp>ªs þz$MapAdapter.build.<locals>.<dictcomp>cSsi|]\}}|dk    r||“qSr}r8rÌr8r8rGrΰsN>rvrwTrwrxrvrXrcrdr$z//éÿÿÿÿ)ržrCr·r ÚdictÚitemsrËrrr_r3r\r^r]Úrstripr³)rErIrQr rÈrÇr_r°r¹rÄrurÆÚsecurer‹r8r8rGrÂVsBP
 
þ
 
 ÿÿþþzMapAdapter.build)N)NNF)NNFNN)NNTNN)NNFNN)NN)N)NN)NNFTN)r—ršr›rœrHr¥ÚtÚoverloadr£r½r¾rr¶rÅr´rµrËrÂr8r8r8rGr[“sX ÷û<ú
ú ú1 ü,ùr[)3Ú
__future__rÚtypingrÔr>ÚpprintrÚ    threadingrÚ urllib.parserrrÚ    _internalr    r
Zdatastructuresr r Ú
exceptionsr rrrÚurlsrZwsgirr/rrrrrrrZmatcherrr)rrÚ TYPE_CHECKINGZ_typeshed.wsgirrr r!Zwrappers.requestr"r#r[r8r8r8rGÚ<module>sJ                               m