The ResolveRegexApplication resolves a URL against a list of urls. The difference to the normal RegexApplication is that this application type resolves method names using regex groups.
Here is a small example to make that clear:
from colubrid import ResolveRegexApplication, HttpResponse, execute
class MyApplication(ResolveRegexApplication):
urls = [
(r'^index$', 'index'),
(r'^page/([a-z]+)$', 'page_$1'),
(r'^blog/([a-z]+)/(\d+)/(\d+)$', 'blog_$1')
]
def index(self):
return HttpResponse('Index')
def page_readme(self):
return HttpResponse('Readme')
def page_informations(self):
return HttpResponse('Information')
def blog_johndoe(self, year, month):
return HttpResposne('Year: %s\nMonth: %s' % (year, month))
app = MyApplication
if __name__ == '__main__':
execute(app)
$n (where n is the number of the group) is replaced by the current group value and is used to find the method.
If the method matches the handler, it removes substituted groups from the list of arguments.
This also works with import paths if you want to call a method in another module.