changeset 0:72cb6dc31e3f

initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
author k0s <k0scist@gmail.com>
date Tue, 27 Oct 2009 15:04:33 -0400
parents
children eb2cb7ebc849
files setup.py webob_view/__init__.py webob_view/template/+package+.ini_tmpl webob_view/template/+package+/+package+.py_tmpl webob_view/template/+package+/__init__.py webob_view/template/+package+/factory.py_tmpl webob_view/template/setup.py_tmpl
diffstat 7 files changed, 154 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Tue Oct 27 15:04:33 2009 -0400
@@ -0,0 +1,28 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = ''
+
+setup(name='webob_view',
+      version=version,
+      description="paste template for a view using webob",
+      long_description="""\
+""",
+      classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      keywords='',
+      author='Jeff Hammel',
+      author_email='jhammel@openplans.org',
+      url='http://www.openplans.org/people/k0s',
+      license='GPL',
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[ 'PasteScript',
+      ],
+      entry_points="""
+      # -*- Entry points: -*-
+      [paste.paster_create_template]
+      webob_view = webob_view:WebobViewTemplate
+      """,
+      )
+      
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webob_view/__init__.py	Tue Oct 27 15:04:33 2009 -0400
@@ -0,0 +1,14 @@
+from paste.script import templates
+
+var = templates.var
+
+class WebobViewTemplate(templates.Template):
+    _template_dir = 'template'
+    summary = "a simple view with webob"
+    vars = [
+        var('description', 'One-line description of the package'),
+        var('author', 'Author name'),
+        var('author_email', 'Author email'),
+        var('url', 'URL of homepage'),
+        var('port', 'port to serve paste')
+        ] 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webob_view/template/+package+.ini_tmpl	Tue Oct 27 15:04:33 2009 -0400
@@ -0,0 +1,21 @@
+#!/usr/bin/env paster
+
+[DEFAULT]
+debug = true
+email_to = ${author_email|empty}
+smtp_server = localhost
+error_email_from = paste@localhost
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = ${port|empty}
+
+[composite:main]
+use = egg:Paste#urlmap
+/ = ${project}
+
+set debug = false
+
+[app:${project}]
+paste.app_factory = ${package}.factory:factory
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webob_view/template/+package+/+package+.py_tmpl	Tue Oct 27 15:04:33 2009 -0400
@@ -0,0 +1,47 @@
+"""
+${repr(project)}: a view with webob
+"""
+
+from webob import Request, Response, exc
+
+class View(object):
+
+    ### class level variables
+    defaults = {}
+
+    def __init__(self, **kw):
+        for key in self.defaults:
+            setattr(self, key, kw.get(key, self.defaults[key]))
+        self.response_functions = { 'GET': self.get,
+                                    'POST': self.post,
+                                    }
+
+    ### methods dealing with HTTP
+    def __call__(self, environ, start_response):
+        request = Request(environ)
+        res = self.make_response(request)
+        return res(environ, start_response)
+                                
+    def make_response(self, request):
+        return self.response_functions.get(request.method, self.error)(request)
+
+    def get_response(self, text, content_type='text/html'):
+        res = Response(content_type=content_type, body=text)
+        return res
+
+    def get(self, request):
+        """
+        return response to a GET requst
+        """
+        return self.get_response('Hello, world')
+
+    def post(self, request):
+        """
+        return response to a POST request
+        """
+        return exc.HTTPOk("Ok")
+
+    def error(self, request):
+        """deal with non-supported methods"""
+        return exc.HTTPMethodNotAllowed("Only %r operations are allowed" % self.response_functions.keys())
+        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webob_view/template/+package+/__init__.py	Tue Oct 27 15:04:33 2009 -0400
@@ -0,0 +1,1 @@
+#
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webob_view/template/+package+/factory.py_tmpl	Tue Oct 27 15:04:33 2009 -0400
@@ -0,0 +1,12 @@
+from ${package} import View
+from paste.httpexceptions import HTTPExceptionHandler
+
+def factory(global_conf, **app_conf):
+    """create a webob view and wrap it in middleware"""
+    keystr = '${project}.'
+    args = dict([(key.split(keystr, 1)[-1], value)
+                 for key, value in app_conf.items()
+                 if key.startswith(keystr) ])
+    app = View(**args)
+    return HTTPExceptionHandler(app)
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webob_view/template/setup.py_tmpl	Tue Oct 27 15:04:33 2009 -0400
@@ -0,0 +1,31 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = "0.0"
+
+setup(name=${repr(project)},
+      version=version,
+      description="${description|nothing}",
+      long_description="""
+""",
+      classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      author=${repr(author)|empty},
+      author_email=${repr(author_email)|empty},
+      url=${repr(url)|empty},
+      license=${repr(license_name)|empty},
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          # -*- Extra requirements: -*-
+         'WebOb',	
+         'Paste',
+         'PasteScript',
+      ],
+      entry_points="""
+      # -*- Entry points: -*-
+      [paste.app_factory]
+      main = ${project}.factory:factory
+      """,
+      )
+