CherryPy Project Download

Changeset 3

Show
Ignore:
Timestamp:
05/14/07 15:45:30
Author:
jtate
Message:

Revise kidrender from feedback given in #cherrypy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • kidrender/__init__.py

    r2 r3  
    3333 
    3434class KidRender(cherrypy.Tool): 
    35     def __init__(self): 
    36         self._name = Non
    37         self._point = 'before_finalize
    38         self._priority = 99 
     35    def __init__(self, name=None, priority = 0): 
     36        self._name = nam
     37        self._point = 'before_handler
     38        self._priority = priority 
    3939        self._templatecache = {} 
    4040 
     
    5656            @param assume_encoding: Format to use when parsing the kid template 
    5757        ''' 
    58         templ = self._templatecache.get(template, None) 
    59         if not templ: 
    60             templ = kid.import_template(name=template) 
    61             self._templatecache[template] = templ 
    62         t = templ.Template(**cherrypy.response.body) 
    63         t.assume_encoding=assume_encoding 
    64         cherrypy.response.body = t.serialize(output=output, encoding=encoding) 
    65         if output is None or 'xhtml' in output: 
    66             if 'application/xhtml+xml' in cherrypy.request.headers['Accept']: 
    67                 cherrypy.response.headers['Content-Type'] = 'application/xhtml+xml' 
    68             else: 
    69                 #This is nasty, but such is the state of XHTML today 
    70                 cherrypy.response.headers['Content-Type'] = 'text/html; charset=%s' % encoding 
     58        cherrypy.request._handler = cherrypy.request.handler 
     59        def wrap(*args, **kwargs): 
     60            ret = cherrypy.request._handler(*args, **kwargs) 
     61            templ = self._templatecache.get(template, None) 
     62            if not templ: 
     63                templ = kid.import_template(name=template) 
     64                self._templatecache[template] = templ 
     65            t = templ.Template(**ret) 
     66            t.assume_encoding=assume_encoding 
     67            out = t.serialize(output=output, encoding=encoding) 
     68            if output is None or 'xhtml' in output: 
     69                if 'application/xhtml+xml' in cherrypy.request.headers['Accept']: 
     70                    cherrypy.response.headers['Content-Type'] = 'application/xhtml+xml' 
     71                else: 
     72                    #This is nasty, but such is the state of XHTML today 
     73                    cherrypy.response.headers['Content-Type'] = 'text/html; charset=%s' % encoding 
     74            return out 
    7175 
     76        cherrypy.request.handler = wrap 
     77 

Hosted by WebFaction

Log in as guest/cherrypy to create/edit wiki pages