diff options
| author | Barry Warsaw | 2011-05-08 05:35:18 +0200 |
|---|---|---|
| committer | Barry Warsaw | 2011-05-08 05:35:18 +0200 |
| commit | cf35116509b12bf067893231ffaca3733dbf6f4e (patch) | |
| tree | 49ba1cbb65df489ed26632e697ff1556c2b0f3ce /src/mailman/utilities/i18n.py | |
| parent | 9dc1a0fbc0315840ef745fe736700c0376bb6976 (diff) | |
| download | mailman-cf35116509b12bf067893231ffaca3733dbf6f4e.tar.gz mailman-cf35116509b12bf067893231ffaca3733dbf6f4e.tar.zst mailman-cf35116509b12bf067893231ffaca3733dbf6f4e.zip | |
Diffstat (limited to 'src/mailman/utilities/i18n.py')
| -rw-r--r-- | src/mailman/utilities/i18n.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/mailman/utilities/i18n.py b/src/mailman/utilities/i18n.py index 000e74ac6..cdc25530d 100644 --- a/src/mailman/utilities/i18n.py +++ b/src/mailman/utilities/i18n.py @@ -28,23 +28,28 @@ __all__ = [ import os +import sys import errno from itertools import product from mailman.config import config from mailman.core.constants import system_preferences +from mailman.core.errors import MailmanException from mailman.core.i18n import _ from mailman.utilities.string import expand, wrap as wrap_text -class TemplateNotFoundError(Exception): +class TemplateNotFoundError(MailmanException): """The named template was not found.""" def __init__(self, template_file): self.template_file = template_file + def __str__(self): + return self.template_file + def _search(template_file, mailing_list=None, language=None): @@ -70,7 +75,7 @@ def _search(template_file, mailing_list=None, language=None): -def find(template_file, mailing_list=None, language=None): +def find(template_file, mailing_list=None, language=None, _trace=False): """Locate an i18n template file. When something in Mailman needs a template file, it always asks for the @@ -140,6 +145,9 @@ def find(template_file, mailing_list=None, language=None): :type mailing_list: `IMailingList` :param language: Optional language code, which influences the search. :type language: string + :param _trace: Enable printing of debugging information during + template search. + :type _trace: bool :return: A tuple of the file system path to the first matching template, and an open file object allowing reading of the file. :rtype: (string, file) @@ -148,16 +156,24 @@ def find(template_file, mailing_list=None, language=None): raw_search_order = _search(template_file, mailing_list, language) for path in raw_search_order: try: + if _trace: + print >> sys.stderr, '@@@', path, fp = open(path) except IOError as error: - if error.errno != errno.ENOENT: + if error.errno == errno.ENOENT: + if _trace: + print >> sys.stderr, 'MISSING' + else: raise else: + if _trace: + print >> sys.stderr, 'FOUND:', path return path, fp raise TemplateNotFoundError(template_file) -def make(template_file, mailing_list=None, language=None, wrap=True, **kw): +def make(template_file, mailing_list=None, language=None, wrap=True, + _trace=False, **kw): """Locate and 'make' a template file. The template file is located as with `find()`, and the resulting text is @@ -173,12 +189,15 @@ def make(template_file, mailing_list=None, language=None, wrap=True, **kw): :type language: string :param wrap: When True, wrap the text. :type wrap: bool + :param _trace: Passed through to ``find()``, this enables printing of + debugging information during template search. + :type _trace: bool :param **kw: Keyword arguments for template interpolation. :return: The interpolated text. :rtype: string :raises TemplateNotFoundError: when the template could not be found. """ - path, fp = find(template_file, mailing_list, language) + path, fp = find(template_file, mailing_list, language, _trace) try: # XXX Removing the trailing newline is a hack carried over from # Mailman 2. The (stripped) template text is then passed through the |
