From: W. Trevor King Date: Mon, 21 Jun 2010 19:20:35 +0000 (-0400) Subject: Assorted fixes to work with Python 2.5 and CherryPy 2.3 X-Git-Tag: v0.1~27 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=99e58954a237398e78bc9b468f6c936be43b12cb;p=cookbook.git Assorted fixes to work with Python 2.5 and CherryPy 2.3 The earlier version worked in Python 2.6 and CherryPy 3.x. --- diff --git a/bin/cook.py b/bin/cook.py index 2a99471..ab9f774 100755 --- a/bin/cook.py +++ b/bin/cook.py @@ -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() diff --git a/cookbook/cookbook.py b/cookbook/cookbook.py index a2ba5a5..07843fb 100644 --- a/cookbook/cookbook.py +++ b/cookbook/cookbook.py @@ -21,6 +21,8 @@ """Represent a cookbook and recipes with Python classes. """ +from __future__ import with_statement + import os import os.path import textwrap