import cherrypy
from buffet import BuffetTool, using_template, TemplateEngineMissing
missing_messages = {'kid_section':'Plugin not installed. Try "easy_install TurboKid" and restart this demo',
'cheetah_section': 'Plugin not installed. Try "easy_install TurboCheetah" and restart this demo',
'string_section': 'Plugin not installed. Try "easy_install BuffetString" and restart this demo',
'myghty_section': 'Plugin not installed. Try "easy_install BuffetMyghty" and restart this demo',
}
class EmptySection(object):
@cherrypy.expose
def index(self):
page_handler_name = cherrypy.request.path.rstrip('/').split('/').pop()
return missing_messages.get(page_handler_name, "Plugin not installed")
try:
class StringSection(object):
_cp_config = {'tools.buffet_s.on': True}
def __init__(self):
cherrypy.tools.buffet_s = BuffetTool('string', 'templates/string')
@cherrypy.expose
@using_template('generic_template')
def index(self):
return dict(title="New String Test", message="""
End Points are fun!
Composition with multiple templates
""")
@cherrypy.expose
def multi_test(self):
return (
('head',
dict(title="Composition Test")
),
('body',
dict(message="Thanks to Bill Mill")
),
('foot', {}
)
)
except TemplateEngineMissing:
StringSection = EmptySection
try:
class CheetahSection(object):
_cp_config = {'tools.buffet_c.on': True}
def __init__(self):
cherrypy.tools.buffet_c = BuffetTool('cheetah')
@cherrypy.expose
@using_template('templates/cheetah/test')
def index(self):
return dict(title="New TurboCheetah Test",
message="Buffet does TurboCheetah!")
except TemplateEngineMissing:
CheetahSection = EmptySection
try:
class KidSection(object):
_cp_config = {'tools.buffet_k.on': True}
def __init__(self):
cherrypy.tools.buffet_k = BuffetTool('kid')
@cherrypy.expose
@using_template('templates/kid/test')
def index(self):
return dict(title="Kid at a Buffet",
message="All you can eat templates.")
except TemplateEngineMissing:
KidSection = EmptySection
try:
class MyghtySection(object):
try:
# attempt to import a Myghty-customized error handler
from cpmyghty import _cp_on_error
except ImportError:
pass
_cp_config = {'tools.buffet_m.on': True}
def __init__(self):
cherrypy.config.update({'myghty_app':{'component_root':'.',
'raise_error':True,
}
})
cherrypy.tools.buffet_m = BuffetTool('myghty',
config_section="myghty_app")
@cherrypy.expose
@using_template('templates/myghty/test')
def index(self):
return dict(title="Myghty good Buffet",
message="Fill up another template.")
@cherrypy.expose
@using_template('templates/myghty/test')
def exception(self):
return dict()
@cherrypy.expose
def cp_exc(self):
3 / 0
return "ha"
except TemplateEngineMissing:
MyghtySection = EmptySection
class TmplTest(object):
string_section = StringSection()
cheetah_section = CheetahSection()
kid_section = KidSection()
myghty_section = MyghtySection()
def index(self):
return "string
\
cheetah
\
kid
\
myghty
\
"
index.exposed = True
cherrypy.config.update({'global':{'engine.autoreload_on':False,
## 'server.log_to_screen':False,
'server.socket_port': 9999,
}
})
cherrypy.quickstart(TmplTest())