MCPcopy
hub / github.com/pallets/werkzeug / dispatch_request

Method dispatch_request

examples/simplewiki/application.py:54–90  ·  view source on GitHub ↗

Dispatch an incoming request.

(self, environ, start_response)

Source from the content-addressed store, hash-verified

52 local.application = self
53
54 def dispatch_request(self, environ, start_response):
55 """Dispatch an incoming request."""
56 # set up all the stuff we want to have for this request. That is
57 # creating a request object, propagating the application to the
58 # current context and instantiating the database session.
59 self.bind_to_context()
60 request = Request(environ)
61 request.bind_to_context()
62
63 # get the current action from the url and normalize the page name
64 # which is just the request path
65 action_name = request.args.get("action") or "show"
66 page_name = "_".join([x for x in request.path.strip("/").split() if x])
67
68 # redirect to the Main_Page if the user requested the index
69 if not page_name:
70 response = redirect(href("Main_Page"))
71
72 # check special pages
73 elif page_name.startswith("Special:"):
74 if page_name[8:] not in pages:
75 response = page_not_found(request, page_name)
76 else:
77 response = pages[page_name[8:]](request)
78
79 # get the callback function for the requested action from the
80 # action module. It's "on_" + the action name. If it doesn't
81 # exists call the missing_action method from the same module.
82 else:
83 action = getattr(actions, f"on_{action_name}", None)
84 if action is None:
85 response = actions.missing_action(request, action_name)
86 else:
87 response = action(request, page_name)
88
89 # make sure the session is removed properly
90 return ClosingIterator(response(environ, start_response), session.remove)
91
92 def __call__(self, environ, start_response):
93 """Just forward a WSGI call to the first internal middleware."""

Callers

nothing calls this directly

Calls 8

bind_to_contextMethod · 0.95
bind_to_contextMethod · 0.95
redirectFunction · 0.90
ClosingIteratorClass · 0.90
hrefFunction · 0.85
RequestClass · 0.70
page_not_foundFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected