Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
regex is not working in top level app #12
When using subapplications regexes, the top level url definitions behave differently then regexes in subapplications. This is an example based on code in http://webpy.org/cookbook/subapp.
import web urls = ( "", "reblog", "/(blog|Blog)", "blog" #change from original ) class reblog: def GET(self): raise web.seeother('/') class blog: def GET(self, path): return "blog " + path app_blog = web.application(urls, locals())
import web import blog urls = ( "/(blog|Blog)", blog.app_blog, #change from original # "/blog", blog.app_blog, "/(.*)", "index" ) class index: def GET(self, path): return "hello " + path app = web.application(urls, locals()) if __name__ == "__main__": app.run()
The regex /(blog|Blog) is the same in blog.py and code.py however request GET http://localhost:1111/blog/Blog does not return the expected result. If the regex is commented out in code.py and replaced with the line below it GET request returns an expected result.
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
I stumbled onto this as well. It appears that while local classes can use regex for URL handling, subapplication URL handling works only with literal strings. Looking in web/application.py around line 421 in the _match() function, the match test uses a startswith() rather than a regex function. This torpedos the design I've been working on, because I assumed (ass == me) that webpy would treat them consistently. So instead of doing URI rest calls that make sense to me:
I have to put static discriminators first so they can get passed off to subapplication classes:
I'm not sure what the purpose was in the inconsistency. When this was implemented, did something prevent treating local classes and subapplications differently? I don't see any comments that might shed light on the code.