Module function receive only re.match.groups as arguments, not url
authordanigm <dani@danigm.net>
Thu, 16 Apr 2009 21:30:52 +0000 (23:30 +0200)
committerdanigm <dani@danigm.net>
Thu, 16 Apr 2009 21:30:52 +0000 (23:30 +0200)
slash separated

index.py
kisspi.py
modules/hello/__init__.py
modules/hello/hello.py

index 8f923e6..c43a08f 100644 (file)
--- a/index.py
+++ b/index.py
@@ -48,12 +48,12 @@ class index:
             m = modules.get(args[0], None)
             if m:
                 #return m.body().GET()
-                f = kisspi.parse_url(m, '/'.join(args[1:]))
+                f, fargs = kisspi.parse_url(m, '/'.join(args[1:]))
                 # adding kisspi to module class (sessions and others stuff)
                 f.kisspi = kisspi
                 function = getattr(f, method)
-                if args[1:]:
-                    returned = function(*args[1:])
+                if fargs:
+                    returned = function(*fargs)
                 else:
                     returned = function()
                 return returned
index d5d52d5..7a1bb43 100644 (file)
--- a/kisspi.py
+++ b/kisspi.py
@@ -17,9 +17,10 @@ def load_modules(path='modules'):
 
 def parse_url(module, path):
     for url, function in module.urls:
-        if re.match(url, path):
-            return function()
-    return None
+        match = re.match(url, path)
+        if match:
+            return function(), match.groups()
+    return None, None
 
 def get_session():
     return web.ses
index 9b02e07..7415f1f 100644 (file)
@@ -10,7 +10,7 @@ import hello
 # /hello -> hello.Hello
 # They are regular expresions and the order is important
 urls = (
-        ('\d', hello.Number),
+        ('(\d+)', hello.Number),
         ('up', hello.Upload),
         ('', hello.Hello),
         )
index 7c01171..3e0f937 100644 (file)
@@ -29,7 +29,7 @@ class Number:
 
 class Upload:
     kisspi = None
-    def GET(self, *args):
+    def GET(self):
         form = '''
             <form action="" method="POST">
                 <input type="text" name="text"/>
@@ -42,7 +42,7 @@ class Upload:
         yield form
         yield '</body></html>'
 
-    def POST(self, *args):
+    def POST(self):
         session = self.kisspi.get_session()
         input = self.kisspi.get_input()
         session.uploaded = input.text