|
|
|
@@ -0,0 +1,24 @@ |
|
|
|
#!/usr/bin/python |
|
|
|
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*- |
|
|
|
|
|
|
|
from singleton import Singleton |
|
|
|
from template import render |
|
|
|
from functools import partial |
|
|
|
|
|
|
|
|
|
|
|
class WSGITemplate( object ): |
|
|
|
__metaclass__ = Singleton |
|
|
|
|
|
|
|
def __init__( self, basedir=None ): |
|
|
|
import os |
|
|
|
self.__basedir = os.path.normpath( os.path.join( os.path.split(__file__)[0], basedir ) ) + '/' |
|
|
|
|
|
|
|
|
|
|
|
def template(self, filename=None ): |
|
|
|
def real_decorator( wsgi_application ): |
|
|
|
def wrapper( environ, start_response ): |
|
|
|
environ[ 'template' ] = partial( render, filename= self.__basedir + filename ) |
|
|
|
environ[ 'basedir' ] = self.__basedir |
|
|
|
return wsgi_application( environ, start_response ) |
|
|
|
return wrapper |
|
|
|
return real_decorator |