changeset 2:b8e5471794b2

move to a dispatcher architecture
author k0s <k0scist@gmail.com>
date Thu, 05 Nov 2009 23:15:37 -0500
parents d9519f40c177
children 198d1cb34c14
files genshi_view/template/+package+/+package+.py_tmpl genshi_view/template/+package+/dispatcher.py genshi_view/template/+package+/factory.py_tmpl setup.py
diffstat 4 files changed, 59 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/genshi_view/template/+package+/+package+.py_tmpl	Thu Nov 05 23:11:45 2009 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-"""
-request dispatcher
-"""
-
-from handlers import Index
-
-from genshi.template import TemplateLoader
-from paste.fileapp import FileApp
-from pkg_resources import resource_filename
-from webob import Request, Response, exc
-
-class Dispatcher(object):
-
-    ### class level variables
-    defaults = { 'auto_reload': 'False'}
-
-    def __init__(self, **kw):
-
-        # set instance parameters from kw and defaults
-        for key in self.defaults:
-            setattr(self, key, kw.get(key, self.defaults[key]))
-#        self.auto_reload = self.auto_reload.lower() == 'true'
-
-        self.handlers = [ Index ]
-
-        # static files
-        self.htdocs = resource_filename(__name__, 'static')
-
-        # template loader # to move???
-#        templates_dir = resource_filename(__name__, 'templates')
-#        self.loader = TemplateLoader(templates_dir,
-#                                     auto_reload=self.auto_reload)
-
-    ### methods dealing with HTTP
-    def __call__(self, environ, start_response):
-        request = Request(environ)
-
-        # serve static files
-        # TODO: put into a handler
-        filename = os.path.join(self.htdocs, request.path_info)
-        if request.path_info != '/' and os.path.exists(filename):
-            fileapp = FileApp(filename)
-            return fileapp(environ, start_response)
-
-        # match the request to a handler
-        for h in self.handlers:
-            handler = h.match(request)
-            if handler is not None:
-                break
-        else:
-            handler = exc.HTTPNotFound
-
-        res = handler()
-        return res(environ, start_response)
-                                
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/genshi_view/template/+package+/dispatcher.py	Thu Nov 05 23:15:37 2009 -0500
@@ -0,0 +1,55 @@
+"""
+request dispatcher
+"""
+
+from handlers import Index
+
+from genshi.template import TemplateLoader
+from paste.fileapp import FileApp
+from pkg_resources import resource_filename
+from webob import Request, Response, exc
+
+class Dispatcher(object):
+
+    ### class level variables
+    defaults = { 'auto_reload': 'False'}
+
+    def __init__(self, **kw):
+
+        # set instance parameters from kw and defaults
+        for key in self.defaults:
+            setattr(self, key, kw.get(key, self.defaults[key]))
+#        self.auto_reload = self.auto_reload.lower() == 'true'
+
+        self.handlers = [ Index ]
+
+        # static files
+        self.htdocs = resource_filename(__name__, 'static')
+
+        # template loader # to move???
+#        templates_dir = resource_filename(__name__, 'templates')
+#        self.loader = TemplateLoader(templates_dir,
+#                                     auto_reload=self.auto_reload)
+
+    ### methods dealing with HTTP
+    def __call__(self, environ, start_response):
+        request = Request(environ)
+
+        # serve static files
+        # TODO: put into a handler
+        filename = os.path.join(self.htdocs, request.path_info)
+        if request.path_info != '/' and os.path.exists(filename):
+            fileapp = FileApp(filename)
+            return fileapp(environ, start_response)
+
+        # match the request to a handler
+        for h in self.handlers:
+            handler = h.match(request)
+            if handler is not None:
+                break
+        else:
+            handler = exc.HTTPNotFound
+
+        res = handler()
+        return res(environ, start_response)
+                                
--- a/genshi_view/template/+package+/factory.py_tmpl	Thu Nov 05 23:11:45 2009 -0500
+++ b/genshi_view/template/+package+/factory.py_tmpl	Thu Nov 05 23:15:37 2009 -0500
@@ -1,12 +1,13 @@
 import os
 
-from ${package} import ${project.title()}View
+from dispatcher import Dispatcher
 from paste.httpexceptions import HTTPExceptionHandler
 from paste.urlparser import StaticURLParser
 from pkg_resources import resource_filename
 
 class PassthroughFileserver(object):
     """serve files if they exist"""
+    # XXX needed???
 
     def __init__(self, app, directory):
         self.app = app
@@ -26,6 +27,6 @@
     args = dict([(key.split(keystr, 1)[-1], value)
                  for key, value in app_conf.items()
                  if key.startswith(keystr) ])
-    app = ${project.title()}View(**args)
+    app = DispatcherView(**args)
     return HTTPExceptionHandler(PassthroughFileserver(app, resource_filename(__name__, 'static')))
     
--- a/setup.py	Thu Nov 05 23:11:45 2009 -0500
+++ b/setup.py	Thu Nov 05 23:15:37 2009 -0500
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = '0.1.1'
+version = '0.2'
 
 setup(name='genshi_view',
       version=version,