[Checkins] SVN: bobo/branches/d2m.extrapathinfo/bobo add extra path info processing, add docs and tests

Michael Haubenwallner michael at d2m.at
Wed Aug 12 02:37:02 EDT 2009


Log message for revision 102695:
  add extra path info processing, add docs and tests

Changed:
  U   bobo/branches/d2m.extrapathinfo/bobo/src/bobo.py
  U   bobo/branches/d2m.extrapathinfo/bobodoctestumentation/src/bobodoctestumentation/index.txt

-=-
Modified: bobo/branches/d2m.extrapathinfo/bobo/src/bobo.py
===================================================================
--- bobo/branches/d2m.extrapathinfo/bobo/src/bobo.py	2009-08-12 05:44:35 UTC (rev 102694)
+++ bobo/branches/d2m.extrapathinfo/bobo/src/bobo.py	2009-08-12 06:37:02 UTC (rev 102695)
@@ -908,7 +908,7 @@
     return _handler(route, method=method, params='params', check=check,
                     content_type=content_type, order_=order)
 
-route_re = re.compile(r'(/:[a-zA-Z]\w*\??)(\.[^/]+)?')
+route_re = re.compile(r'(/:[a-zA-Z]\w*[\?\*]?)(\.[^/]+)?')
 def _compile_route(route, partial=False):
     assert route.startswith('/') or not route
     pat = route_re.split(route)
@@ -920,8 +920,13 @@
     while pat:
         name = pat.pop()[2:]
         optional = name.endswith('?')
-        if optional:
+        wildcard = name.endswith('*')
+        if optional or wildcard:
             name = name[:-1]
+        if wildcard:
+            name = '/(?P<%s>.*)' % name
+            rpat.append(name)
+            break
         name = '/(?P<%s>[^/]*)' % name
         ext = pat.pop()
         if ext:

Modified: bobo/branches/d2m.extrapathinfo/bobodoctestumentation/src/bobodoctestumentation/index.txt
===================================================================
--- bobo/branches/d2m.extrapathinfo/bobodoctestumentation/src/bobodoctestumentation/index.txt	2009-08-12 05:44:35 UTC (rev 102694)
+++ bobo/branches/d2m.extrapathinfo/bobodoctestumentation/src/bobodoctestumentation/index.txt	2009-08-12 06:37:02 UTC (rev 102695)
@@ -410,6 +410,56 @@
     'Hello Sally! My name is jim.'
 
 
+If the placeholder is a '*' everything up to the end of the path is available
+in the placeholder variable::
+
+    @bobo.query('/greeters/:extra_path*')
+    def hello(name="world", extra_path=''):
+        return "Hello %s! Extra path info is '%s'." % (name, extra_path)
+
+.. -> src
+
+    >>> update_module('helloapp', src)
+    >>> app = webtest.TestApp(bobo.Application(bobo_resources='helloapp'))
+
+Then we can use a URL like::
+
+    http://localhost:8080/greeters/name/Sally
+.. -> url strip
+
+    >>> app.get(url, status=200).body
+    "Hello world! Extra path info is 'name/Sally'."
+
+And get::
+
+    Hello world! Extra path info is 'name/Sally'.
+
+It is up to you to further process the extra path information.
+
+Extra path info can be combined with the suffix pattern::
+
+    @bobo.query('/greeters/:extra_path*.html')
+    def hello(name="world", extra_path=''):
+        return "Hello %s! Extra path info is '%s'." % (name, extra_path)
+
+.. -> src
+
+    >>> update_module('helloapp', src)
+    >>> app = webtest.TestApp(bobo.Application(bobo_resources='helloapp'))
+
+::
+
+    http://localhost:8080/greeters/name/Sally.html
+.. -> url strip
+
+    >>> app.get(url, status=200).body
+    "Hello world! Extra path info is 'name/Sally.html'."
+
+We now get::
+
+    Hello world! Extra path info is 'name/Sally.html'.
+
+
 Subroutes
 ---------
 



More information about the Checkins mailing list