Patch to make errors in templates not cause the thing to die, but to send *something* so that you can diagnose the problem more easily. from mailman-developers, 2 September 1999. diff -c -r1.75 Utils.py *** Utils.py 1999/09/02 19:39:08 1.75 --- Utils.py 1999/09/02 19:51:38 *************** *** 27,32 **** --- 27,34 ---- import os import string import re + from UserDict import UserDict + from types import StringType # XXX: obsolete, should use re module import regsub import random *************** *** 620,625 **** --- 622,645 ---- + class SafeDict(UserDict): + """Dictionary which returns a default value for unknown keys. + + This is used in maketext so that editing templates is a bit more robust. + """ + def __init__(self, d): + UserDict.__init__(self) + self.update(d) + + def __getitem__(self, key): + try: + return self.data[key] + except KeyError: + if type(key) == StringType: + return '%('+key+')s' + else: + return '' % `key` + + def maketext(templatefile, dict, raw=0): """Make some text from a template file. *************** *** 631,639 **** fp = open(file) template = fp.read() fp.close() if raw: ! return template % dict ! return wrap(template % dict) --- 651,660 ---- fp = open(file) template = fp.read() fp.close() + text = template % SafeDict(dict) if raw: ! return text ! return wrap(text)