diff roundup/web/router.py @ 4909:f31c93abedf6 routing

routing: No leading slash in URL map patterns
author anatoly techtonik <techtonik@gmail.com>
date Wed, 16 Jul 2014 03:17:54 +0300
parents c37069a99cec
children e5f90a69f660
line wrap: on
line diff
--- a/roundup/web/router.py	Wed Jul 16 03:10:02 2014 +0300
+++ b/roundup/web/router.py	Wed Jul 16 03:17:54 2014 +0300
@@ -22,9 +22,10 @@
 ExampleHandler = NamedObject('ExampleHandler')
 ExampleFileHandler = NamedObject('ExampleFileHandler')
 
+
 EXAMPLE_URLMAP = (
-    '/static/(.*)', ExampleFileHandler,
-    '/', ExampleHandler
+    'static/(.*)', ExampleFileHandler,
+    '', ExampleHandler
 )
 
 
@@ -35,15 +36,19 @@
     def __init__(self, urlmap=[]):
         """
         `urlmap` is a list (pattern, handler, pattern, ...)
+        pattern should have no leading slash
         """
         self.urlmap = urlmap
 
     def get_handler(self, urlpath):
         """
         `urlpath` is a part of url /that/looks?like=this
+        (leading slash is optional)
 
         returns tuple (handler, arguments) or (None, ())
         """
+        # strip leading slashes before matching
+        path = urlpath.lstrip('/')
         for i in range(0, len(self.urlmap), 2):
             pattern, handler = self.urlmap[i], self.urlmap[i+1]
             match = re.match(pattern, urlpath)

Roundup Issue Tracker: http://roundup-tracker.org/