def run_tpl(self,script):
        """Templating system with the string substitution syntax
        introduced in Python 2.4"""

        # values must be strings, not lists
        dic = dict([ (k,v[0]) for k,v in self.body.items() ])
        # first check if the string.Template class is available
        if hasattr(string,"Template"): # Python 2.4 or above
            try:
                data = string.Template(open(script).read()).substitute(dic)
            except:
                exc_type,exc_value,tb=sys.exc_info()
                msg = exc_value.args[0]
                data = '%s in file %s : %s' \
                    %(exc_type.__name__,os.path.basename(script), 
                    cgi.escape(msg))
        else:
            data = "Unable to handle this syntax for " + \
                "string substitution. Python version must be 2.4 or above"
        self.resp_headers['Content-length'] = len(data)
        self.done(200,cStringIO.StringIO(data))
Templating system with the string substitution syntax
        introduced in Python 2.4
recipes/Python/392879_My_first_application_server/recipe-392879.py