Is there any straightforward to convert all incoming urls to lowercase before they get matched against urlpatterns in run_wsgi_app(webapp.WSGIApplication(urlpatterns))
?
views:
104answers:
2
+3
A:
You'd have to wrap the instance of WSGIApplication
with your own WSGI app that lowercases the URL in the WSGI environment -- but then the environment would just stay modified, which may have other unpleasant effects. Why not just add (?i)
to the regex patterns you use in urlpatterns
instead?
Alex Martelli
2009-10-03 00:31:10
Thanks.But how will this work in '/(?P<some_category>\w+)/edit/(?P<item_id>\w+)/?' where 'edit' might be 'EDIT'?
alex
2009-10-03 00:46:49
@gmsd, as I said, just add `(?i)` to the pattern; for example, use `'(?i)/(?P<some_category>\w+)/edit/(?P<item_id>\w+)/?'` (just like your pattern plus `(?i)` in front, to tell `re` that the match is cases-insensitive. See http://docs.python.org/library/re.html?#regular-expression-syntax .
Alex Martelli
2009-10-03 01:44:07
A:
I wonder if you could modify your CGI environment variables before executing the WSGIApplication instance.
os.putenv(os.getenv('PATH_INFO').lower())
Something along those lines. I've done this myself for slight URL modifications, however I 301 redirected to the new URL; I didn't continue processing with WSGI.
jhs
2009-10-03 03:01:44
This solution will work (with the caveats Alex mentioned), but WSGI middleware is a better idea.
Nick Johnson
2009-10-04 21:39:03