Returned by :meth:`Map.bind` or :meth:`Map.bind_to_environ` and does the URL matching and building based on runtime information.
| 380 | |
| 381 | |
| 382 | class MapAdapter: |
| 383 | class="st">"""Returned by :meth:`Map.bind` or :meth:`Map.bind_to_environ` and does |
| 384 | the URL matching and building based on runtime information. |
| 385 | class="st">""" |
| 386 | |
| 387 | def __init__( |
| 388 | self, |
| 389 | map: Map, |
| 390 | server_name: str, |
| 391 | script_name: str, |
| 392 | subdomain: str | None, |
| 393 | url_scheme: str, |
| 394 | path_info: str, |
| 395 | default_method: str, |
| 396 | query_args: t.Mapping[str, t.Any] | str | None = None, |
| 397 | ): |
| 398 | self.map = map |
| 399 | self.server_name = server_name |
| 400 | |
| 401 | if not script_name.endswith(class="st">"/"): |
| 402 | script_name += class="st">"/" |
| 403 | |
| 404 | self.script_name = script_name |
| 405 | self.subdomain = subdomain |
| 406 | self.url_scheme = url_scheme |
| 407 | self.path_info = path_info |
| 408 | self.default_method = default_method |
| 409 | self.query_args = query_args |
| 410 | self.websocket = self.url_scheme in {class="st">"ws", class="st">"wss"} |
| 411 | |
| 412 | def dispatch( |
| 413 | self, |
| 414 | view_func: t.Callable[[str, t.Mapping[str, t.Any]], WSGIApplication], |
| 415 | path_info: str | None = None, |
| 416 | method: str | None = None, |
| 417 | catch_http_exceptions: bool = False, |
| 418 | ) -> WSGIApplication: |
| 419 | class="st">"""Does the complete dispatching process. `view_func` is called with |
| 420 | the endpoint and a dict with the values for the view. It should |
| 421 | look up the view function, call it, and return a response object |
| 422 | or WSGI application. http exceptions are not caught by default |
| 423 | so that applications can display nicer error messages by just |
| 424 | catching them by hand. If you want to stick with the default |
| 425 | error messages you can pass it ``catch_http_exceptions=True`` and |
| 426 | it will catch the http exceptions. |
| 427 | |
| 428 | Here a small example for the dispatch usage:: |
| 429 | |
| 430 | from werkzeug.wrappers import Request, Response |
| 431 | from werkzeug.wsgi import responder |
| 432 | from werkzeug.routing import Map, Rule |
| 433 | |
| 434 | def on_index(request): |
| 435 | return Response(&class="cm">#x27;Hello from the index') |
| 436 | |
| 437 | url_map = Map([Rule(&class="cm">#x27;/class="st">', endpoint='index')]) |
| 438 | views = {&class="cm">#x27;index': on_index} |
| 439 |