summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2007-03-21 14:11:53 +0000
committerbwarsaw2007-03-21 14:11:53 +0000
commitfc51f4c9de9751c03fb21394b393253e8c225453 (patch)
treea931a2a61e156ca8332a92d6369163741f8e506d
parentcf950f7430ecabc8d4ff370c4f9e6e01f7b44fd4 (diff)
downloadmailman-fc51f4c9de9751c03fb21394b393253e8c225453.tar.gz
mailman-fc51f4c9de9751c03fb21394b393253e8c225453.tar.zst
mailman-fc51f4c9de9751c03fb21394b393253e8c225453.zip
-rw-r--r--Mailman/Handlers/Acknowledge.py4
-rw-r--r--Mailman/Handlers/CookHeaders.py1
-rw-r--r--Mailman/Handlers/Hold.py16
-rw-r--r--Mailman/Handlers/ToDigest.py5
-rw-r--r--Mailman/MailList.py3
-rw-r--r--Mailman/i18n.py32
-rw-r--r--Mailman/testing/base.py16
-rw-r--r--Mailman/testing/test_handlers.py2
8 files changed, 49 insertions, 30 deletions
diff --git a/Mailman/Handlers/Acknowledge.py b/Mailman/Handlers/Acknowledge.py
index 609f6ea8a..d02920cde 100644
--- a/Mailman/Handlers/Acknowledge.py
+++ b/Mailman/Handlers/Acknowledge.py
@@ -29,6 +29,8 @@ from Mailman import Utils
from Mailman.configuration import config
from Mailman.i18n import _
+__i18n_templates__ = True
+
def process(mlist, msg, msgdata):
@@ -57,7 +59,7 @@ def process(mlist, msg, msgdata):
# Craft the outgoing message, with all headers and attributes
# necessary for general delivery. Then enqueue it to the outgoing
# queue.
- subject = _('%(realname)s post acknowledgement')
+ subject = _('$realname post acknowledgement')
usermsg = Message.UserNotification(sender, mlist.GetBouncesEmail(),
subject, text, lang)
usermsg.send(mlist)
diff --git a/Mailman/Handlers/CookHeaders.py b/Mailman/Handlers/CookHeaders.py
index c28ec25ab..11f08acc8 100644
--- a/Mailman/Handlers/CookHeaders.py
+++ b/Mailman/Handlers/CookHeaders.py
@@ -276,7 +276,6 @@ def prefix_subject(mlist, msg, msgdata):
if subject.strip() == '':
subject = _('(no subject)')
cset = Utils.GetCharSet(mlist.preferred_language)
- subject = unicode(subject, cset)
# and substitute %d in prefix with post_id
try:
prefix = prefix % mlist.post_id
diff --git a/Mailman/Handlers/Hold.py b/Mailman/Handlers/Hold.py
index 180b6fd70..d13babba6 100644
--- a/Mailman/Handlers/Hold.py
+++ b/Mailman/Handlers/Hold.py
@@ -49,6 +49,8 @@ log = logging.getLogger('mailman.vette')
def _(s):
return s
+__i18n_templates__ = True
+
class ForbiddenPoster(Errors.HoldMessage):
@@ -84,8 +86,8 @@ class Administrivia(Errors.HoldMessage):
listurl = mlist.GetScriptURL('listinfo', absolute=1)
request = mlist.GetRequestEmail()
return _("""Please do *not* post administrative requests to the mailing
-list. If you wish to subscribe, visit %(listurl)s or send a message with the
-word `help' in it to the request address, %(request)s, for further
+list. If you wish to subscribe, visit $listurl or send a message with the
+word `help' in it to the request address, $request, for further
instructions.""")
class SuspiciousHeaders(Errors.HoldMessage):
@@ -100,13 +102,13 @@ class MessageTooBig(Errors.HoldMessage):
def reason_notice(self):
size = self.__msgsize
limit = self.__limit
- return _('''Message body is too big: %(size)d bytes with a limit of
-%(limit)d KB''')
+ return _('''Message body is too big: $size bytes with a limit of
+$limit KB''')
def rejection_notice(self, mlist):
kb = self.__limit
return _('''Your message was too big; please trim it to less than
-%(kb)d KB in size.''')
+$kb KB in size.''')
class ModeratedNewsgroup(ModeratedPost):
reason = _('Posting to a moderated newsgroup')
@@ -244,7 +246,7 @@ def hold_for_approval(mlist, msg, msgdata, exc):
d['confirmurl'] = '%s/%s' % (mlist.GetScriptURL('confirm', absolute=1),
cookie)
lang = msgdata.get('lang', mlist.getMemberLanguage(sender))
- subject = _('Your message to %(listname)s awaits moderator approval')
+ subject = _('Your message to $listname awaits moderator approval')
text = Utils.maketext('postheld.txt', d, lang=lang, mlist=mlist)
nmsg = Message.UserNotification(sender, adminaddr, subject, text, lang)
nmsg.send(mlist)
@@ -263,7 +265,7 @@ def hold_for_approval(mlist, msg, msgdata, exc):
d['reason'] = _(reason)
d['subject'] = usersubject
# craft the admin notification message and deliver it
- subject = _('%(listname)s post from %(sender)s requires approval')
+ subject = _('$listname post from $sender requires approval')
nmsg = Message.UserNotification(owneraddr, owneraddr, subject,
lang=lang)
nmsg.set_type('multipart/mixed')
diff --git a/Mailman/Handlers/ToDigest.py b/Mailman/Handlers/ToDigest.py
index 3b22c6cee..e43cb68ce 100644
--- a/Mailman/Handlers/ToDigest.py
+++ b/Mailman/Handlers/ToDigest.py
@@ -54,6 +54,7 @@ from Mailman.Queue.sbcache import get_switchboard
from Mailman.configuration import config
_ = i18n._
+__i18n_templates__ = True
UEMPTYSTRING = u''
EMPTYSTRING = ''
@@ -146,7 +147,7 @@ def send_i18n_digests(mlist, mboxfp):
realname = mlist.real_name
volume = mlist.volume
issue = mlist.next_digest_number
- digestid = _('%(realname)s Digest, Vol %(volume)d, Issue %(issue)d')
+ digestid = _('$realname Digest, Vol $volume, Issue $issue')
digestsubj = Header(digestid, lcset, header_name='Subject')
# Set things up for the MIME digest. Only headers not added by
# CookHeaders need be added here.
@@ -292,7 +293,7 @@ def send_i18n_digests(mlist, mboxfp):
toctext = toc.getvalue()
# MIME
tocpart = MIMEText(toctext.encode(lcset), _charset=lcset)
- tocpart['Content-Description']= _("Today's Topics (%(msgcount)d messages)")
+ tocpart['Content-Description']= _("Today's Topics ($msgcount messages)")
mimemsg.attach(tocpart)
# RFC 1153
print >> plainmsg, toctext
diff --git a/Mailman/MailList.py b/Mailman/MailList.py
index 640baa314..fcdbca9a6 100644
--- a/Mailman/MailList.py
+++ b/Mailman/MailList.py
@@ -403,8 +403,7 @@ class MailList(object, HTMLFormatter, Deliverer, ListAdmin,
config.DEFAULT_BOUNCE_MATCHING_HEADERS
self.header_filter_rules = []
self.anonymous_list = config.DEFAULT_ANONYMOUS_LIST
- internalname = self.internal_name()
- self.real_name = internalname[0].upper() + internalname[1:]
+ self.real_name = self.internal_name().capitalize()
self.description = ''
self.info = ''
self.welcome_msg = ''
diff --git a/Mailman/i18n.py b/Mailman/i18n.py
index 59d10db25..66584e895 100644
--- a/Mailman/i18n.py
+++ b/Mailman/i18n.py
@@ -73,7 +73,7 @@ if _translation is None:
def _(s):
if s == '':
- return s
+ return u''
assert s
# Do translation of the given string into the current language, and do
# Ping-string interpolation into the resulting string.
@@ -97,24 +97,24 @@ def _(s):
d = frame.f_globals.copy()
d.update(frame.f_locals)
use_templates = d.get('__i18n_templates__', False)
- # Translating the string returns an encoded 8-bit string. Rather than
- # turn that into a Unicode, we turn any Unicodes in the dictionary values
- # into encoded 8-bit strings. XXX: Returning a Unicode here broke too
- # much other stuff and _() has many tentacles. Eventually I think we want
- # to use Unicode everywhere.
- tns = _translation.gettext(s)
- charset = _translation.charset()
- if not charset:
- charset = 'us-ascii'
+ # Mailman must be unicode safe internally (i.e. all strings inside Mailman
+ # must be unicodes). The translation service is one boundary to the
+ # outside world, so to honor this constraint, make sure that all strings
+ # to come out of _() are unicodes, even if the translated string or
+ # dictionary values are 8-bit strings.
+ tns = _translation.ugettext(s)
+ charset = _translation.charset() or 'us-ascii'
for k, v in d.items():
- if isinstance(v, unicode):
- d[k] = v.encode(charset, 'replace')
+ if isinstance(v, str):
+ d[k] = unicode(v, charset, 'replace')
# Are we using $-strings or %-strings?
if use_templates:
- return Template(tns).safe_substitute(attrdict(d))
- if type(tns) == str:
- tns = unicode(tns, charset)
- return SafeDict(d, charset=charset).interpolate(tns)
+ translated_string = Template(tns).safe_substitute(attrdict(d))
+ else:
+ translated_string = SafeDict(d, charset=charset).interpolate(tns)
+ if isinstance(translated_string, str):
+ translated_string = unicode(translated_string, charset)
+ return translated_string
diff --git a/Mailman/testing/base.py b/Mailman/testing/base.py
index a61740956..2979ad18b 100644
--- a/Mailman/testing/base.py
+++ b/Mailman/testing/base.py
@@ -19,7 +19,9 @@
import os
import grp
+import new
import pwd
+import sys
import stat
import shutil
import difflib
@@ -39,6 +41,11 @@ NL = '\n'
+def dummy_mta_function(*args, **kws):
+ pass
+
+
+
class TestBase(unittest.TestCase):
def _configure(self, fp):
# Make sure that we don't pollute the real database with our test
@@ -46,6 +53,9 @@ class TestBase(unittest.TestCase):
test_engine_url = 'sqlite:///' + self._dbfile
print >> fp, 'SQLALCHEMY_ENGINE_URL = "%s"' % test_engine_url
config.SQLALCHEMY_ENGINE_URL = test_engine_url
+ # Use the Mailman.MTA.stub module
+ print >> fp, 'MTA = "stub"'
+ config.MTA = 'stub'
print >> fp, 'add_domain("example.com", "www.example.com")'
# Only add this domain once to the current process
if 'example.com' not in config.domains:
@@ -80,6 +90,12 @@ class TestBase(unittest.TestCase):
self._configure(fp)
finally:
fp.close()
+ # Create a fake new Mailman.MTA module which stubs out the create()
+ # and remove() functions.
+ stubmta_module = new.module('Mailman.MTA.stub')
+ sys.modules['Mailman.MTA.stub'] = stubmta_module
+ stubmta_module.create = dummy_mta_function
+ stubmta_module.remove = dummy_mta_function
# Be sure to close the connection to the current database, and then
# reconnect to the new temporary SQLite database. Otherwise we end up
# with turds in the main database and our qrunner subprocesses won't
diff --git a/Mailman/testing/test_handlers.py b/Mailman/testing/test_handlers.py
index 2e964389e..849ccfb91 100644
--- a/Mailman/testing/test_handlers.py
+++ b/Mailman/testing/test_handlers.py
@@ -129,7 +129,7 @@ From: aperson@example.org
eq(qdata.get('recips'), ['aperson@example.org'])
eq(qdata.get('version'), 3)
# Check the .pck
- eq(str(str(qmsg['subject'])), '_xtest post acknowledgement')
+ eq(str(qmsg['subject']), '_xtest post acknowledgement')
eq(qmsg['to'], 'aperson@example.org')
eq(qmsg['from'], '_xtest-bounces@example.com')
eq(qmsg.get_content_type(), 'text/plain')