[Checkins] SVN: Products.MailHost/trunk/src/Products/MailHost/ PEP8
Hanno Schlichting
hannosch at hannosch.eu
Tue Jul 13 12:26:16 EDT 2010
Log message for revision 114712:
PEP8
Changed:
U Products.MailHost/trunk/src/Products/MailHost/MailHost.py
U Products.MailHost/trunk/src/Products/MailHost/SendMailTag.py
U Products.MailHost/trunk/src/Products/MailHost/__init__.py
U Products.MailHost/trunk/src/Products/MailHost/decorator.py
U Products.MailHost/trunk/src/Products/MailHost/tests/testMailHost.py
-=-
Modified: Products.MailHost/trunk/src/Products/MailHost/MailHost.py
===================================================================
--- Products.MailHost/trunk/src/Products/MailHost/MailHost.py 2010-07-13 16:13:03 UTC (rev 114711)
+++ Products.MailHost/trunk/src/Products/MailHost/MailHost.py 2010-07-13 16:26:15 UTC (rev 114712)
@@ -65,10 +65,13 @@
getaddresses = emailutils.getaddresses
CHARSET_RE = re.compile('charset=[\'"]?([\w-]+)[\'"]?', re.IGNORECASE)
+
class MailHostError(Exception):
pass
manage_addMailHostForm = DTMLFile('dtml/addMailHost_form', globals())
+
+
def manage_addMailHost(self,
id,
title='',
@@ -80,8 +83,8 @@
):
""" Add a MailHost into the system.
"""
- i = MailHost( id, title, smtp_host, smtp_port ) #create new mail host
- self._setObject( id,i ) #register it
+ i = MailHost(id, title, smtp_host, smtp_port)
+ self._setObject(id, i)
if REQUEST is not None:
REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
@@ -106,25 +109,22 @@
force_tls = False
lock = Lock()
- # timeout = 1.0 # unused?
-
manage_options = (
(
- {'icon':'', 'label':'Edit',
- 'action':'manage_main',
- 'help':('MailHost','Mail-Host_Edit.stx')},
+ {'icon': '', 'label': 'Edit',
+ 'action': 'manage_main',
+ 'help': ('MailHost', 'Mail-Host_Edit.stx')},
)
+ RoleManager.manage_options
+ Item.manage_options
)
-
def __init__(self,
id='',
title='',
smtp_host='localhost',
- smtp_port=25,
- force_tls=False,
+ smtp_port=25,
+ force_tls=False,
smtp_uid='',
smtp_pwd='',
smtp_queue=False,
@@ -134,7 +134,7 @@
"""
self.id = id
self.title = title
- self.smtp_host = str( smtp_host )
+ self.smtp_host = str(smtp_host)
self.smtp_port = int(smtp_port)
self.smtp_uid = smtp_uid
self.smtp_pwd = smtp_pwd
@@ -154,10 +154,10 @@
smtp_host,
smtp_port,
smtp_uid='',
- smtp_pwd='',
+ smtp_pwd='',
smtp_queue=False,
smtp_queue_directory='/tmp',
- force_tls=False,
+ force_tls=False,
REQUEST=None,
):
"""Make the changes.
@@ -175,20 +175,17 @@
self.smtp_queue = smtp_queue
self.smtp_queue_directory = smtp_queue_directory
- # restart queue processor thread
+ # restart queue processor thread
if self.smtp_queue:
- self._stopQueueProcessorThread()
- self._startQueueProcessorThread()
+ self._stopQueueProcessorThread()
+ self._startQueueProcessorThread()
else:
- self._stopQueueProcessorThread()
+ self._stopQueueProcessorThread()
if REQUEST is not None:
msg = 'MailHost %s updated' % self.id
- return self.manage_main( self
- , REQUEST
- , manage_tabs_message=msg
- )
+ return self.manage_main(self, REQUEST, manage_tabs_message=msg)
security.declareProtected(use_mailhost_services, 'sendTemplate')
def sendTemplate(trueself,
@@ -258,8 +255,7 @@
port=int(self.smtp_port),
username=self.smtp_uid or None,
password=self.smtp_pwd or None,
- force_tls=self.force_tls
- )
+ force_tls=self.force_tls)
security.declarePrivate('_getThreadKey')
def _getThreadKey(self):
@@ -272,7 +268,7 @@
""" Stop thread for processing the mail queue.
"""
key = self._getThreadKey()
- if queue_threads.has_key(key):
+ if key in queue_threads:
thread = queue_threads[key]
thread.stop()
while thread.isAlive():
@@ -286,12 +282,12 @@
""" Start thread for processing the mail queue.
"""
key = self._getThreadKey()
- if not queue_threads.has_key(key):
+ if key not in queue_threads:
thread = QueueProcessorThread()
thread.setMailer(self._makeMailer())
thread.setQueuePath(self.smtp_queue_directory)
thread.start()
- queue_threads[key] = thread
+ queue_threads[key] = thread
LOG.info('Thread for %s started' % key)
security.declareProtected(view, 'queueLength')
@@ -315,7 +311,8 @@
return th.isAlive()
return False
- security.declareProtected(change_configuration, 'manage_restartQueueThread')
+ security.declareProtected(change_configuration,
+ 'manage_restartQueueThread')
def manage_restartQueueThread(self, action='start', REQUEST=None):
""" Restart the queue processor thread """
@@ -354,6 +351,7 @@
class MailHost(Persistent, MailBase):
"""persistent version"""
+
def uu_encoder(msg):
"""For BBB only, don't send uuencoded emails"""
orig = StringIO(msg.get_payload())
@@ -368,11 +366,12 @@
'7bit': Encoders.encode_7or8bit,
'8bit': Encoders.encode_7or8bit,
'x-uuencode': uu_encoder,
- 'uuencode': uu_encoder,
+ 'uuencode': uu_encoder,
'x-uue': uu_encoder,
'uue': uu_encoder,
}
+
def _encode(body, encode=None):
"""Manually sets an encoding and encodes the message if not
already encoded."""
@@ -384,15 +383,16 @@
# already encoded correctly, may have been automated
return body
if mo['Content-Transfer-Encoding'] not in ['7bit', None]:
- raise MailHostError, 'Message already encoded'
+ raise MailHostError('Message already encoded')
if encode in ENCODERS:
ENCODERS[encode](mo)
if not mo['Content-Transfer-Encoding']:
- mo['Content-Transfer-Encoding'] = encode
+ mo['Content-Transfer-Encoding'] = encode
if not mo['Mime-Version']:
- mo['Mime-Version'] = '1.0'
+ mo['Mime-Version'] = '1.0'
return mo.as_string()
+
def _mungeHeaders(messageText, mto=None, mfrom=None, subject=None,
charset=None, msg_type=None):
"""Sets missing message headers, and deletes Bcc.
@@ -426,8 +426,8 @@
# encoding for the charset
mo.set_charset(charset)
elif charset_match and not charset:
- # If a charset parameter was provided use it for header encoding below,
- # Otherwise, try to use the charset provided in the message.
+ # If a charset parameter was provided use it for header encoding
+ # below, otherwise, try to use the charset provided in the message.
charset = charset_match.groups()[0]
else:
# Do basically the same for each payload as for the complete
@@ -458,7 +458,7 @@
if mto:
if isinstance(mto, basestring):
- mto = [formataddr(addr) for addr in getaddresses((mto,))]
+ mto = [formataddr(addr) for addr in getaddresses((mto, ))]
if not mo.get('To'):
mo['To'] = ', '.join(str(_encode_address_string(e, charset))
for e in mto)
@@ -468,9 +468,9 @@
for header in ('To', 'Cc', 'Bcc'):
v = ','.join(mo.get_all(header) or [])
if v:
- mto += [formataddr(addr) for addr in getaddresses((v,))]
+ mto += [formataddr(addr) for addr in getaddresses((v, ))]
if not mto:
- raise MailHostError, "No message recipients designated"
+ raise MailHostError("No message recipients designated")
if mfrom:
# XXX: do we really want to override an explicitly set From
@@ -479,7 +479,7 @@
mo['From'] = _encode_address_string(mfrom, charset)
else:
if mo.get('From') is None:
- raise MailHostError,"Message missing SMTP Header 'From'"
+ raise MailHostError("Message missing SMTP Header 'From'")
mfrom = mo['From']
if mo.get('Bcc'):
@@ -490,6 +490,7 @@
return mo.as_string(), mto, mfrom
+
def _try_encode(text, charset):
"""Attempt to encode using the default charset if none is
provided. Should we permit encoding errors?"""
@@ -498,6 +499,7 @@
else:
return text.encode()
+
def _encode_address_string(text, charset):
"""Split the email into parts and use header encoding on the name
part if needed. We do this because the actual addresses need to be
Modified: Products.MailHost/trunk/src/Products/MailHost/SendMailTag.py
===================================================================
--- Products.MailHost/trunk/src/Products/MailHost/SendMailTag.py 2010-07-13 16:13:03 UTC (rev 114711)
+++ Products.MailHost/trunk/src/Products/MailHost/SendMailTag.py 2010-07-13 16:26:15 UTC (rev 114712)
@@ -11,11 +11,13 @@
#
##############################################################################
-from MailHost import MailBase, MailHostError
-from DocumentTemplate.DT_Util import parse_params,render_blocks
+from DocumentTemplate.DT_Util import parse_params
+from DocumentTemplate.DT_Util import render_blocks
from DocumentTemplate.DT_String import String
+from Products.MailHost.MailHost import MailBase, MailHostError
+
class SendMailTag:
'''the send mail tag, used like thus:
@@ -63,20 +65,25 @@
encode=None)
smtphost=None
-
+
has_key=args.has_key
- if has_key('mailhost'): mailhost=args['mailhost']
- elif has_key('smtphost'): mailhost=smtphost=args['smtphost']
- elif has_key(''): mailhost=args['mailhost']=args['']
- else: raise MailHostError, 'No mailhost was specified in tag'
+ if has_key('mailhost'):
+ mailhost = args['mailhost']
+ elif has_key('smtphost'):
+ mailhost = smtphost = args['smtphost']
+ elif has_key(''):
+ mailhost = args['mailhost'] = args['']
+ else:
+ raise MailHostError('No mailhost was specified in tag')
for key in ('mailto', 'mailfrom', 'subject', 'port'):
- if not args.has_key(key):args[key]=''
+ if not key in args:
+ args[key] = ''
if has_key('encode') and args['encode'] not in \
('base64', 'quoted-printable', 'uuencode', 'x-uuencode',
'uue', 'x-uue'):
- raise MailHostError, (
+ raise MailHostError(
'An unsupported encoding was specified in tag')
if not smtphost:
@@ -98,7 +105,8 @@
self.port=args['port']
if has_key('encode'):
self.encode=args['encode']
- else: self.encode=None
+ else:
+ self.encode=None
def render(self, md):
if self.mailhost:
Modified: Products.MailHost/trunk/src/Products/MailHost/__init__.py
===================================================================
--- Products.MailHost/trunk/src/Products/MailHost/__init__.py 2010-07-13 16:13:03 UTC (rev 114711)
+++ Products.MailHost/trunk/src/Products/MailHost/__init__.py 2010-07-13 16:26:15 UTC (rev 114712)
@@ -14,6 +14,7 @@
import MailHost
import SendMailTag
+
def initialize(context):
context.registerClass(
MailHost.MailHost,
Modified: Products.MailHost/trunk/src/Products/MailHost/decorator.py
===================================================================
--- Products.MailHost/trunk/src/Products/MailHost/decorator.py 2010-07-13 16:13:03 UTC (rev 114711)
+++ Products.MailHost/trunk/src/Products/MailHost/decorator.py 2010-07-13 16:26:15 UTC (rev 114712)
@@ -14,6 +14,7 @@
Decorator(s)
"""
+
def synchronized(lock):
""" Decorator for method synchronization. """
Modified: Products.MailHost/trunk/src/Products/MailHost/tests/testMailHost.py
===================================================================
--- Products.MailHost/trunk/src/Products/MailHost/tests/testMailHost.py 2010-07-13 16:13:03 UTC (rev 114711)
+++ Products.MailHost/trunk/src/Products/MailHost/tests/testMailHost.py 2010-07-13 16:26:15 UTC (rev 114712)
@@ -29,6 +29,7 @@
self.sent = messageText
self.immediate = immediate
+
class FakeContent(object):
def __init__(self, template_name, message):
def template(self, context, REQUEST=None):
@@ -39,6 +40,7 @@
def check_status(context, REQUEST=None):
return 'Message Sent'
+
class TestMailHost(unittest.TestCase):
def _getTargetClass(self):
@@ -53,30 +55,30 @@
verifyClass(IMailHost, self._getTargetClass())
- def testAllHeaders( self ):
+ def testAllHeaders(self):
msg = """To: recipient at domain.com
From: sender at domain.com
Subject: This is the subject
This is the message body."""
# No additional info
- resmsg, resto, resfrom = _mungeHeaders( msg )
+ resmsg, resto, resfrom = _mungeHeaders(msg)
self.failUnless(resto == ['recipient at domain.com'])
- self.failUnless(resfrom == 'sender at domain.com' )
+ self.failUnless(resfrom == 'sender at domain.com')
# Add duplicated info
resmsg, resto, resfrom = _mungeHeaders(msg, 'recipient at domain.com',
- 'sender at domain.com', 'This is the subject' )
+ 'sender at domain.com', 'This is the subject')
self.failUnlessEqual(resto, ['recipient at domain.com'])
- self.failUnlessEqual(resfrom, 'sender at domain.com' )
+ self.failUnlessEqual(resfrom, 'sender at domain.com')
# Add extra info
resmsg, resto, resfrom = _mungeHeaders(msg, 'recipient2 at domain.com',
- 'sender2 at domain.com', 'This is the real subject' )
+ 'sender2 at domain.com', 'This is the real subject')
self.failUnlessEqual(resto, ['recipient2 at domain.com'])
- self.failUnlessEqual(resfrom, 'sender2 at domain.com' )
+ self.failUnlessEqual(resfrom, 'sender2 at domain.com')
- def testMissingHeaders( self ):
+ def testMissingHeaders(self):
msg = """X-Header: Dummy header
This is the message body."""
@@ -87,7 +89,7 @@
self.failUnlessRaises(MailHostError, _mungeHeaders, msg,
mto='recipient at domain.com')
- def testNoHeaders( self ):
+ def testNoHeaders(self):
msg = """This is the message body."""
# Doesn't specify to
self.failUnlessRaises(MailHostError, _mungeHeaders, msg,
@@ -99,14 +101,14 @@
resmsg, resto, resfrom = _mungeHeaders(msg, 'recipient2 at domain.com',
'sender2 at domain.com', 'This is the real subject')
self.failUnlessEqual(resto, ['recipient2 at domain.com'])
- self.failUnlessEqual(resfrom,'sender2 at domain.com' )
+ self.failUnlessEqual(resfrom, 'sender2 at domain.com')
- def testBCCHeader( self ):
+ def testBCCHeader(self):
msg = "From: me at example.com\nBcc: many at example.com\n\nMessage text"
# Specify only the "Bcc" header. Useful for bulk emails.
resmsg, resto, resfrom = _mungeHeaders(msg)
self.failUnlessEqual(resto, ['many at example.com'])
- self.failUnlessEqual(resfrom, 'me at example.com' )
+ self.failUnlessEqual(resfrom, 'me at example.com')
def test__getThreadKey_uses_fspath(self):
mh1 = self._makeOne('mh1')
@@ -117,26 +119,28 @@
mh2.absolute_url = lambda self: 'http://example.com/mh2'
self.assertEqual(mh1._getThreadKey(), mh2._getThreadKey())
- def testAddressParser( self ):
- msg = """To: "Name, Nick" <recipient at domain.com>, "Foo Bar" <foo at domain.com>
+ def testAddressParser(self):
+ msg = """\
+To: "Name, Nick" <recipient at domain.com>, "Foo Bar" <foo at domain.com>
CC: "Web, Jack" <jack at web.com>
From: sender at domain.com
Subject: This is the subject
This is the message body."""
-
+
# Test Address-Parser for To & CC given in messageText
-
- resmsg, resto, resfrom = _mungeHeaders( msg )
+
+ resmsg, resto, resfrom = _mungeHeaders(msg)
self.failUnlessEqual(resto, ['"Name, Nick" <recipient at domain.com>',
'Foo Bar <foo at domain.com>',
'"Web, Jack" <jack at web.com>'])
self.failUnlessEqual(resfrom, 'sender at domain.com')
# Test Address-Parser for a given mto-string
-
- resmsg, resto, resfrom = _mungeHeaders(msg, mto= '"Public, Joe" <pjoe at domain.com>, Foo Bar <foo at domain.com>')
+ resmsg, resto, resfrom = _mungeHeaders(msg,
+ mto='"Public, Joe" <pjoe at domain.com>, Foo Bar <foo at domain.com>')
+
self.failUnlessEqual(resto, ['"Public, Joe" <pjoe at domain.com>',
'Foo Bar <foo at domain.com>'])
self.failUnlessEqual(resfrom, 'sender at domain.com')
@@ -170,7 +174,8 @@
mailhost = self._makeOne('MailHost')
mailhost.send(messageText=inmsg,
- mto='"Name, Nick" <recipient at domain.com>, "Foo Bar" <foo at domain.com>',
+ mto='"Name, Nick" <recipient at domain.com>, '
+ '"Foo Bar" <foo at domain.com>',
mfrom='sender at domain.com', subject='This is the subject')
self.assertEqual(mailhost.sent, outmsg)
@@ -190,7 +195,8 @@
mailhost = self._makeOne('MailHost')
mailhost.send(messageText=inmsg,
- mto=['"Name, Nick" <recipient at domain.com>', '"Foo Bar" <foo at domain.com>'],
+ mto=['"Name, Nick" <recipient at domain.com>',
+ '"Foo Bar" <foo at domain.com>'],
mfrom='sender at domain.com', subject='This is the subject')
self.assertEqual(mailhost.sent, outmsg)
@@ -203,8 +209,10 @@
This is the message body."""
mailhost = self._makeOne('MailHost')
- mailhost.simple_send(mto='"Name, Nick" <recipient at domain.com>, "Foo Bar" <foo at domain.com>',
- mfrom='sender at domain.com', subject='This is the subject',
+ mailhost.simple_send(mto='"Name, Nick" <recipient at domain.com>, '
+ '"Foo Bar" <foo at domain.com>',
+ mfrom='sender at domain.com',
+ subject='This is the subject',
body='This is the message body.')
self.assertEqual(mailhost.sent, outmsg)
self.assertEqual(mailhost.immediate, False)
@@ -218,9 +226,12 @@
This is the message body."""
mailhost = self._makeOne('MailHost')
- mailhost.simple_send(mto='"Name, Nick" <recipient at domain.com>, "Foo Bar" <foo at domain.com>',
- mfrom='sender at domain.com', subject='This is the subject',
- body='This is the message body.', immediate=True)
+ mailhost.simple_send(mto='"Name, Nick" <recipient at domain.com>, '
+ '"Foo Bar" <foo at domain.com>',
+ mfrom='sender at domain.com',
+ subject='This is the subject',
+ body='This is the message body.',
+ immediate=True)
self.assertEqual(mailhost.sent, outmsg)
self.assertEqual(mailhost.immediate, True)
@@ -231,12 +242,14 @@
mailhost = self._makeOne('MailHost')
mailhost.send(messageText=msg,
- mto='"Name, Nick" <recipient at domain.com>, "Foo Bar" <foo at domain.com>',
- mfrom='sender at domain.com', subject='This is the subject')
+ mto='"Name, Nick" <recipient at domain.com>, '
+ '"Foo Bar" <foo at domain.com>',
+ mfrom='sender at domain.com',
+ subject='This is the subject')
out = message_from_string(mailhost.sent)
self.failUnlessEqual(out.get_payload(), msg)
self.failUnlessEqual(out['To'],
- '"Name, Nick" <recipient at domain.com>, Foo Bar <foo at domain.com>')
+ '"Name, Nick" <recipient at domain.com>, Foo Bar <foo at domain.com>')
self.failUnlessEqual(out['From'], 'sender at domain.com')
def testSendEncodedBody(self):
@@ -248,16 +261,20 @@
msg = "Here's some encoded t\xc3\xa9xt."
mailhost = self._makeOne('MailHost')
mailhost.send(messageText=msg,
- mto='"Name, Nick" <recipient at domain.com>, "Foo Bar" <foo at domain.com>',
- mfrom='sender at domain.com', subject='This is the subject', charset='utf-8')
+ mto='"Name, Nick" <recipient at domain.com>, '
+ '"Foo Bar" <foo at domain.com>',
+ mfrom='sender at domain.com',
+ subject='This is the subject',
+ charset='utf-8')
out = message_from_string(mailhost.sent)
self.failUnlessEqual(out['To'],
- '"Name, Nick" <recipient at domain.com>, Foo Bar <foo at domain.com>')
+ '"Name, Nick" <recipient at domain.com>, Foo Bar <foo at domain.com>')
self.failUnlessEqual(out['From'], 'sender at domain.com')
# utf-8 will default to Quoted Printable encoding
self.failUnlessEqual(out['Content-Transfer-Encoding'],
'quoted-printable')
- self.failUnlessEqual(out['Content-Type'], 'text/plain; charset="utf-8"')
+ self.failUnlessEqual(out['Content-Type'],
+ 'text/plain; charset="utf-8"')
self.failUnlessEqual(out.get_payload(),
"Here's some encoded t=C3=A9xt.")
@@ -274,13 +291,14 @@
self.failUnlessEqual(out['To'],
'=?utf-8?q?Ferran_Adri=C3=A0?= <ferran at example.com>')
self.failUnlessEqual(out['From'],
- '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= <jose at example.com>')
+ '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= <jose at example.com>')
self.failUnlessEqual(out['Subject'],
- '=?utf-8?q?=C2=BFEsferificaci=C3=B3n=3F?=')
+ '=?utf-8?q?=C2=BFEsferificaci=C3=B3n=3F?=')
# utf-8 will default to Quoted Printable encoding
self.failUnlessEqual(out['Content-Transfer-Encoding'],
'quoted-printable')
- self.failUnlessEqual(out['Content-Type'], 'text/plain; charset="utf-8"')
+ self.failUnlessEqual(out['Content-Type'],
+ 'text/plain; charset="utf-8"')
self.failUnlessEqual(out.get_payload(), "A message.")
def testAlreadyEncodedMessage(self):
@@ -338,7 +356,7 @@
'=?iso-8859-1?q?=BFEsferificaci=F3n=3F?=')
# original headers will be unaltered
self.failUnlessEqual(out['From'],
- '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= <jose at example.com>')
+ '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= <jose at example.com>')
def testUnicodeMessage(self):
# unicode messages and headers are decoded using the given charset
@@ -355,12 +373,13 @@
self.failUnlessEqual(out['To'],
'"Name, Nick" <recipient at domain.com>')
self.failUnlessEqual(out['From'],
- '=?utf-8?q?Ferran_Adri=C3=A0?= <ferran at example.com>')
+ '=?utf-8?q?Ferran_Adri=C3=A0?= <ferran at example.com>')
self.failUnlessEqual(out['Subject'], '=?utf-8?q?=C2=A1Andr=C3=A9s!?=')
- self.failUnlessEqual(out['Content-Transfer-Encoding'], 'quoted-printable')
+ self.failUnlessEqual(out['Content-Transfer-Encoding'],
+ 'quoted-printable')
self.failUnlessEqual(out['Content-Type'], 'text/html; charset="utf-8"')
self.failUnlessEqual(out.get_payload(),
- "Here's some unencoded <strong>t=C3=A9xt</strong>.")
+ "Here's some unencoded <strong>t=C3=A9xt</strong>.")
def testUnicodeNoEncodingErrors(self):
# Unicode messages and headers raise errors if no charset is passed to
@@ -390,7 +409,7 @@
mfrom=u'Foo Bar <foo at domain.com>', subject=subject)
out = mailhost.sent
# Ensure the results are not unicode
- self.failUnlessEqual(out,"""\
+ self.failUnlessEqual(out, """\
Date: Sun, 27 Aug 2006 17:00:00 +0200
Subject: Andres!
To: "Name, Nick" <recipient at domain.com>
@@ -419,14 +438,15 @@
# we can even alter a from and subject headers without affecting the
# original object
- mailhost.send(msg, mfrom='Foo Bar <foo at domain.com>', subject='Changed!')
+ mailhost.send(msg,
+ mfrom='Foo Bar <foo at domain.com>', subject='Changed!')
out = message_from_string(mailhost.sent)
# We need to make sure we didn't mutate the message we were passed
self.failIfEqual(out.as_string(), msg.as_string())
self.failUnlessEqual(out['From'], 'Foo Bar <foo at domain.com>')
self.failUnlessEqual(msg['From'],
- '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= <jose at example.com>')
+ '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= <jose at example.com>')
# The subject is encoded with the body encoding since no
# explicit encoding was specified
self.failUnlessEqual(out['Subject'], '=?utf-8?q?Changed!?=')
@@ -492,7 +512,8 @@
mailhost = self._makeOne('MailHost')
# We pass an encoded string with unspecified charset, it should be
# encoded 8bit
- mailhost.send('Date: Sun, 27 Aug 2006 17:00:00 +0200\n\nA M\xc3\xa9ssage',
+ mailhost.send('Date: Sun, 27 Aug 2006 17:00:00 +0200\n\n'
+ 'A M\xc3\xa9ssage',
mfrom='sender at domain.com',
mto='Foo Bar <foo at domain.com>', encode='8bit')
out = message_from_string(mailhost.sent)
@@ -613,8 +634,5 @@
def test_suite():
suite = unittest.TestSuite()
- suite.addTest( unittest.makeSuite( TestMailHost ) )
+ suite.addTest(unittest.makeSuite(TestMailHost))
return suite
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
More information about the checkins
mailing list