Assorted fixes to work with Python 2.5 and CherryPy 2.3
authorW. Trevor King <wking@drexel.edu>
Mon, 21 Jun 2010 19:20:35 +0000 (15:20 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 21 Jun 2010 19:20:35 +0000 (15:20 -0400)
The earlier version worked in Python 2.6 and CherryPy 3.x.

bin/cook.py
cookbook/cookbook.py

index 2a994712ffd2a76cb4940862bfd67095d4a1306e..ab9f774b11285253f79614bab9fa2be7f214caa8 100755 (executable)
@@ -25,6 +25,7 @@ from cookbook.mom import MomParser
 from cookbook.cookbook import test as test_cookbook
 
 try:
+    import jinja2
     import cherrypy
     from cookbook.server import Server
     from cookbook.server import test as test_server
@@ -81,15 +82,29 @@ if __name__ == '__main__':
         template_dir = os.path.join(module_dir, 'template')
         config = os.path.join(module_dir, 'config')
         s = Server(c, template_dir)
-        cherrypy.config.update({ # http://www.cherrypy.org/wiki/ConfigAPI
-                'server.socket_host': options.address,
-                'server.socket_port': int(options.port),
-                'tools.encode.on': True,
-                'tools.encode.encoding': 'utf8',
-                'tools.staticdir.root': static_dir
-                })
-        app_config = { '/static': { 'tools.staticdir.on': True,
-                                    'tools.staticdir.dir': '', } }
-        cherrypy.quickstart(root=s, config=app_config)
-        sys.stderr.write('Saving cookbook\n')
+        if cherrypy.__version__.startswith('3.'):
+            cherrypy.config.update({ # http://www.cherrypy.org/wiki/ConfigAPI
+                    'server.socket_host': options.address,
+                    'server.socket_port': int(options.port),
+                    'tools.encode.on': True,
+                    'tools.encode.encoding': 'utf8',
+                    'tools.staticdir.root': static_dir,
+                    })
+            app_config = { '/static': { 'tools.staticdir.on': True,
+                                        'tools.staticdir.dir': '', } }
+            cherrypy.quickstart(root=s, config=app_config)
+        elif cherrypy.__version__.startswith('2.'):
+            cherrypy.root = s
+            cherrypy.config.update({
+                    'server.environment': 'production',
+                    'server.socket_host': options.address,
+                    'server.socket_port': int(options.port),
+                    'encoding_filter.on': True,
+                    'encodinf_filter.encoding': 'utf8',
+                    'static_filter.on': True,
+                    'static_filter.dir': static_dir,
+                    })
+            import pprint
+            pprint.pprint(cherrypy.config.configs)
+            cherrypy.server.start()
         s.cleanup()
index a2ba5a524d09432f796fc3d2ffae211f1b5d59ee..07843fb7dd891acfc68e3058372dbb1a6b1340b3 100644 (file)
@@ -21,6 +21,8 @@
 """Represent a cookbook and recipes with Python classes.
 """
 
+from __future__ import with_statement
+
 import os
 import os.path
 import textwrap