<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from cStringIO import StringIO <EOL> from mako . lookup import TemplateLookup <EOL> from mako . runtime import Context <EOL> from werkzeug import cached_property <EOL> default_config = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> class Mako ( object ) : <EOL> def __init__ ( self , app , _globals = None , filters = None ) : <EOL> self . app = app <EOL> config = app . config [ __name__ ] <EOL> dirs = config . get ( '<STR_LIT>' ) <EOL> if isinstance ( dirs , basestring ) : <EOL> dirs = [ dirs ] <EOL> self . environment = TemplateLookup ( directories = dirs , <EOL> output_encoding = '<STR_LIT:utf-8>' , encoding_errors = '<STR_LIT:replace>' ) <EOL> def render ( self , _filename , ** context ) : <EOL> """<STR_LIT>""" <EOL> template = self . environment . get_template ( _filename ) <EOL> return template . render_unicode ( ** context ) <EOL> def render_template ( self , _handler , _filename , ** context ) : <EOL> """<STR_LIT>""" <EOL> ctx = _handler . context . copy ( ) <EOL> ctx . update ( context ) <EOL> return self . render ( _filename , ** ctx ) <EOL> def render_response ( self , _handler , _filename , ** context ) : <EOL> """<STR_LIT>""" <EOL> res = self . render_template ( _handler , _filename , ** context ) <EOL> return self . app . response_class ( res ) <EOL> @ classmethod <EOL> def factory ( cls , _app , _name , ** kwargs ) : <EOL> if _name not in _app . registry : <EOL> _app . registry [ _name ] = cls ( _app , ** kwargs ) <EOL> return _app . registry [ _name ] <EOL> class MakoMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> mako_class = Mako <EOL> @ cached_property <EOL> def mako ( self ) : <EOL> return self . mako_class . factory ( self . app , '<STR_LIT>' ) <EOL> def render_template ( self , _filename , ** context ) : <EOL> return self . mako . render_template ( self , _filename , ** context ) <EOL> def render_response ( self , _filename , ** context ) : <EOL> return self . mako . render_response ( self , _filename , ** context ) </s>
