def findtext(self, template, dict=None): """Make some text from a template file. Once the templatefile is found, string substitution is performed by interpolation in `dict'.""" if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, 'utf-8', 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError), e: # The template is really screwed up raise Exception, "This template is really screwed up"