text: import cherrypy
  
  from mako.lookup import TemplateLookup
  
  class MakoHandler(cherrypy.dispatch.LateParamPageHandler):
      """Callable which sets response.body."""
      
      def __init__(self, template, next_handler):
          self.template = template
          self.next_handler = next_handler
      
      def __call__(self):
          env = globals().copy()
          env.update(self.next_handler())
          try:
              return self.template.render(**env)
          except:
              # something went wrong rendering the template
              # this will generate a pretty error page with details
              cherrypy.response.status = "500"
              return exceptions.html_error_template().render()
  
  
  class MakoLoader(object):
      
      def __init__(self):
          self.lookups = {}
      
      def __call__(self, filename, directories, module_directory=None,
                   collection_size=-1):
          # Find the appropriate template lookup.
          key = (tuple(directories), module_directory)
          try:
              lookup = self.lookups[key]
          except KeyError:
              lookup = TemplateLookup(directories=directories,
                                      module_directory=module_directory,
                                      collection_size=collection_size,
                                      )
              self.lookups[key] = lookup
          cherrypy.request.lookup = lookup
          
          # Replace the current handler.
          cherrypy.request.template = t = lookup.get_template(filename)
          cherrypy.request.handler = MakoHandler(t, cherrypy.request.handler)