~barry/mailman/templatecache

« back to all changes in this revision

Viewing changes to src/mailman/utilities/string.py

  • Committer: Barry Warsaw
  • Date: 2012-10-31 16:37:22 UTC
  • mfrom: (7178.1.1 work2)
  • Revision ID: barry@list.org-20121031163722-3lszhsiv9ai0akfp
 * Python 2.7 is not required.  Python 2.6 is no longer officially supported.
   The code base is now also `python2.7 -3` clean, although there are still
   some warnings in 3rd party dependencies.  LP: #1073506

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    :return: The substituted string.
61
61
    :rtype: string
62
62
    """
63
 
    # Python 2.6 requires ** dictionaries to have str, not unicode keys, so
64
 
    # convert as necessary.  Note that string.Template uses **.  For our
65
 
    # purposes, keys should always be ascii.  Values though can be anything.
66
 
    cooked = substitutions.__class__()
67
 
    for key in substitutions:
68
 
        if isinstance(key, unicode):
69
 
            key = key.encode('ascii')
70
 
        cooked[key] = substitutions[key]
71
 
    try:
72
 
        return template_class(template).safe_substitute(cooked)
73
 
    except (TypeError, ValueError):
74
 
        # The template is really screwed up.
75
 
        log.exception('broken template: %s', template)
 
63
    return template_class(template).safe_substitute(substitutions)
76
64
 
77
65
 
78
66