Mercurial > p > roundup > code
comparison roundup/web/router.py @ 4924:6ee1844019d5 routing
routing: Add DEBUG flag for troubleshooting
| author | anatoly techtonik <techtonik@gmail.com> |
|---|---|
| date | Wed, 20 Aug 2014 13:36:08 +0300 |
| parents | 35dc9191394d |
| children | 997fa47c92d5 |
comparison
equal
deleted
inserted
replaced
| 4923:91029cc0dc59 | 4924:6ee1844019d5 |
|---|---|
| 5 | 5 |
| 6 Public domain work by: | 6 Public domain work by: |
| 7 anatoly techtonik <techtonik@gmail.com> | 7 anatoly techtonik <techtonik@gmail.com> |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 DEBUG = False | |
| 11 | |
| 12 | |
| 10 import re | 13 import re |
| 11 | |
| 12 | 14 |
| 13 # --- Example URL mapping | 15 # --- Example URL mapping |
| 14 | 16 |
| 15 class NamedObject(object): | 17 class NamedObject(object): |
| 16 """Object that outputs given name when printed""" | 18 """Object that outputs given name when printed""" |
| 49 """ | 51 """ |
| 50 # strip leading slashes before matching | 52 # strip leading slashes before matching |
| 51 path = urlpath.lstrip('/') | 53 path = urlpath.lstrip('/') |
| 52 for i in range(0, len(self.urlmap), 2): | 54 for i in range(0, len(self.urlmap), 2): |
| 53 pattern, handler = self.urlmap[i], self.urlmap[i+1] | 55 pattern, handler = self.urlmap[i], self.urlmap[i+1] |
| 56 if DEBUG: | |
| 57 print('router: matching %s' % pattern) | |
| 54 match = re.match(pattern, path) | 58 match = re.match(pattern, path) |
| 55 if match: | 59 if match: |
| 56 return handler, match.groups() | 60 return handler, match.groups() |
| 57 return (None, ()) | 61 return (None, ()) |
| 58 | 62 |
