# This patch file, files created by its use and not subject to other copyright # and any changes in other files generated by its use are # Copyright (C) 2000-2003 by the Free Software Foundation, Inc. # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA # This patch file is Free Software and permission is granted to copy and # redistribute it in original or modified form under the terms of the # GNU General Public License (GPL). # See the GPL COPYING files accompanying Mailman distributions this # patch was intended to work in conjunction with for further details. diff -r -u -P mailman-2.1.2/Mailman/Archiver/HyperArch.py mailman-2.1.2-tempcache/Mailman/Archiver/HyperArch.py --- mailman-2.1.2/Mailman/Archiver/HyperArch.py Sat Feb 8 07:13:49 2003 +++ mailman-2.1.2-tempcache/Mailman/Archiver/HyperArch.py Thu May 1 12:48:12 2003 @@ -159,21 +159,37 @@ -# This doesn't need to be a weakref instance because it's just storing -# strings. Keys are (templatefile, lang) tuples. +# Two caches are maintained. +# +# _templatefilepathcache is used to associate a (templatefile, lang, listname) +# key with the file system path to a template file. This path is the one +# that the Utils.maketext() function has computed is the one to match the +# values in the key tuple. +# +# _templatecache associate a file system path as key with the text +# returned after processing the contents of that file by Utilts.maketext() +# + +_templatefilepathcache = {} _templatecache = {} def quick_maketext(templatefile, dict=None, lang=None, mlist=None): + if mlist: + listname = mlist._internal_name + else: + listname = '' if lang is None: if mlist is None: lang = mm_cfg.DEFAULT_SERVER_LANGUAGE else: lang = mlist.preferred_language - template = _templatecache.get((templatefile, lang)) + cachekey = (templatefile, lang, listname) + template = _templatecache.get(cachekey) if template is None: # Use the basic maketext, with defaults to get the raw template - template = Utils.maketext(templatefile, lang=lang, raw=1) - _templatecache[(templatefile, lang)] = template + (template, filepath) = Utils.real_maketext(templatefile, lang=lang, raw=1, mlist=mlist) + _templatefilepathcache[cachekey] = filepath + _templatecache[filepath] = template # Copied from Utils.maketext() text = template if dict is not None: diff -r -u -P mailman-2.1.2/Mailman/Utils.py mailman-2.1.2-tempcache/Mailman/Utils.py --- mailman-2.1.2/Mailman/Utils.py Mon Apr 7 23:51:14 2003 +++ mailman-2.1.2-tempcache/Mailman/Utils.py Thu May 1 12:23:01 2003 @@ -381,7 +381,7 @@ -def maketext(templatefile, dict=None, raw=False, lang=None, mlist=None): +def real_maketext(templatefile, dict=None, raw=False, lang=None, mlist=None): # Make some text from a template file. The order of searches depends on # whether mlist and lang are provided. Once the templatefile is found, # string substitution is performed by interpolation in `dict'. If `raw' @@ -426,6 +426,12 @@ # on the above description. Mailman's upgrade script cannot do this for # you. # + # The function has been revised and renamed as it now returns both the + # template text and the path in the file system from which it retrieved the + # template. The original function name is now a wrapper function which just + # returns the tempate text as before after calling this renamed function and + # discarding the second item it returns. + # # Calculate the languages to scan languages = [] if lang is not None: @@ -460,7 +466,8 @@ # Try one last time with the distro English template, which, unless # you've got a really broken installation, must be there. try: - fp = open(os.path.join(mm_cfg.TEMPLATE_DIR, 'en', templatefile)) + filename = os.path.join(mm_cfg.TEMPLATE_DIR, 'en', templatefile) + fp = open(filename) except IOError, e: if e.errno <> errno.ENOENT: raise # We never found the template. BAD! @@ -483,9 +490,11 @@ syslog('error', 'broken template: %s\n%s', filename, e) pass if raw: - return text - return wrap(text) + return (text, filename) + return (wrap(text), filename) +def maketext(templatefile, dict=None, raw=False, lang=None, mlist=None): + return real_maketext(templatefile, dict=dict, raw=raw, lang=lang, mlist=mlist)[0] ADMINDATA = {