Dispatch an incoming request.
(self, environ, start_response)
| 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.""" |
nothing calls this directly
no test coverage detected