req.path_info_pop() enhancement

5 views
Skip to first unread message

Sergey Schetinin

unread,
Mar 25, 2010, 4:46:57 PM3/25/10
to Paste Users
A minute ago I was once again explaining how I do the dispatching with req.path_info_peek() / req.path_info_pop() and it struck me that it can be simplified quite a bit by adding a `pattern` argument to path_info_pop:

        Optional ``pattern`` argument is a regexp to match the return value
        before returning. If there is no match, no changes are made to the
        request and None is returned.

So instead of this:

    id = req.path_info_peek()
    if id.isdigit():
        req.path_info_pop()
        return ArticleApp(int(id))

We can now do this:

    id = req.path_info_pop('\d+')
    if id:
        return ArticleApp(int(id))


http://bitbucket.org/ianb/webob/changeset/45dc8e052537/



--
Best Regards,
Sergey Schetinin

http://s3bk.com/ -- S3 Backup
http://word-to-html.com/ -- Word to HTML Converter
Reply all
Reply to author
Forward
0 new messages