From 4bf507bcd530766cb5b83b0e030df5b099f73c35 Mon Sep 17 00:00:00 2001 From: pavithra-m13 <138682484+pavithra-m13@users.noreply.github.com> Date: Sat, 12 Aug 2023 15:30:47 +0530 Subject: [PATCH] changed dispatched by path example --- docs/patterns/appdispatch.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/patterns/appdispatch.rst b/docs/patterns/appdispatch.rst index efa470a7..91745f79 100644 --- a/docs/patterns/appdispatch.rst +++ b/docs/patterns/appdispatch.rst @@ -146,7 +146,7 @@ the ``Host`` header to figure out the subdomain one simply looks at the request path up to the first slash:: from threading import Lock - from werkzeug.wsgi import pop_path_info, peek_path_info + from wsgiref.util import shift_path_info class PathDispatcher: @@ -166,13 +166,19 @@ request path up to the first slash:: return app def __call__(self, environ, start_response): - app = self.get_application(peek_path_info(environ)) + app = self.get_application(self._peek_path_info(environ)) if app is not None: - pop_path_info(environ) + shift_path_info(environ) else: app = self.default_app return app(environ, start_response) + def _peek_path_info(self, environ): + segments = environ.get("PATH_INFO", "").lstrip("/").split("/", 1) + if segments: + return segments[0] + return None + The big difference between this and the subdomain one is that this one falls back to another application if the creator function returns ``None``::