Skip to content

Commit aa6d4c3

Browse files
pavithra-m13davidism
authored andcommitted
update dispatch-by-path example
1 parent 826514b commit aa6d4c3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

docs/patterns/appdispatch.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ the ``Host`` header to figure out the subdomain one simply looks at the
146146
request path up to the first slash::
147147

148148
from threading import Lock
149-
from werkzeug.wsgi import pop_path_info, peek_path_info
149+
from wsgiref.util import shift_path_info
150150

151151
class PathDispatcher:
152152

@@ -166,13 +166,20 @@ request path up to the first slash::
166166
return app
167167

168168
def __call__(self, environ, start_response):
169-
app = self.get_application(peek_path_info(environ))
169+
app = self.get_application(self._peek_path_info(environ))
170170
if app is not None:
171-
pop_path_info(environ)
171+
shift_path_info(environ)
172172
else:
173173
app = self.default_app
174174
return app(environ, start_response)
175175

176+
def _peek_path_info(environ):
177+
segments = environ.get("PATH_INFO", "").lstrip("/").split("/", 1)
178+
if segments:
179+
return segments[0]
180+
181+
return None
182+
176183
The big difference between this and the subdomain one is that this one
177184
falls back to another application if the creator function returns ``None``::
178185

0 commit comments

Comments
 (0)