Revision: 8171
http://svn.sourceforge.net/mailman/?rev=8171&view=rev
Author: bwarsaw
Date: 2007-03-21 07:11:53 -0700 (Wed, 21 Mar 2007)
Log Message:
-----------
Test suite repair. All tests are now passing again.
- In i18n.py, change this method so that everything it returns will be
guaranteed to be a unicode. Mailman 2.2 will be unicode-safe, meaning all
strings internally will be unicodes. The translation service is one
boundary point were strings come from the outside, so ensure that they are
unicodes and convert if necessary. This may break some things, but it's
better to fix those situations than to continue to return 8-bit strings from
_().
- In Mailman/testing/base.py, craft a fake module called Mailman.MTA.stub and
stick no-op functions on stub.create() and stub.remove(). We really don't
need the MTA modules for testing purposes (yet at least), and if you're
using the default configuration, you'll get tons of cruft on stdout when the
Manual MTA tries to add and remove mailing lists.
Set up the test configuration environment to use this stub MTA module.
- In test_handlers.py, remove an extraneous str().
- Convert ToDigest.py, Hold.py and Acknowledge.py to __i18n_templates__. (I'm
pretty darn close to just making everything use $-strings by default.)
- In CookHeaders.py, there's no need to unicode()-ify the subject since that
should already be a unicode when passed from _().
- In MailList.py, we can use the str.capitalize() method.
Modified Paths:
--------------
trunk/mailman/Mailman/Handlers/Acknowledge.py
trunk/mailman/Mailman/Handlers/CookHeaders.py
trunk/mailman/Mailman/Handlers/Hold.py
trunk/mailman/Mailman/Handlers/ToDigest.py
trunk/mailman/Mailman/MailList.py
trunk/mailman/Mailman/i18n.py
trunk/mailman/Mailman/testing/base.py
trunk/mailman/Mailman/testing/test_handlers.py
Modified: trunk/mailman/Mailman/Handlers/Acknowledge.py
===================================================================
--- trunk/mailman/Mailman/Handlers/Acknowledge.py 2007-03-21 00:06:04 UTC
(rev 8170)
+++ trunk/mailman/Mailman/Handlers/Acknowledge.py 2007-03-21 14:11:53 UTC
(rev 8171)
@@ -29,7 +29,9 @@
from Mailman.configuration import config
from Mailman.i18n import _
+__i18n_templates__ = True
+
def process(mlist, msg, msgdata):
# Extract the sender's address and find them in the user database
@@ -57,7 +59,7 @@
# 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)
Modified: trunk/mailman/Mailman/Handlers/CookHeaders.py
===================================================================
--- trunk/mailman/Mailman/Handlers/CookHeaders.py 2007-03-21 00:06:04 UTC
(rev 8170)
+++ trunk/mailman/Mailman/Handlers/CookHeaders.py 2007-03-21 14:11:53 UTC
(rev 8171)
@@ -276,7 +276,6 @@
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
Modified: trunk/mailman/Mailman/Handlers/Hold.py
===================================================================
--- trunk/mailman/Mailman/Handlers/Hold.py 2007-03-21 00:06:04 UTC (rev
8170)
+++ trunk/mailman/Mailman/Handlers/Hold.py 2007-03-21 14:11:53 UTC (rev
8171)
@@ -49,7 +49,9 @@
def _(s):
return s
+__i18n_templates__ = True
+
class ForbiddenPoster(Errors.HoldMessage):
reason = _('Sender is explicitly forbidden')
@@ -84,8 +86,8 @@
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 @@
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 @@
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 @@
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')
Modified: trunk/mailman/Mailman/Handlers/ToDigest.py
===================================================================
--- trunk/mailman/Mailman/Handlers/ToDigest.py 2007-03-21 00:06:04 UTC (rev
8170)
+++ trunk/mailman/Mailman/Handlers/ToDigest.py 2007-03-21 14:11:53 UTC (rev
8171)
@@ -54,6 +54,7 @@
from Mailman.configuration import config
_ = i18n._
+__i18n_templates__ = True
UEMPTYSTRING = u''
EMPTYSTRING = ''
@@ -146,7 +147,7 @@
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 @@
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
Modified: trunk/mailman/Mailman/MailList.py
===================================================================
--- trunk/mailman/Mailman/MailList.py 2007-03-21 00:06:04 UTC (rev 8170)
+++ trunk/mailman/Mailman/MailList.py 2007-03-21 14:11:53 UTC (rev 8171)
@@ -403,8 +403,7 @@
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 = ''
Modified: trunk/mailman/Mailman/i18n.py
===================================================================
--- trunk/mailman/Mailman/i18n.py 2007-03-21 00:06:04 UTC (rev 8170)
+++ trunk/mailman/Mailman/i18n.py 2007-03-21 14:11:53 UTC (rev 8171)
@@ -73,7 +73,7 @@
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 @@
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
Modified: trunk/mailman/Mailman/testing/base.py
===================================================================
--- trunk/mailman/Mailman/testing/base.py 2007-03-21 00:06:04 UTC (rev
8170)
+++ trunk/mailman/Mailman/testing/base.py 2007-03-21 14:11:53 UTC (rev
8171)
@@ -19,7 +19,9 @@
import os
import grp
+import new
import pwd
+import sys
import stat
import shutil
import difflib
@@ -39,6 +41,11 @@
+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 @@
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 @@
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
Modified: trunk/mailman/Mailman/testing/test_handlers.py
===================================================================
--- trunk/mailman/Mailman/testing/test_handlers.py 2007-03-21 00:06:04 UTC
(rev 8170)
+++ trunk/mailman/Mailman/testing/test_handlers.py 2007-03-21 14:11:53 UTC
(rev 8171)
@@ -129,7 +129,7 @@
eq(qdata.get('recips'), ['[EMAIL PROTECTED]'])
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'], '[EMAIL PROTECTED]')
eq(qmsg['from'], '[EMAIL PROTECTED]')
eq(qmsg.get_content_type(), 'text/plain')
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org