summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2008-09-28 15:55:09 -0400
committerBarry Warsaw2008-09-28 15:55:09 -0400
commit39f1395cd1640fd639a2c824611fa1ad9f09a929 (patch)
treec3d0492dce4f2e912aea3aa616ce9a2881379197
parent512145d93efc318adc0250dd53f4a53d8738f679 (diff)
downloadmailman-39f1395cd1640fd639a2c824611fa1ad9f09a929.tar.gz
mailman-39f1395cd1640fd639a2c824611fa1ad9f09a929.tar.zst
mailman-39f1395cd1640fd639a2c824611fa1ad9f09a929.zip
-rw-r--r--mailman/Archiver/Archiver.py7
-rw-r--r--mailman/Archiver/HyperArch.py7
-rw-r--r--mailman/Defaults.py4
-rw-r--r--mailman/SafeDict.py55
-rw-r--r--mailman/Utils.py6
-rw-r--r--mailman/i18n.py1
-rw-r--r--mailman/templates/en/archidxentry.html6
-rw-r--r--mailman/templates/en/archidxfoot.html16
-rw-r--r--mailman/templates/en/archidxhead.html22
-rw-r--r--mailman/templates/en/archtoc.html20
-rw-r--r--mailman/templates/en/archtocentry.html12
-rw-r--r--mailman/templates/en/archtocnombox.html16
-rw-r--r--mailman/templates/en/article.html48
-rw-r--r--mailman/tests/test_safedict.py48
14 files changed, 80 insertions, 188 deletions
diff --git a/mailman/Archiver/Archiver.py b/mailman/Archiver/Archiver.py
index 23757b427..313bd9a0a 100644
--- a/mailman/Archiver/Archiver.py
+++ b/mailman/Archiver/Archiver.py
@@ -34,7 +34,6 @@ from string import Template
from mailman import Mailbox
from mailman import Utils
-from mailman.SafeDict import SafeDict
from mailman.configuration import config
from mailman.i18n import _
@@ -161,9 +160,9 @@ class Archiver:
raise
def ExternalArchive(self, ar, txt):
- d = SafeDict({'listname': self.fqdn_listname,
- 'hostname': self.host_name,
- })
+ cmd = Template(ar).safe_substitute(
+ listname=self.fqdn_listname,
+ hostname=self.host_name)
cmd = ar % d
extarch = os.popen(cmd, 'w')
extarch.write(txt)
diff --git a/mailman/Archiver/HyperArch.py b/mailman/Archiver/HyperArch.py
index 52a0bfa50..48e6d5835 100644
--- a/mailman/Archiver/HyperArch.py
+++ b/mailman/Archiver/HyperArch.py
@@ -42,13 +42,13 @@ from email.Charset import Charset
from email.Errors import HeaderParseError
from email.Header import decode_header, make_header
from locknix.lockfile import Lock
+from string import Template
from mailman import Utils
from mailman import i18n
from mailman.Archiver import HyperDatabase
from mailman.Archiver import pipermail
from mailman.Mailbox import ArchiverMailbox
-from mailman.SafeDict import SafeDict
from mailman.configuration import config
log = logging.getLogger('mailman.error')
@@ -199,15 +199,14 @@ def quick_maketext(templatefile, dict=None, lang=None, mlist=None):
text = template
if dict is not None:
try:
- sdict = SafeDict(dict)
try:
- text = sdict.interpolate(template)
+ text = Template(template).safe_substitute(**dict)
except UnicodeError:
# Try again after coercing the template to unicode
utemplate = unicode(template,
Utils.GetCharSet(lang),
'replace')
- text = sdict.interpolate(utemplate)
+ text = Template(utemplate).safe_substitute(**dict)
except (TypeError, ValueError):
# The template is really screwed up
pass
diff --git a/mailman/Defaults.py b/mailman/Defaults.py
index 1f862657d..a0aad0b8e 100644
--- a/mailman/Defaults.py
+++ b/mailman/Defaults.py
@@ -236,8 +236,8 @@ DEFAULT_DIGEST_VOLUME_FREQUENCY = 1
# be a shell command string which will get passed to os.popen(). This string
# can contain the following substitution strings:
#
-# %(listname)s -- gets the internal name of the list
-# %(hostname)s -- gets the email hostname for the list
+# $listname -- gets the internal name of the list
+# $hostname -- gets the email hostname for the list
#
# being archived will be substituted for this. Please note that os.popen() is
# used.
diff --git a/mailman/SafeDict.py b/mailman/SafeDict.py
deleted file mode 100644
index 31db1df67..000000000
--- a/mailman/SafeDict.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (C) 1998-2008 by the Free Software Foundation, Inc.
-#
-# This file is part of GNU Mailman.
-#
-# GNU Mailman is free software: you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option)
-# any later version.
-#
-# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
-
-from mailman.configuration import config
-
-"""A `safe' dictionary for string interpolation."""
-
-COMMASPACE = ', '
-
-# XXX This module should go away.
-
-
-
-class SafeDict(dict):
- """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='', charset=None, lang=None):
- super(SafeDict, self).__init__(d)
- if charset:
- self.cset = charset
- elif lang:
- self.cset = config.languages.get_charset(lang)
- else:
- self.cset = 'us-ascii'
-
- def __getitem__(self, key):
- try:
- return super(SafeDict, self).__getitem__(key)
- except KeyError:
- if isinstance(key, basestring):
- return '%('+key+')s'
- else:
- return '<Missing key: %s>' % `key`
-
- def interpolate(self, template):
- for k, v in self.items():
- if isinstance(v, str):
- self.__setitem__(k, unicode(v, self.cset))
- return template % self
diff --git a/mailman/Utils.py b/mailman/Utils.py
index 178fff538..c0d2620b3 100644
--- a/mailman/Utils.py
+++ b/mailman/Utils.py
@@ -37,12 +37,11 @@ import email.Header
import email.Iterators
from email.Errors import HeaderParseError
-from string import ascii_letters, digits, whitespace
+from string import ascii_letters, digits, whitespace, Template
import mailman.templates
from mailman import passwords
-from mailman.SafeDict import SafeDict
from mailman.configuration import config
from mailman.core import errors
@@ -525,8 +524,7 @@ def findtext(templatefile, dict=None, raw=False, lang=None, mlist=None):
text = template
if dict is not None:
try:
- sdict = SafeDict(dict, lang=lang)
- text = sdict.interpolate(template)
+ text = Template(template).safe_substitute(**dict)
except (TypeError, ValueError):
# The template is really screwed up
log.exception('broken template: %s', filename)
diff --git a/mailman/i18n.py b/mailman/i18n.py
index e9c58ad91..186965509 100644
--- a/mailman/i18n.py
+++ b/mailman/i18n.py
@@ -22,7 +22,6 @@ import string
import gettext
import mailman.messages
-from mailman.SafeDict import SafeDict
from mailman.configuration import config
_translation = None
diff --git a/mailman/templates/en/archidxentry.html b/mailman/templates/en/archidxentry.html
index f9bb57aab..1927ae7fe 100644
--- a/mailman/templates/en/archidxentry.html
+++ b/mailman/templates/en/archidxentry.html
@@ -1,4 +1,4 @@
-<LI><A HREF="%(filename)s">%(subject)s
-</A><A NAME="%(sequence)i">&nbsp;</A>
-<I>%(author)s
+<LI><A HREF="$filename">$subject
+</A><A NAME="$sequence">&nbsp;</A>
+<I>$author
</I>
diff --git a/mailman/templates/en/archidxfoot.html b/mailman/templates/en/archidxfoot.html
index 0b0a42075..6a43546ea 100644
--- a/mailman/templates/en/archidxfoot.html
+++ b/mailman/templates/en/archidxfoot.html
@@ -1,21 +1,21 @@
</ul>
<p>
<a name="end"><b>Last message date:</b></a>
- <i>%(lastdate)s</i><br>
- <b>Archived on:</b> <i>%(archivedate)s</i>
+ <i>$lastdate</i><br>
+ <b>Archived on:</b> <i>$archivedate</i>
<p>
<ul>
<li> <b>Messages sorted by:</b>
- %(thread_ref)s
- %(subject_ref)s
- %(author_ref)s
- %(date_ref)s
- <li><b><a href="%(listinfo)s">More info on this list...
+ $thread_ref
+ $subject_ref
+ $author_ref
+ $date_ref
+ <li><b><a href="$listinfo">More info on this list...
</a></b></li>
</ul>
<p>
<hr>
<i>This archive was generated by
- Pipermail %(version)s.</i>
+ Pipermail $version.</i>
</BODY>
</HTML>
diff --git a/mailman/templates/en/archidxhead.html b/mailman/templates/en/archidxhead.html
index 4fdf4731d..70a7558d7 100644
--- a/mailman/templates/en/archidxhead.html
+++ b/mailman/templates/en/archidxhead.html
@@ -1,24 +1,24 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
- <title>The %(listname)s %(archive)s Archive by %(archtype)s</title>
+ <title>The $listname $archive Archive by $archtype</title>
<META NAME="robots" CONTENT="noindex,follow">
- %(encoding)s
+ $encoding
</HEAD>
<BODY BGCOLOR="#ffffff">
<a name="start"></A>
- <h1>%(archive)s Archives by %(archtype)s</h1>
+ <h1>$archive Archives by $archtype</h1>
<ul>
<li> <b>Messages sorted by:</b>
- %(thread_ref)s
- %(subject_ref)s
- %(author_ref)s
- %(date_ref)s
+ $thread_ref
+ $subject_ref
+ $author_ref
+ $date_ref
- <li><b><a href="%(listinfo)s">More info on this list...
+ <li><b><a href="$listinfo">More info on this list...
</a></b></li>
</ul>
- <p><b>Starting:</b> <i>%(firstdate)s</i><br>
- <b>Ending:</b> <i>%(lastdate)s</i><br>
- <b>Messages:</b> %(size)s<p>
+ <p><b>Starting:</b> <i>$firstdate</i><br>
+ <b>Ending:</b> <i>$lastdate</i><br>
+ <b>Messages:</b> $size<p>
<ul>
diff --git a/mailman/templates/en/archtoc.html b/mailman/templates/en/archtoc.html
index 6969d5152..4dcaf5a50 100644
--- a/mailman/templates/en/archtoc.html
+++ b/mailman/templates/en/archtoc.html
@@ -1,20 +1,20 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
- <title>The %(listname)s Archives</title>
+ <title>The $listname Archives</title>
<META NAME="robots" CONTENT="noindex,follow">
- %(meta)s
+ $meta
</HEAD>
<BODY BGCOLOR="#ffffff">
- <h1>The %(listname)s Archives </h1>
+ <h1>The $listname Archives </h1>
<p>
- You can get <a href="%(listinfo)s">more information about this list</a>
- or you can <a href="%(fullarch)s">download the full raw archive</a>
- (%(size)s).
+ You can get <a href="$listinfo">more information about this list</a>
+ or you can <a href="$fullarch">download the full raw archive</a>
+ ($size).
</p>
- %(noarchive_msg)s
- %(archive_listing_start)s
- %(archive_listing)s
- %(archive_listing_end)s
+ $noarchive_msg
+ $archive_listing_start
+ $archive_listing
+ $archive_listing_end
</BODY>
</HTML>
diff --git a/mailman/templates/en/archtocentry.html b/mailman/templates/en/archtocentry.html
index 00cf9c47d..e2a6d2e37 100644
--- a/mailman/templates/en/archtocentry.html
+++ b/mailman/templates/en/archtocentry.html
@@ -1,12 +1,12 @@
<tr>
- <td>%(archivelabel)s:</td>
+ <td>$archivelabel:</td>
<td>
- <A href="%(archive)s/thread.html">[ Thread ]</a>
- <A href="%(archive)s/subject.html">[ Subject ]</a>
- <A href="%(archive)s/author.html">[ Author ]</a>
- <A href="%(archive)s/date.html">[ Date ]</a>
+ <A href="$archive/thread.html">[ Thread ]</a>
+ <A href="$archive/subject.html">[ Subject ]</a>
+ <A href="$archive/author.html">[ Author ]</a>
+ <A href="$archive/date.html">[ Date ]</a>
</td>
- %(textlink)s
+ $textlink
</tr>
diff --git a/mailman/templates/en/archtocnombox.html b/mailman/templates/en/archtocnombox.html
index 0b1239ec8..5989aa53d 100644
--- a/mailman/templates/en/archtocnombox.html
+++ b/mailman/templates/en/archtocnombox.html
@@ -1,18 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
- <title>The %(listname)s Archives</title>
+ <title>The $listname Archives</title>
<META NAME="robots" CONTENT="noindex,follow">
- %(meta)s
+ $meta
</HEAD>
<BODY BGCOLOR="#ffffff">
- <h1>The %(listname)s Archives </h1>
+ <h1>The $listname Archives </h1>
<p>
- You can get <a href="%(listinfo)s">more information about this list</a>.
+ You can get <a href="$listinfo">more information about this list</a>.
</p>
- %(noarchive_msg)s
- %(archive_listing_start)s
- %(archive_listing)s
- %(archive_listing_end)s
+ $noarchive_msg
+ $archive_listing_start
+ $archive_listing
+ $archive_listing_end
</BODY>
</HTML>
diff --git a/mailman/templates/en/article.html b/mailman/templates/en/article.html
index 38dbc5543..9ba25fe4e 100644
--- a/mailman/templates/en/article.html
+++ b/mailman/templates/en/article.html
@@ -1,50 +1,50 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
- <TITLE> %(title)s
+ <TITLE> $title
</TITLE>
<LINK REL="Index" HREF="index.html" >
- <LINK REL="made" HREF="mailto:%(email_url)s?Subject=%(subject_url)s&In-Reply-To=%(in_reply_to_url)s">
+ <LINK REL="made" HREF="mailto:${email_url}?Subject=${subject_url}&In-Reply-To=$in_reply_to_url">
<META NAME="robots" CONTENT="index,nofollow">
- %(encoding)s
- %(prev)s
- %(next)s
+ $encoding
+ $prev
+ $next
</HEAD>
<BODY BGCOLOR="#ffffff">
- <H1>%(subject_html)s</H1>
- <B>%(author_html)s</B>
- <A HREF="mailto:%(email_url)s?Subject=%(subject_url)s&In-Reply-To=%(in_reply_to_url)s"
- TITLE="%(subject_html)s">%(email_html)s
+ <H1>$subject_html</H1>
+ <B>$author_html</B>
+ <A HREF="mailto:${email_url}?Subject=${subject_url}&In-Reply-To=${in_reply_to_url}"
+ TITLE="$subject_html">$email_html
</A><BR>
- <I>%(datestr_html)s</I>
+ <I>$datestr_html</I>
<P><UL>
- %(prev_wsubj)s
- %(next_wsubj)s
+ $prev_wsubj
+ $next_wsubj
<LI> <B>Messages sorted by:</B>
- <a href="date.html#%(sequence)s">[ date ]</a>
- <a href="thread.html#%(sequence)s">[ thread ]</a>
- <a href="subject.html#%(sequence)s">[ subject ]</a>
- <a href="author.html#%(sequence)s">[ author ]</a>
+ <a href="date.html#$sequence">[ date ]</a>
+ <a href="thread.html#$sequence">[ thread ]</a>
+ <a href="subject.html#$sequence">[ subject ]</a>
+ <a href="author.html#$sequence">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
-%(body)s
+$body
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
- %(prev_wsubj)s
- %(next_wsubj)s
+ $prev_wsubj
+ $next_wsubj
<LI> <B>Messages sorted by:</B>
- <a href="date.html#%(sequence)s">[ date ]</a>
- <a href="thread.html#%(sequence)s">[ thread ]</a>
- <a href="subject.html#%(sequence)s">[ subject ]</a>
- <a href="author.html#%(sequence)s">[ author ]</a>
+ <a href="date.html#$sequence">[ date ]</a>
+ <a href="thread.html#$sequence">[ thread ]</a>
+ <a href="subject.html#$sequence">[ subject ]</a>
+ <a href="author.html#$sequence">[ author ]</a>
</LI>
</UL>
<hr>
-<a href="%(listurl)s">More information about the %(listname)s
+<a href="$listurl">More information about the $listname
mailing list</a><br>
</body></html>
diff --git a/mailman/tests/test_safedict.py b/mailman/tests/test_safedict.py
deleted file mode 100644
index 12abbdb97..000000000
--- a/mailman/tests/test_safedict.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright (C) 2001-2008 by the Free Software Foundation, Inc.
-#
-# This file is part of GNU Mailman.
-#
-# GNU Mailman is free software: you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option)
-# any later version.
-#
-# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
-
-"""Unit tests for the SafeDict module."""
-
-import email
-import unittest
-
-from mailman import SafeDict
-
-
-
-class TestSafeDict(unittest.TestCase):
- def test_okay(self):
- sd = SafeDict.SafeDict({'foo': 'bar'})
- si = '%(foo)s' % sd
- self.assertEqual(si, 'bar')
-
- def test_key_error(self):
- sd = SafeDict.SafeDict({'foo': 'bar'})
- si = '%(baz)s' % sd
- self.assertEqual(si, '%(baz)s')
-
- def test_key_error_not_string(self):
- key = ()
- sd = SafeDict.SafeDict({})
- self.assertEqual(sd[key], '<Missing key: ()>')
-
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestSafeDict))
- return suite