Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

Location:
python/vendor/current/Lib/email
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Lib/email/__init__.py

    r2 r388  
    55"""A package for parsing, handling, and generating email messages."""
    66
    7 __version__ = '4.0.1'
     7__version__ = '4.0.3'
    88
    99__all__ = [
  • python/vendor/current/Lib/email/_parseaddr.py

    r2 r388  
    1414    ]
    1515
    16 import time
     16import time, calendar
    1717
    1818SPACE = ' '
     
    108108    except ValueError:
    109109        return None
     110    # Check for a yy specified in two-digit format, then convert it to the
     111    # appropriate four-digit format, according to the POSIX standard. RFC 822
     112    # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822)
     113    # mandates a 4-digit yy. For more information, see the documentation for
     114    # the time module.
     115    if yy < 100:
     116        # The year is between 1969 and 1999 (inclusive).
     117        if yy > 68:
     118            yy += 1900
     119        # The year is between 2000 and 2068 (inclusive).
     120        else:
     121            yy += 2000
    110122    tzoffset = None
    111123    tz = tz.upper()
     
    139151
    140152def mktime_tz(data):
    141     """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp."""
     153    """Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp."""
    142154    if data[9] is None:
    143155        # No zone info, so localtime is better assumption than GMT
    144156        return time.mktime(data[:8] + (-1,))
    145157    else:
    146         t = time.mktime(data[:8] + (0,))
    147         return t - data[9] - time.timezone
     158        t = calendar.timegm(data)
     159        return t - data[9]
    148160
    149161
    150162def quote(str):
    151     """Add quotes around a string."""
     163    """Prepare string to be used in a quoted string.
     164
     165    Turns backslash and double quote characters into quoted pairs.  These
     166    are the only characters that need to be quoted inside a quoted string.
     167    Does not add the surrounding double quotes.
     168    """
    152169    return str.replace('\\', '\\\\').replace('"', '\\"')
    153170
     
    307324                self.pos += 1
    308325            elif self.field[self.pos] == '"':
    309                 aslist.append('"%s"' % self.getquote())
     326                aslist.append('"%s"' % quote(self.getquote()))
    310327            elif self.field[self.pos] in self.atomends:
    311328                break
  • python/vendor/current/Lib/email/base64mime.py

    r2 r388  
    134134
    135135    Each line of encoded text will end with eol, which defaults to "\\n".  Set
    136     this to "\r\n" if you will be using the result of this function directly
     136    this to "\\r\\n" if you will be using the result of this function directly
    137137    in an email.
    138138    """
  • python/vendor/current/Lib/email/charset.py

    r2 r388  
    1010    ]
    1111
     12import codecs
    1213import email.base64mime
    1314import email.quoprimime
     
    187188                   body_encoding.
    188189
    189     output_charset: Some character sets must be converted before the can be
     190    output_charset: Some character sets must be converted before they can be
    190191                    used in email headers or bodies.  If the input_charset is
    191192                    one of them, this attribute will contain the name of the
     
    213214        except UnicodeError:
    214215            raise errors.CharsetError(input_charset)
    215         input_charset = input_charset.lower()
    216         # Set the input charset after filtering through the aliases
     216        input_charset = input_charset.lower().encode('ascii')
     217        # Set the input charset after filtering through the aliases and/or codecs
     218        if not (input_charset in ALIASES or input_charset in CHARSETS):
     219            try:
     220                input_charset = codecs.lookup(input_charset).name
     221            except LookupError:
     222                pass
    217223        self.input_charset = ALIASES.get(input_charset, input_charset)
    218224        # We can try to guess which encoding and conversion to use by the
  • python/vendor/current/Lib/email/encoders.py

    r2 r388  
    7777        orig.encode('ascii')
    7878    except UnicodeError:
    79         # iso-2022-* is non-ASCII but still 7-bit
    80         charset = msg.get_charset()
    81         output_cset = charset and charset.output_charset
    82         if output_cset and output_cset.lower().startswith('iso-2202-'):
    83             msg['Content-Transfer-Encoding'] = '7bit'
    84         else:
    85             msg['Content-Transfer-Encoding'] = '8bit'
     79        msg['Content-Transfer-Encoding'] = '8bit'
    8680    else:
    8781        msg['Content-Transfer-Encoding'] = '7bit'
  • python/vendor/current/Lib/email/feedparser.py

    r2 r388  
    1414This completes the parsing and returns the root message object.
    1515
    16 The other advantage of this parser is that it will never throw a parsing
     16The other advantage of this parser is that it will never raise a parsing
    1717exception.  Instead, when it finds something unexpected, it adds a 'defect' to
    1818the current message.  Defects are just instances that live on the message
     
    2929NLCRE = re.compile('\r\n|\r|\n')
    3030NLCRE_bol = re.compile('(\r\n|\r|\n)')
    31 NLCRE_eol = re.compile('(\r\n|\r|\n)$')
     31NLCRE_eol = re.compile('(\r\n|\r|\n)\Z')
    3232NLCRE_crack = re.compile('(\r\n|\r|\n)')
    3333# RFC 2822 $3.6.8 Optional fields.  ftext is %d33-57 / %d59-126, Any character
     
    106106        # this is the empty string.
    107107        self._partial = parts.pop()
     108        #GAN 29Mar09  bugs 1555570, 1721862  Confusion at 8K boundary ending with \r:
     109        # is there a \n to follow later?
     110        if not self._partial and parts and parts[-1].endswith('\r'):
     111            self._partial = parts.pop(-2)+parts.pop()
    108112        # parts is a list of strings, alternating between the line contents
    109113        # and the eol character(s).  Gather up a list of lines after
     
    213217        self._parse_headers(headers)
    214218        # Headers-only parsing is a backwards compatibility hack, which was
    215         # necessary in the older parser, which could throw errors.  All
     219        # necessary in the older parser, which could raise errors.  All
    216220        # remaining lines in the input are thrown into the message body.
    217221        if self._headersonly:
  • python/vendor/current/Lib/email/generator.py

    r2 r388  
    1 # Copyright (C) 2001-2006 Python Software Foundation
    2 # Author: Barry Warsaw
     1# Copyright (C) 2001-2010 Python Software Foundation
    32# Contact: email-sig@python.org
    43
     
    158157                print >> self._fp, v
    159158            else:
    160                 # Header's got lots of smarts, so use it.
     159                # Header's got lots of smarts, so use it.  Note that this is
     160                # fundamentally broken though because we lose idempotency when
     161                # the header string is continued with tabs.  It will now be
     162                # continued with spaces.  This was reversedly broken before we
     163                # fixed bug 1974.  Either way, we lose.
    161164                print >> self._fp, Header(
    162                     v, maxlinelen=self._maxheaderlen,
    163                     header_name=h, continuation_ws='\t').encode()
     165                    v, maxlinelen=self._maxheaderlen, header_name=h).encode()
    164166        # A blank line always separates headers from body
    165167        print >> self._fp
     
    202204            g.flatten(part, unixfrom=False)
    203205            msgtexts.append(s.getvalue())
    204         # Now make sure the boundary we've selected doesn't appear in any of
    205         # the message texts.
    206         alltext = NL.join(msgtexts)
    207206        # BAW: What about boundaries that are wrapped in double-quotes?
    208         boundary = msg.get_boundary(failobj=_make_boundary(alltext))
    209         # If we had to calculate a new boundary because the body text
    210         # contained that string, set the new boundary.  We don't do it
    211         # unconditionally because, while set_boundary() preserves order, it
    212         # doesn't preserve newlines/continuations in headers.  This is no big
    213         # deal in practice, but turns out to be inconvenient for the unittest
    214         # suite.
    215         if msg.get_boundary() != boundary:
     207        boundary = msg.get_boundary()
     208        if not boundary:
     209            # Create a boundary that doesn't appear in any of the
     210            # message texts.
     211            alltext = NL.join(msgtexts)
     212            boundary = _make_boundary(alltext)
    216213            msg.set_boundary(boundary)
    217214        # If there's a preamble, write it out, with a trailing CRLF
    218215        if msg.preamble is not None:
    219             print >> self._fp, msg.preamble
     216            if self._mangle_from_:
     217                preamble = fcre.sub('>From ', msg.preamble)
     218            else:
     219                preamble = msg.preamble
     220            print >> self._fp, preamble
    220221        # dash-boundary transport-padding CRLF
    221222        print >> self._fp, '--' + boundary
     
    235236        if msg.epilogue is not None:
    236237            print >> self._fp
    237             self._fp.write(msg.epilogue)
     238            if self._mangle_from_:
     239                epilogue = fcre.sub('>From ', msg.epilogue)
     240            else:
     241                epilogue = msg.epilogue
     242            self._fp.write(epilogue)
    238243
    239244    def _handle_multipart_signed(self, msg):
     
    293298
    294299class DecodedGenerator(Generator):
    295     """Generator a text representation of a message.
     300    """Generates a text representation of a message.
    296301
    297302    Like the Generator base class, except that non-text parts are substituted
  • python/vendor/current/Lib/email/header.py

    r2 r388  
    4747# For use with .match()
    4848fcre = re.compile(r'[\041-\176]+:$')
     49
     50# Find a header embedded in a putative header value.  Used to check for
     51# header injection attack.
     52_embeded_header = re.compile(r'\n[^ \t]+:')
    4953
    5054
     
    9599                    dec = email.quoprimime.header_decode(encoded)
    96100                elif encoding == 'b':
     101                    paderr = len(encoded) % 4   # Postel's law: add missing padding
     102                    if paderr:
     103                        encoded += '==='[:4 - paderr]
    97104                    try:
    98105                        dec = email.base64mime.decode(encoded)
     
    405412            lastchunk, lastcharset = newchunks[-1]
    406413            lastlen = lastcharset.encoded_header_len(lastchunk)
    407         return self._encode_chunks(newchunks, maxlinelen)
     414        value = self._encode_chunks(newchunks, maxlinelen)
     415        if _embeded_header.search(value):
     416            raise HeaderParseError("header value appears to contain "
     417                "an embedded header: {!r}".format(value))
     418        return value
    408419
    409420
  • python/vendor/current/Lib/email/message.py

    r2 r388  
    4040    """Convenience function to format and return a key=value pair.
    4141
    42     This will quote the value if needed or if quote is true.
     42    This will quote the value if needed or if quote is true.  If value is a
     43    three tuple (charset, language, value), it will be encoded according
     44    to RFC2231 rules.
    4345    """
    4446    if value is not None and len(value) > 0:
     
    6466        s = s[1:]
    6567        end = s.find(';')
    66         while end > 0 and s.count('"', 0, end) % 2:
     68        while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
    6769            end = s.find(';', end + 1)
    6870        if end < 0:
     
    100102
    101103    Message objects implement part of the `mapping' interface, which assumes
    102     there is exactly one occurrance of the header per message.  Some headers
     104    there is exactly one occurrence of the header per message.  Some headers
    103105    do in fact appear multiple times (e.g. Received) and for those headers,
    104106    you must use the explicit API to set or get all the headers.  Not all of
     
    252254        # Charset constructor?
    253255        self._charset = charset
    254         if not self.has_key('MIME-Version'):
     256        if 'MIME-Version' not in self:
    255257            self.add_header('MIME-Version', '1.0')
    256         if not self.has_key('Content-Type'):
     258        if 'Content-Type' not in self:
    257259            self.add_header('Content-Type', 'text/plain',
    258260                            charset=charset.get_output_charset())
    259261        else:
    260262            self.set_param('charset', charset.get_output_charset())
     263        if isinstance(self._payload, unicode):
     264            self._payload = self._payload.encode(charset.output_charset)
    261265        if str(charset) != charset.get_output_charset():
    262266            self._payload = charset.body_encode(self._payload)
    263         if not self.has_key('Content-Transfer-Encoding'):
     267        if 'Content-Transfer-Encoding' not in self:
    264268            cte = charset.get_body_encoding()
    265269            try:
     
    287291
    288292        Note that if the header appeared multiple times, exactly which
    289         occurrance gets returned is undefined.  Use get_all() to get all
     293        occurrence gets returned is undefined.  Use get_all() to get all
    290294        the values matching a header field name.
    291295        """
     
    390394        additional parameters for the header field, with underscores converted
    391395        to dashes.  Normally the parameter will be added as key="value" unless
    392         value is None, in which case only the key will be added.
     396        value is None, in which case only the key will be added.  If a
     397        parameter value contains non-ASCII characters it must be specified as a
     398        three-tuple of (charset, language, value), in which case it will be
     399        encoded according to RFC2231 rules.
    393400
    394401        Example:
     
    554561        to False.
    555562        """
    556         if not self.has_key(header):
     563        if header not in self:
    557564            return failobj
    558565        for k, v in self._get_params_preserve(failobj, header):
     
    585592            value = (charset, language, value)
    586593
    587         if not self.has_key(header) and header.lower() == 'content-type':
     594        if header not in self and header.lower() == 'content-type':
    588595            ctype = 'text/plain'
    589596        else:
     
    620627        header.
    621628        """
    622         if not self.has_key(header):
     629        if header not in self:
    623630            return
    624631        new_ctype = ''
     
    656663            del self['mime-version']
    657664            self['MIME-Version'] = '1.0'
    658         if not self.has_key(header):
     665        if header not in self:
    659666            self[header] = type
    660667            return
  • python/vendor/current/Lib/email/mime/application.py

    r2 r388  
    1818        """Create an application/* type MIME document.
    1919
    20         _data is a string containing the raw applicatoin data.
     20        _data is a string containing the raw application data.
    2121
    2222        _subtype is the MIME content type subtype, defaulting to
  • python/vendor/current/Lib/email/mime/nonmultipart.py

    r2 r388  
    1616    """Base class for MIME multipart/* type messages."""
    1717
    18     __pychecker__ = 'unusednames=payload'
    19 
    2018    def attach(self, payload):
    2119        # The public API prohibits attaching multiple subparts to MIMEBase
     
    2422        raise errors.MultipartConversionError(
    2523            'Cannot attach additional subparts to non-multipart/*')
    26 
    27     del __pychecker__
  • python/vendor/current/Lib/email/quoprimime.py

    r2 r388  
    339339    """
    340340    s = s.replace('_', ' ')
    341     return re.sub(r'=\w{2}', _unquote_match, s)
     341    return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s)
  • python/vendor/current/Lib/email/test/data/msg_10.txt

    r2 r388  
    2727--BOUNDARY
    2828Content-Type: text/plain; charset="iso-8859-1"
     29Content-Transfer-Encoding: Base64
     30
     31VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UuCg==
     32
     33
     34--BOUNDARY
     35Content-Type: text/plain; charset="iso-8859-1"
    2936
    3037This has no Content-Transfer-Encoding: header.
  • python/vendor/current/Lib/email/test/test_email.py

    r2 r388  
    1 # Copyright (C) 2001-2007 Python Software Foundation
     1# Copyright (C) 2001-2010 Python Software Foundation
    22# Contact: email-sig@python.org
    33# email package unit tests
     
    1010import unittest
    1111import warnings
     12import textwrap
    1213from cStringIO import StringIO
    1314
     
    4243
    4344
    44 
    4545def openfile(filename, mode='r'):
    4646    path = os.path.join(os.path.dirname(landmark), 'data', filename)
     
    4949
    5050
    51 
    5251# Base test class
    5352class TestEmailBase(unittest.TestCase):
    5453    def ndiffAssertEqual(self, first, second):
    55         """Like failUnlessEqual except use ndiff for readable output."""
    56         if first <> second:
     54        """Like assertEqual except use ndiff for readable output."""
     55        if first != second:
    5756            sfirst = str(first)
    5857            ssecond = str(second)
     
    6968            fp.close()
    7069        return msg
    71 
    7270
    7371
     
    183181                          msg.set_boundary, 'BOUNDARY')
    184182
     183    def test_make_boundary(self):
     184        msg = MIMEMultipart('form-data')
     185        # Note that when the boundary gets created is an implementation
     186        # detail and might change.
     187        self.assertEqual(msg.items()[0][1], 'multipart/form-data')
     188        # Trigger creation of boundary
     189        msg.as_string()
     190        self.assertEqual(msg.items()[0][1][:33],
     191                        'multipart/form-data; boundary="==')
     192        # XXX: there ought to be tests of the uniqueness of the boundary, too.
     193
    185194    def test_message_rfc822_only(self):
    186195        # Issue 7970: message/rfc822 not in multipart parsed by
     
    209218        eq(msg.get_payload(2).get_payload(decode=True),
    210219           'This is a Base64 encoded message.')
    211         # Subpart 4 has no Content-Transfer-Encoding: header.
     220        # Subpart 4 is base64 with a trailing newline, which
     221        # used to be stripped (issue 7143).
    212222        eq(msg.get_payload(3).get_payload(decode=True),
     223           'This is a Base64 encoded message.\n')
     224        # Subpart 5 has no Content-Transfer-Encoding: header.
     225        eq(msg.get_payload(4).get_payload(decode=True),
    213226           'This has no Content-Transfer-Encoding: header.\n')
    214227
     
    255268        msg['to'] = 'You'
    256269        # Check for case insensitivity
    257         self.failUnless('from' in msg)
    258         self.failUnless('From' in msg)
    259         self.failUnless('FROM' in msg)
    260         self.failUnless('to' in msg)
    261         self.failUnless('To' in msg)
    262         self.failUnless('TO' in msg)
     270        self.assertTrue('from' in msg)
     271        self.assertTrue('From' in msg)
     272        self.assertTrue('FROM' in msg)
     273        self.assertTrue('to' in msg)
     274        self.assertTrue('To' in msg)
     275        self.assertTrue('TO' in msg)
    263276
    264277    def test_as_string(self):
     
    267280        fp = openfile('msg_01.txt')
    268281        try:
    269             text = fp.read()
     282            # BAW 30-Mar-2009 Evil be here.  So, the generator is broken with
     283            # respect to long line breaking.  It's also not idempotent when a
     284            # header from a parsed message is continued with tabs rather than
     285            # spaces.  Before we fixed bug 1974 it was reversedly broken,
     286            # i.e. headers that were continued with spaces got continued with
     287            # tabs.  For Python 2.x there's really no good fix and in Python
     288            # 3.x all this stuff is re-written to be right(er).  Chris Withers
     289            # convinced me that using space as the default continuation
     290            # character is less bad for more applications.
     291            text = fp.read().replace('\t', ' ')
    270292        finally:
    271293            fp.close()
     
    273295        fullrepr = str(msg)
    274296        lines = fullrepr.split('\n')
    275         self.failUnless(lines[0].startswith('From '))
     297        self.assertTrue(lines[0].startswith('From '))
    276298        eq(text, NL.join(lines[1:]))
    277299
     
    342364                         '"Jim&amp;&amp;Jill"')
    343365
     366    def test_get_param_with_quotes(self):
     367        msg = email.message_from_string(
     368            'Content-Type: foo; bar*0="baz\\"foobar"; bar*1="\\"baz"')
     369        self.assertEqual(msg.get_param('bar'), 'baz"foobar"baz')
     370        msg = email.message_from_string(
     371            "Content-Type: foo; bar*0=\"baz\\\"foobar\"; bar*1=\"\\\"baz\"")
     372        self.assertEqual(msg.get_param('bar'), 'baz"foobar"baz')
     373
    344374    def test_has_key(self):
    345375        msg = email.message_from_string('Header: exists')
    346         self.failUnless(msg.has_key('header'))
    347         self.failUnless(msg.has_key('Header'))
    348         self.failUnless(msg.has_key('HEADER'))
    349         self.failIf(msg.has_key('headeri'))
     376        self.assertTrue(msg.has_key('header'))
     377        self.assertTrue(msg.has_key('Header'))
     378        self.assertTrue(msg.has_key('HEADER'))
     379        self.assertFalse(msg.has_key('headeri'))
    350380
    351381    def test_set_param(self):
     
    525555        self.assertEqual('us-ascii', msg.get_content_charset())
    526556
    527 
     557    # Issue 5871: reject an attempt to embed a header inside a header value
     558    # (header injection attack).
     559    def test_embeded_header_via_Header_rejected(self):
     560        msg = Message()
     561        msg['Dummy'] = Header('dummy\nX-Injected-Header: test')
     562        self.assertRaises(Errors.HeaderParseError, msg.as_string)
     563
     564    def test_embeded_header_via_string_rejected(self):
     565        msg = Message()
     566        msg['Dummy'] = 'dummy\nX-Injected-Header: test'
     567        self.assertRaises(Errors.HeaderParseError, msg.as_string)
    528568
    529569
     
    538578    def test_default_cte(self):
    539579        eq = self.assertEqual
     580        # 7bit data and the default us-ascii _charset
    540581        msg = MIMEText('hello world')
    541582        eq(msg['content-transfer-encoding'], '7bit')
    542 
    543     def test_default_cte(self):
    544         eq = self.assertEqual
    545         # With no explicit _charset its us-ascii, and all are 7-bit
    546         msg = MIMEText('hello world')
    547         eq(msg['content-transfer-encoding'], '7bit')
    548         # Similar, but with 8-bit data
     583        # Similar, but with 8bit data
    549584        msg = MIMEText('hello \xf8 world')
    550585        eq(msg['content-transfer-encoding'], '8bit')
     
    553588        eq(msg['content-transfer-encoding'], 'quoted-printable')
    554589
    555 
     590    def test_encode7or8bit(self):
     591        # Make sure a charset whose input character set is 8bit but
     592        # whose output character set is 7bit gets a transfer-encoding
     593        # of 7bit.
     594        eq = self.assertEqual
     595        msg = email.MIMEText.MIMEText('\xca\xb8', _charset='euc-jp')
     596        eq(msg['content-transfer-encoding'], '7bit')
    556597
    557598
     
    572613        eq(sfp.getvalue(), """\
    573614Subject: bug demonstration
    574 \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
    575 \tmore text
     615 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
     616 more text
    576617
    577618test
     
    673714Content-Transfer-Encoding: 7bit
    674715X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
    675 \tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
     716 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
    676717
    677718''')
     
    689730From: test@dom.ain
    690731References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
    691 \t<5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>
     732 <5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>
    692733
    693734Test""")
     
    767808        eq(msg.as_string(0), '''\
    768809To: "Someone Test #A" <someone@eecs.umich.edu>, <someone@eecs.umich.edu>,
    769 \t"Someone Test #B" <someone@umich.edu>,
    770 \t"Someone Test #C" <someone@eecs.umich.edu>,
    771 \t"Someone Test #D" <someone@eecs.umich.edu>
     810 "Someone Test #B" <someone@umich.edu>,
     811 "Someone Test #C" <someone@eecs.umich.edu>,
     812 "Someone Test #D" <someone@eecs.umich.edu>
    772813
    773814''')
     
    812853\tWed, 05 Mar 2003 18:10:18 -0700
    813854Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
    814 \throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
    815 \tWed, 05 Mar 2003 18:10:18 -0700
     855 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
     856 Wed, 05 Mar 2003 18:10:18 -0700
    816857
    817858""")
     
    820861        h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")'
    821862        msg = Message()
    822         msg['Received-1'] = Header(h, header_name='Received-1',
    823                                    continuation_ws='\t')
    824         msg['Received-2'] = h
    825         self.assertEqual(msg.as_string(), """\
    826 Received-1: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
     863        msg['Received'] = Header(h, header_name='Received',
     864                                 continuation_ws='\t')
     865        msg['Received'] = h
     866        self.ndiffAssertEqual(msg.as_string(), """\
     867Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
    827868\t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
    828 Received-2: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
    829 \t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
     869Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
     870 (David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
    830871
    831872""")
     
    841882        eq(msg.as_string(), """\
    842883Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
    843 \tlocQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
     884 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
    844885Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
    845886 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
     
    851892        m = '''\
    852893Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsoft SMTPSVC(5.0.2195.4905);
    853 \tWed, 16 Oct 2002 07:41:11 -0700'''
     894 Wed, 16 Oct 2002 07:41:11 -0700'''
    854895        msg = email.message_from_string(m)
    855896        eq(msg.as_string(), '''\
    856897Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with
    857 \tMicrosoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700
     898 Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700
    858899
    859900''')
     
    869910        eq(msg.as_string(), """\
    870911List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
    871 \t<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
     912 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
    872913List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
    873914 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
    874915
    875916""")
    876 
    877917
    878918
     
    910950""")
    911951
    912 
     952    def test_mangle_from_in_preamble_and_epilog(self):
     953        s = StringIO()
     954        g = Generator(s, mangle_from_=True)
     955        msg = email.message_from_string(textwrap.dedent("""\
     956            From: foo@bar.com
     957            Mime-Version: 1.0
     958            Content-Type: multipart/mixed; boundary=XXX
     959
     960            From somewhere unknown
     961
     962            --XXX
     963            Content-Type: text/plain
     964
     965            foo
     966
     967            --XXX--
     968
     969            From somewhere unknowable
     970            """))
     971        g.flatten(msg)
     972        self.assertEqual(len([1 for x in s.getvalue().split('\n')
     973                                  if x.startswith('>From ')]), 2)
    913974
    914975
     
    9421003    def test_add_header(self):
    9431004        eq = self.assertEqual
    944         unless = self.failUnless
     1005        unless = self.assertTrue
    9451006        self._au.add_header('Content-Disposition', 'attachment',
    9461007                            filename='audiotest.au')
     
    9621023
    9631024
    964 
    9651025# Test the basic MIMEImage class
    9661026class TestMIMEImage(unittest.TestCase):
     
    9861046    def test_add_header(self):
    9871047        eq = self.assertEqual
    988         unless = self.failUnless
     1048        unless = self.assertTrue
    9891049        self._im.add_header('Content-Disposition', 'attachment',
    9901050                            filename='dingusfish.gif')
     
    10061066
    10071067
    1008 
    10091068# Test the basic MIMEText class
    10101069class TestMIMEText(unittest.TestCase):
     
    10141073    def test_types(self):
    10151074        eq = self.assertEqual
    1016         unless = self.failUnless
     1075        unless = self.assertTrue
    10171076        eq(self._msg.get_content_type(), 'text/plain')
    10181077        eq(self._msg.get_param('charset'), 'us-ascii')
     
    10241083    def test_payload(self):
    10251084        self.assertEqual(self._msg.get_payload(), 'hello there')
    1026         self.failUnless(not self._msg.is_multipart())
     1085        self.assertTrue(not self._msg.is_multipart())
    10271086
    10281087    def test_charset(self):
     
    10321091        eq(msg['content-type'], 'text/plain; charset="us-ascii"')
    10331092
     1093    def test_7bit_unicode_input(self):
     1094        eq = self.assertEqual
     1095        msg = MIMEText(u'hello there', _charset='us-ascii')
     1096        eq(msg.get_charset().input_charset, 'us-ascii')
     1097        eq(msg['content-type'], 'text/plain; charset="us-ascii"')
     1098
     1099    def test_7bit_unicode_input_no_charset(self):
     1100        eq = self.assertEqual
     1101        msg = MIMEText(u'hello there')
     1102        eq(msg.get_charset(), 'us-ascii')
     1103        eq(msg['content-type'], 'text/plain; charset="us-ascii"')
     1104        self.assertTrue('hello there' in msg.as_string())
     1105
     1106    def test_8bit_unicode_input(self):
     1107        teststr = u'\u043a\u0438\u0440\u0438\u043b\u0438\u0446\u0430'
     1108        eq = self.assertEqual
     1109        msg = MIMEText(teststr, _charset='utf-8')
     1110        eq(msg.get_charset().output_charset, 'utf-8')
     1111        eq(msg['content-type'], 'text/plain; charset="utf-8"')
     1112        eq(msg.get_payload(decode=True), teststr.encode('utf-8'))
     1113
     1114    def test_8bit_unicode_input_no_charset(self):
     1115        teststr = u'\u043a\u0438\u0440\u0438\u043b\u0438\u0446\u0430'
     1116        self.assertRaises(UnicodeEncodeError, MIMEText, teststr)
    10341117
    10351118
     
    10691152        else:
    10701153            sign = '+'
    1071         tzoffset = ' %s%04d' % (sign, tzsecs / 36)
     1154        tzoffset = ' %s%04d' % (sign, tzsecs // 36)
    10721155        container['Date'] = time.strftime(
    10731156            '%a, %d %b %Y %H:%M:%S',
     
    10801163        # convenience
    10811164        eq = self.assertEqual
    1082         unless = self.failUnless
     1165        unless = self.assertTrue
    10831166        raises = self.assertRaises
    10841167        # tests
     
    13941477--    XXXX--
    13951478''')
    1396         self.failUnless(msg.is_multipart())
     1479        self.assertTrue(msg.is_multipart())
    13971480        eq(msg.get_boundary(), '    XXXX')
    13981481        eq(len(msg.get_payload()), 2)
     
    14101493YXNkZg==
    14111494--===============0012394164==--""")
    1412         self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==')
    1413 
     1495        self.assertEqual(m.get_payload(0).get_payload(), 'YXNkZg==')
    14141496
    14151497
     
    14251507
    14261508    def test_same_boundary_inner_outer(self):
    1427         unless = self.failUnless
     1509        unless = self.assertTrue
    14281510        msg = self._msgobj('msg_15.txt')
    14291511        # XXX We can probably eventually do better
     
    14351517
    14361518    def test_multipart_no_boundary(self):
    1437         unless = self.failUnless
     1519        unless = self.assertTrue
    14381520        msg = self._msgobj('msg_25.txt')
    14391521        unless(isinstance(msg.get_payload(), str))
     
    14931575
    14941576    def test_lying_multipart(self):
    1495         unless = self.failUnless
     1577        unless = self.assertTrue
    14961578        msg = self._msgobj('msg_41.txt')
    14971579        unless(hasattr(msg, 'defects'))
     
    15131595        bad = outer.get_payload(1).get_payload(0)
    15141596        self.assertEqual(len(bad.defects), 1)
    1515         self.failUnless(isinstance(bad.defects[0],
     1597        self.assertTrue(isinstance(bad.defects[0],
    15161598                                   Errors.StartBoundaryNotFoundDefect))
    15171599
     
    15231605        eq(msg.get_payload(), 'Line 2\nLine 3')
    15241606        eq(len(msg.defects), 1)
    1525         self.failUnless(isinstance(msg.defects[0],
     1607        self.assertTrue(isinstance(msg.defects[0],
    15261608                                   Errors.FirstHeaderLineIsContinuationDefect))
    15271609        eq(msg.defects[0].line, ' Line 1\n')
    1528 
    15291610
    15301611
     
    15761657                              ('sbord', None)])
    15771658
    1578 
     1659    def test_rfc2047_B_bad_padding(self):
     1660        s = '=?iso-8859-1?B?%s?='
     1661        data = [                                # only test complete bytes
     1662            ('dm==', 'v'), ('dm=', 'v'), ('dm', 'v'),
     1663            ('dmk=', 'vi'), ('dmk', 'vi')
     1664          ]
     1665        for q, a in data:
     1666            dh = decode_header(s % q)
     1667            self.assertEqual(dh, [(a, 'iso-8859-1')])
     1668
     1669    def test_rfc2047_Q_invalid_digits(self):
     1670        # issue 10004.
     1671        s = '=?iso-8659-1?Q?andr=e9=zz?='
     1672        self.assertEqual(decode_header(s),
     1673                        [(b'andr\xe9=zz', 'iso-8659-1')])
    15791674
    15801675
     
    15931688    def test_valid_argument(self):
    15941689        eq = self.assertEqual
    1595         unless = self.failUnless
     1690        unless = self.assertTrue
    15961691        subject = 'A sub-message'
    15971692        m = Message()
     
    16371732    def test_parse_message_rfc822(self):
    16381733        eq = self.assertEqual
    1639         unless = self.failUnless
     1734        unless = self.assertTrue
    16401735        msg = self._msgobj('msg_11.txt')
    16411736        eq(msg.get_content_type(), 'message/rfc822')
     
    16441739        eq(len(payload), 1)
    16451740        submsg = payload[0]
    1646         self.failUnless(isinstance(submsg, Message))
     1741        self.assertTrue(isinstance(submsg, Message))
    16471742        eq(submsg['subject'], 'An enclosed message')
    16481743        eq(submsg.get_payload(), 'Here is the body of the message.\n')
     
    16501745    def test_dsn(self):
    16511746        eq = self.assertEqual
    1652         unless = self.failUnless
     1747        unless = self.assertTrue
    16531748        # msg 16 is a Delivery Status Notification, see RFC 1894
    16541749        msg = self._msgobj('msg_16.txt')
     
    18921987
    18931988
    1894 
    18951989# A general test of parser->model->generator idempotency.  IOW, read a message
    18961990# in, parse it into a message object tree, then without touching the tree,
     
    19162010
    19172011    def test_parse_text_message(self):
    1918         eq = self.assertEquals
     2012        eq = self.assertEqual
    19192013        msg, text = self._msgobj('msg_01.txt')
    19202014        eq(msg.get_content_type(), 'text/plain')
     
    19282022
    19292023    def test_parse_untyped_message(self):
    1930         eq = self.assertEquals
     2024        eq = self.assertEqual
    19312025        msg, text = self._msgobj('msg_03.txt')
    19322026        eq(msg.get_content_type(), 'text/plain')
     
    20002094
    20012095    def test_content_type(self):
    2002         eq = self.assertEquals
    2003         unless = self.failUnless
     2096        eq = self.assertEqual
     2097        unless = self.assertTrue
    20042098        # Get a message object and reset the seek pointer for other tests
    20052099        msg, text = self._msgobj('msg_05.txt')
     
    20232117        msg3 = msg.get_payload(2)
    20242118        eq(msg3.get_content_type(), 'message/rfc822')
    2025         self.failUnless(isinstance(msg3, Message))
     2119        self.assertTrue(isinstance(msg3, Message))
    20262120        payload = msg3.get_payload()
    20272121        unless(isinstance(payload, list))
     
    20322126
    20332127    def test_parser(self):
    2034         eq = self.assertEquals
    2035         unless = self.failUnless
     2128        eq = self.assertEqual
     2129        unless = self.assertTrue
    20362130        msg, text = self._msgobj('msg_06.txt')
    20372131        # Check some of the outer headers
     
    20432137        eq(len(payload), 1)
    20442138        msg1 = payload[0]
    2045         self.failUnless(isinstance(msg1, Message))
     2139        self.assertTrue(isinstance(msg1, Message))
    20462140        eq(msg1.get_content_type(), 'text/plain')
    2047         self.failUnless(isinstance(msg1.get_payload(), str))
     2141        self.assertTrue(isinstance(msg1.get_payload(), str))
    20482142        eq(msg1.get_payload(), '\n')
    2049 
    20502143
    20512144
     
    20832176
    20842177    def test_message_from_string_with_class(self):
    2085         unless = self.failUnless
     2178        unless = self.assertTrue
    20862179        fp = openfile('msg_01.txt')
    20872180        try:
     
    21062199
    21072200    def test_message_from_file_with_class(self):
    2108         unless = self.failUnless
     2201        unless = self.assertTrue
    21092202        # Create a subclass
    21102203        class MyMessage(Message):
     
    21932286        eq(int(time.strftime('%Y', timetup[:9])), 2003)
    21942287
     2288    def test_mktime_tz(self):
     2289        self.assertEqual(Utils.mktime_tz((1970, 1, 1, 0, 0, 0,
     2290                                          -1, -1, -1, 0)), 0)
     2291        self.assertEqual(Utils.mktime_tz((1970, 1, 1, 0, 0, 0,
     2292                                          -1, -1, -1, 1234)), -1234)
     2293
     2294    def test_parsedate_y2k(self):
     2295        """Test for parsing a date with a two-digit year.
     2296
     2297        Parsing a date with a two-digit year should return the correct
     2298        four-digit year. RFC822 allows two-digit years, but RFC2822 (which
     2299        obsoletes RFC822) requires four-digit years.
     2300
     2301        """
     2302        self.assertEqual(Utils.parsedate_tz('25 Feb 03 13:47:26 -0800'),
     2303                         Utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'))
     2304        self.assertEqual(Utils.parsedate_tz('25 Feb 71 13:47:26 -0800'),
     2305                         Utils.parsedate_tz('25 Feb 1971 13:47:26 -0800'))
     2306
    21952307    def test_parseaddr_empty(self):
    21962308        self.assertEqual(Utils.parseaddr('<>'), ('', ''))
     
    22272339        self.assertEqual(Utils.formataddr((a, b)), y)
    22282340
     2341    def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
     2342        # issue 10005.  Note that in the third test the second pair of
     2343        # backslashes is not actually a quoted pair because it is not inside a
     2344        # comment or quoted string: the address being parsed has a quoted
     2345        # string containing a quoted backslash, followed by 'example' and two
     2346        # backslashes, followed by another quoted string containing a space and
     2347        # the word 'example'.  parseaddr copies those two backslashes
     2348        # literally.  Per rfc5322 this is not technically correct since a \ may
     2349        # not appear in an address outside of a quoted string.  It is probably
     2350        # a sensible Postel interpretation, though.
     2351        eq = self.assertEqual
     2352        eq(Utils.parseaddr('""example" example"@example.com'),
     2353          ('', '""example" example"@example.com'))
     2354        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
     2355          ('', '"\\"example\\" example"@example.com'))
     2356        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
     2357          ('', '"\\\\"example\\\\" example"@example.com'))
     2358
    22292359    def test_multiline_from_comment(self):
    22302360        x = """\
     
    22482378    def test_charset_richcomparisons(self):
    22492379        eq = self.assertEqual
    2250         ne = self.failIfEqual
     2380        ne = self.assertNotEqual
    22512381        cset1 = Charset()
    22522382        cset2 = Charset()
     
    23752505
    23762506
    2377 
    23782507# Test the iterator/generators
    23792508class TestIterators(TestEmailBase):
     
    24342563""")
    24352564
     2565    def test_pushCR_LF(self):
     2566        '''FeedParser BufferedSubFile.push() assumed it received complete
     2567           line endings.  A CR ending one push() followed by a LF starting
     2568           the next push() added an empty line.
     2569        '''
     2570        imt = [
     2571            ("a\r \n",  2),
     2572            ("b",       0),
     2573            ("c\n",     1),
     2574            ("",        0),
     2575            ("d\r\n",   1),
     2576            ("e\r",     0),
     2577            ("\nf",     1),
     2578            ("\r\n",    1),
     2579          ]
     2580        from email.feedparser import BufferedSubFile, NeedMoreData
     2581        bsf = BufferedSubFile()
     2582        om = []
     2583        nt = 0
     2584        for il, n in imt:
     2585            bsf.push(il)
     2586            nt += n
     2587            n1 = 0
     2588            while True:
     2589                ol = bsf.readline()
     2590                if ol == NeedMoreData:
     2591                    break
     2592                om.append(ol)
     2593                n1 += 1
     2594            self.assertTrue(n == n1)
     2595        self.assertTrue(len(om) == nt)
     2596        self.assertTrue(''.join([il for il, n in imt]) == ''.join(om))
    24362597
    24372598
     
    24492610        eq(msg['to'], 'ppp@zzz.org')
    24502611        eq(msg.get_content_type(), 'multipart/mixed')
    2451         self.failIf(msg.is_multipart())
    2452         self.failUnless(isinstance(msg.get_payload(), str))
     2612        self.assertFalse(msg.is_multipart())
     2613        self.assertTrue(isinstance(msg.get_payload(), str))
    24532614
    24542615    def test_whitespace_continuation(self):
     
    25802741        eq(msg.get_payload(), 'body')
    25812742
    2582 
     2743    def test_CRLFLF_at_end_of_part(self):
     2744        # issue 5610: feedparser should not eat two chars from body part ending
     2745        # with "\r\n\n".
     2746        m = (
     2747            "From: foo@bar.com\n"
     2748            "To: baz\n"
     2749            "Mime-Version: 1.0\n"
     2750            "Content-Type: multipart/mixed; boundary=BOUNDARY\n"
     2751            "\n"
     2752            "--BOUNDARY\n"
     2753            "Content-Type: text/plain\n"
     2754            "\n"
     2755            "body ending with CRLF newline\r\n"
     2756            "\n"
     2757            "--BOUNDARY--\n"
     2758          )
     2759        msg = email.message_from_string(m)
     2760        self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n'))
    25832761
    25842762
     
    26552833
    26562834
    2657 
    26582835class TestQuopri(unittest.TestCase):
    26592836    def setUp(self):
     
    26712848    def test_header_quopri_check(self):
    26722849        for c in self.hlit:
    2673             self.failIf(quopriMIME.header_quopri_check(c))
     2850            self.assertFalse(quopriMIME.header_quopri_check(c))
    26742851        for c in self.hnon:
    2675             self.failUnless(quopriMIME.header_quopri_check(c))
     2852            self.assertTrue(quopriMIME.header_quopri_check(c))
    26762853
    26772854    def test_body_quopri_check(self):
    26782855        for c in self.blit:
    2679             self.failIf(quopriMIME.body_quopri_check(c))
     2856            self.assertFalse(quopriMIME.body_quopri_check(c))
    26802857        for c in self.bnon:
    2681             self.failUnless(quopriMIME.body_quopri_check(c))
     2858            self.assertTrue(quopriMIME.body_quopri_check(c))
    26822859
    26832860    def test_header_quopri_len(self):
     
    27662943
    27672944
    2768 
    27692945# Test the Charset class
    27702946class TestCharset(unittest.TestCase):
     
    27992975        c = Charset('us-ascii')
    28002976        eq('hello world', c.body_encode('hello world'))
    2801         # Try the convert argument, where input codec <> output codec
     2977        # Try the convert argument, where input codec != output codec
    28022978        c = Charset('euc-jp')
    28032979        # With apologies to Tokio Kikuchi ;)
     
    28232999        self.assertRaises(Errors.CharsetError, Charset, 'asc\xffii')
    28243000
    2825 
     3001    def test_codecs_aliases_accepted(self):
     3002        charset = Charset('utf8')
     3003        self.assertEqual(str(charset), 'utf-8')
    28263004
    28273005
     
    28503028                   maxlinelen=76)
    28513029        for l in h.encode(splitchars=' ').split('\n '):
    2852             self.failUnless(len(l) <= 76)
     3030            self.assertTrue(len(l) <= 76)
    28533031
    28543032    def test_multilingual(self):
     
    29843162    def test_broken_base64_header(self):
    29853163        raises = self.assertRaises
    2986         s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?='
     3164        s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?='
    29873165        raises(Errors.HeaderParseError, decode_header, s)
    29883166
    2989 
     3167    # Issue 1078919
     3168    def test_ascii_add_header(self):
     3169        msg = Message()
     3170        msg.add_header('Content-Disposition', 'attachment',
     3171                       filename='bud.gif')
     3172        self.assertEqual('attachment; filename="bud.gif"',
     3173            msg['Content-Disposition'])
     3174
     3175    def test_nonascii_add_header_via_triple(self):
     3176        msg = Message()
     3177        msg.add_header('Content-Disposition', 'attachment',
     3178            filename=('iso-8859-1', '', 'Fu\xdfballer.ppt'))
     3179        self.assertEqual(
     3180            'attachment; filename*="iso-8859-1\'\'Fu%DFballer.ppt"',
     3181            msg['Content-Disposition'])
     3182
     3183    def test_encode_unaliased_charset(self):
     3184        # Issue 1379416: when the charset has no output conversion,
     3185        # output was accidentally getting coerced to unicode.
     3186        res = Header('abc','iso-8859-2').encode()
     3187        self.assertEqual(res, '=?iso-8859-2?q?abc?=')
     3188        self.assertIsInstance(res, str)
    29903189
    29913190
     
    30143213        msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
    30153214                      charset='us-ascii', language='en')
    3016         eq(msg.as_string(), """\
     3215        self.ndiffAssertEqual(msg.as_string(), """\
    30173216Return-Path: <bbb@zzz.org>
    30183217Delivered-To: bbb@zzz.org
    30193218Received: by mail.zzz.org (Postfix, from userid 889)
    3020 \tid 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
     3219 id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
    30213220MIME-Version: 1.0
    30223221Content-Transfer-Encoding: 7bit
     
    30273226Date: Fri, 4 May 2001 14:05:44 -0400
    30283227Content-Type: text/plain; charset=us-ascii;
    3029 \ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
     3228 title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
    30303229
    30313230
     
    30483247Delivered-To: bbb@zzz.org
    30493248Received: by mail.zzz.org (Postfix, from userid 889)
    3050 \tid 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
     3249 id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
    30513250MIME-Version: 1.0
    30523251Content-Transfer-Encoding: 7bit
     
    30573256Date: Fri, 4 May 2001 14:05:44 -0400
    30583257Content-Type: text/plain; charset="us-ascii";
    3059 \ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
     3258 title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
    30603259
    30613260
     
    30813280        msg = email.message_from_string(m)
    30823281        param = msg.get_param('NAME')
    3083         self.failIf(isinstance(param, tuple))
     3282        self.assertFalse(isinstance(param, tuple))
    30843283        self.assertEqual(
    30853284            param,
     
    32343433        msg = email.message_from_string(m)
    32353434        param = msg.get_param('name')
    3236         self.failIf(isinstance(param, tuple))
     3435        self.assertFalse(isinstance(param, tuple))
    32373436        self.assertEqual(param, "Frank's Document")
    32383437
     
    32583457        msg = email.message_from_string(m)
    32593458        param = msg.get_param('name')
    3260         self.failIf(isinstance(param, tuple))
     3459        self.assertFalse(isinstance(param, tuple))
    32613460        self.assertEqual(param, "us-ascii'en-us'Frank's Document")
    32623461
     
    32993498        eq(language, 'en-us')
    33003499        eq(s, 'My Document For You')
    3301 
    33023500
    33033501
     
    33393537
    33403538
    3341 
    33423539def _testclasses():
    33433540    mod = sys.modules[__name__]
     
    33583555
    33593556
    3360 
    33613557if __name__ == '__main__':
    33623558    unittest.main(defaultTest='suite')
  • python/vendor/current/Lib/email/test/test_email_codecs.py

    r2 r388  
    44
    55import unittest
    6 from test.test_support import TestSkipped, run_unittest
     6from test.test_support import run_unittest
    77
    88from email.test.test_email import TestEmailBase
     
    1616    unicode('foo', 'euc-jp')
    1717except LookupError:
    18     raise TestSkipped
     18    raise unittest.SkipTest
    1919
    2020
  • python/vendor/current/Lib/email/test/test_email_codecs_renamed.py

    r2 r388  
    44
    55import unittest
    6 from test.test_support import TestSkipped, run_unittest
     6from test.test_support import run_unittest
    77
    88from email.test.test_email import TestEmailBase
     
    1616    unicode('foo', 'euc-jp')
    1717except LookupError:
    18     raise TestSkipped
     18    raise unittest.SkipTest
    1919
    2020
  • python/vendor/current/Lib/email/test/test_email_renamed.py

    r2 r388  
    4343
    4444
    45 
    4645def openfile(filename, mode='r'):
    4746    path = os.path.join(os.path.dirname(landmark), 'data', filename)
     
    5049
    5150
    52 
    5351# Base test class
    5452class TestEmailBase(unittest.TestCase):
    5553    def ndiffAssertEqual(self, first, second):
    56         """Like failUnlessEqual except use ndiff for readable output."""
    57         if first <> second:
     54        """Like assertEqual except use ndiff for readable output."""
     55        if first != second:
    5856            sfirst = str(first)
    5957            ssecond = str(second)
     
    7068            fp.close()
    7169        return msg
    72 
    7370
    7471
     
    198195        eq(msg.get_payload(2).get_payload(decode=True),
    199196           'This is a Base64 encoded message.')
    200         # Subpart 4 has no Content-Transfer-Encoding: header.
     197        # Subpart 4 is base64 with a trailing newline, which
     198        # used to be stripped (issue 7143).
    201199        eq(msg.get_payload(3).get_payload(decode=True),
     200           'This is a Base64 encoded message.\n')
     201        # Subpart 5 has no Content-Transfer-Encoding: header.
     202        eq(msg.get_payload(4).get_payload(decode=True),
    202203           'This has no Content-Transfer-Encoding: header.\n')
    203204
     
    231232        msg['to'] = 'You'
    232233        # Check for case insensitivity
    233         self.failUnless('from' in msg)
    234         self.failUnless('From' in msg)
    235         self.failUnless('FROM' in msg)
    236         self.failUnless('to' in msg)
    237         self.failUnless('To' in msg)
    238         self.failUnless('TO' in msg)
     234        self.assertTrue('from' in msg)
     235        self.assertTrue('From' in msg)
     236        self.assertTrue('FROM' in msg)
     237        self.assertTrue('to' in msg)
     238        self.assertTrue('To' in msg)
     239        self.assertTrue('TO' in msg)
    239240
    240241    def test_as_string(self):
     
    243244        fp = openfile('msg_01.txt')
    244245        try:
    245             text = fp.read()
     246            # BAW 30-Mar-2009 Evil be here.  So, the generator is broken with
     247            # respect to long line breaking.  It's also not idempotent when a
     248            # header from a parsed message is continued with tabs rather than
     249            # spaces.  Before we fixed bug 1974 it was reversedly broken,
     250            # i.e. headers that were continued with spaces got continued with
     251            # tabs.  For Python 2.x there's really no good fix and in Python
     252            # 3.x all this stuff is re-written to be right(er).  Chris Withers
     253            # convinced me that using space as the default continuation
     254            # character is less bad for more applications.
     255            text = fp.read().replace('\t', ' ')
    246256        finally:
    247257            fp.close()
    248         eq(text, msg.as_string())
     258        self.ndiffAssertEqual(text, msg.as_string())
    249259        fullrepr = str(msg)
    250260        lines = fullrepr.split('\n')
    251         self.failUnless(lines[0].startswith('From '))
     261        self.assertTrue(lines[0].startswith('From '))
    252262        eq(text, NL.join(lines[1:]))
    253263
     
    320330    def test_has_key(self):
    321331        msg = email.message_from_string('Header: exists')
    322         self.failUnless(msg.has_key('header'))
    323         self.failUnless(msg.has_key('Header'))
    324         self.failUnless(msg.has_key('HEADER'))
    325         self.failIf(msg.has_key('headeri'))
     332        self.assertTrue(msg.has_key('header'))
     333        self.assertTrue(msg.has_key('Header'))
     334        self.assertTrue(msg.has_key('HEADER'))
     335        self.assertFalse(msg.has_key('headeri'))
    326336
    327337    def test_set_param(self):
     
    496506
    497507
    498 
    499508# Test the email.encoders module
    500509class TestEncoders(unittest.TestCase):
     
    524533
    525534
    526 
    527535# Test long header wrapping
    528536class TestLongHeaders(TestEmailBase):
     
    541549        eq(sfp.getvalue(), """\
    542550Subject: bug demonstration
    543 \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
    544 \tmore text
     551 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
     552 more text
    545553
    546554test
     
    642650Content-Transfer-Encoding: 7bit
    643651X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
    644 \tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
     652 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
    645653
    646654''')
     
    658666From: test@dom.ain
    659667References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
    660 \t<5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>
     668 <5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>
    661669
    662670Test""")
     
    736744        eq(msg.as_string(0), '''\
    737745To: "Someone Test #A" <someone@eecs.umich.edu>, <someone@eecs.umich.edu>,
    738 \t"Someone Test #B" <someone@umich.edu>,
    739 \t"Someone Test #C" <someone@eecs.umich.edu>,
    740 \t"Someone Test #D" <someone@eecs.umich.edu>
     746 "Someone Test #B" <someone@umich.edu>,
     747 "Someone Test #C" <someone@eecs.umich.edu>,
     748 "Someone Test #D" <someone@eecs.umich.edu>
    741749
    742750''')
     
    776784        msg['Received-1'] = Header(h, continuation_ws='\t')
    777785        msg['Received-2'] = h
    778         self.assertEqual(msg.as_string(), """\
     786        self.ndiffAssertEqual(msg.as_string(), """\
    779787Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
    780788\throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
    781789\tWed, 05 Mar 2003 18:10:18 -0700
    782790Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
    783 \throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
    784 \tWed, 05 Mar 2003 18:10:18 -0700
     791 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
     792 Wed, 05 Mar 2003 18:10:18 -0700
    785793
    786794""")
     
    789797        h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")'
    790798        msg = Message()
    791         msg['Received-1'] = Header(h, header_name='Received-1',
    792                                    continuation_ws='\t')
    793         msg['Received-2'] = h
    794         self.assertEqual(msg.as_string(), """\
    795 Received-1: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
     799        msg['Received'] = Header(h, header_name='Received-1',
     800                                 continuation_ws='\t')
     801        msg['Received'] = h
     802        self.ndiffAssertEqual(msg.as_string(), """\
     803Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
    796804\t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
    797 Received-2: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
    798 \t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
     805Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
     806 (David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
    799807
    800808""")
     
    810818        eq(msg.as_string(), """\
    811819Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
    812 \tlocQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
     820 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
    813821Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
    814822 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
     
    820828        m = '''\
    821829Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsoft SMTPSVC(5.0.2195.4905);
    822 \tWed, 16 Oct 2002 07:41:11 -0700'''
     830 Wed, 16 Oct 2002 07:41:11 -0700'''
    823831        msg = email.message_from_string(m)
    824832        eq(msg.as_string(), '''\
    825833Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with
    826 \tMicrosoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700
     834 Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700
    827835
    828836''')
     
    836844        msg['List'] = h
    837845        msg['List'] = Header(h, header_name='List')
    838         eq(msg.as_string(), """\
    839 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
    840 \t<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
     846        self.ndiffAssertEqual(msg.as_string(), """\
    841847List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
    842848 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
     849List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
     850 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
    843851
    844852""")
    845 
    846853
    847854
     
    878885Blah blah blah
    879886""")
    880 
    881887
    882888
     
    911917    def test_add_header(self):
    912918        eq = self.assertEqual
    913         unless = self.failUnless
     919        unless = self.assertTrue
    914920        self._au.add_header('Content-Disposition', 'attachment',
    915921                            filename='audiotest.au')
     
    931937
    932938
    933 
    934939# Test the basic MIMEImage class
    935940class TestMIMEImage(unittest.TestCase):
     
    955960    def test_add_header(self):
    956961        eq = self.assertEqual
    957         unless = self.failUnless
     962        unless = self.assertTrue
    958963        self._im.add_header('Content-Disposition', 'attachment',
    959964                            filename='dingusfish.gif')
     
    975980
    976981
    977 
    978982# Test the basic MIMEApplication class
    979983class TestMIMEApplication(unittest.TestCase):
     
    991995        eq(msg.get_payload(decode=True), bytes)
    992996
    993 
     997    def test_binary_body_with_encode_7or8bit(self):
     998        # Issue 17171.
     999        bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
     1000        msg = MIMEApplication(bytesdata, _encoder=encoders.encode_7or8bit)
     1001        # Treated as a string, this will be invalid code points.
     1002        self.assertEqual(msg.get_payload(), bytesdata)
     1003        self.assertEqual(msg.get_payload(decode=True), bytesdata)
     1004        self.assertEqual(msg['Content-Transfer-Encoding'], '8bit')
     1005        s = StringIO()
     1006        g = Generator(s)
     1007        g.flatten(msg)
     1008        wireform = s.getvalue()
     1009        msg2 = email.message_from_string(wireform)
     1010        self.assertEqual(msg.get_payload(), bytesdata)
     1011        self.assertEqual(msg2.get_payload(decode=True), bytesdata)
     1012        self.assertEqual(msg2['Content-Transfer-Encoding'], '8bit')
     1013
     1014    def test_binary_body_with_encode_noop(self):
     1015        # Issue 16564: This does not produce an RFC valid message, since to be
     1016        # valid it should have a CTE of binary.  But the below works, and is
     1017        # documented as working this way.
     1018        bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
     1019        msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop)
     1020        self.assertEqual(msg.get_payload(), bytesdata)
     1021        self.assertEqual(msg.get_payload(decode=True), bytesdata)
     1022        s = StringIO()
     1023        g = Generator(s)
     1024        g.flatten(msg)
     1025        wireform = s.getvalue()
     1026        msg2 = email.message_from_string(wireform)
     1027        self.assertEqual(msg.get_payload(), bytesdata)
     1028        self.assertEqual(msg2.get_payload(decode=True), bytesdata)
    9941029
    9951030
     
    10011036    def test_types(self):
    10021037        eq = self.assertEqual
    1003         unless = self.failUnless
     1038        unless = self.assertTrue
    10041039        eq(self._msg.get_content_type(), 'text/plain')
    10051040        eq(self._msg.get_param('charset'), 'us-ascii')
     
    10111046    def test_payload(self):
    10121047        self.assertEqual(self._msg.get_payload(), 'hello there')
    1013         self.failUnless(not self._msg.is_multipart())
     1048        self.assertTrue(not self._msg.is_multipart())
    10141049
    10151050    def test_charset(self):
     
    10181053        eq(msg.get_charset().input_charset, 'us-ascii')
    10191054        eq(msg['content-type'], 'text/plain; charset="us-ascii"')
    1020 
    10211055
    10221056
     
    10561090        else:
    10571091            sign = '+'
    1058         tzoffset = ' %s%04d' % (sign, tzsecs / 36)
     1092        tzoffset = ' %s%04d' % (sign, tzsecs // 36)
    10591093        container['Date'] = time.strftime(
    10601094            '%a, %d %b %Y %H:%M:%S',
     
    10671101        # convenience
    10681102        eq = self.assertEqual
    1069         unless = self.failUnless
     1103        unless = self.assertTrue
    10701104        raises = self.assertRaises
    10711105        # tests
     
    13811415--    XXXX--
    13821416''')
    1383         self.failUnless(msg.is_multipart())
     1417        self.assertTrue(msg.is_multipart())
    13841418        eq(msg.get_boundary(), '    XXXX')
    13851419        eq(len(msg.get_payload()), 2)
     
    13971431YXNkZg==
    13981432--===============0012394164==--""")
    1399         self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==')
    1400 
     1433        self.assertEqual(m.get_payload(0).get_payload(), 'YXNkZg==')
    14011434
    14021435
     
    14121445
    14131446    def test_same_boundary_inner_outer(self):
    1414         unless = self.failUnless
     1447        unless = self.assertTrue
    14151448        msg = self._msgobj('msg_15.txt')
    14161449        # XXX We can probably eventually do better
     
    14221455
    14231456    def test_multipart_no_boundary(self):
    1424         unless = self.failUnless
     1457        unless = self.assertTrue
    14251458        msg = self._msgobj('msg_25.txt')
    14261459        unless(isinstance(msg.get_payload(), str))
     
    14801513
    14811514    def test_lying_multipart(self):
    1482         unless = self.failUnless
     1515        unless = self.assertTrue
    14831516        msg = self._msgobj('msg_41.txt')
    14841517        unless(hasattr(msg, 'defects'))
     
    15001533        bad = outer.get_payload(1).get_payload(0)
    15011534        self.assertEqual(len(bad.defects), 1)
    1502         self.failUnless(isinstance(bad.defects[0],
     1535        self.assertTrue(isinstance(bad.defects[0],
    15031536                                   errors.StartBoundaryNotFoundDefect))
    15041537
     
    15101543        eq(msg.get_payload(), 'Line 2\nLine 3')
    15111544        eq(len(msg.defects), 1)
    1512         self.failUnless(isinstance(msg.defects[0],
     1545        self.assertTrue(isinstance(msg.defects[0],
    15131546                                   errors.FirstHeaderLineIsContinuationDefect))
    15141547        eq(msg.defects[0].line, ' Line 1\n')
    1515 
    15161548
    15171549
     
    15641596
    15651597
    1566 
    15671598# Test the MIMEMessage class
    15681599class TestMIMEMessage(TestEmailBase):
     
    15791610    def test_valid_argument(self):
    15801611        eq = self.assertEqual
    1581         unless = self.failUnless
     1612        unless = self.assertTrue
    15821613        subject = 'A sub-message'
    15831614        m = Message()
     
    16231654    def test_parse_message_rfc822(self):
    16241655        eq = self.assertEqual
    1625         unless = self.failUnless
     1656        unless = self.assertTrue
    16261657        msg = self._msgobj('msg_11.txt')
    16271658        eq(msg.get_content_type(), 'message/rfc822')
     
    16301661        eq(len(payload), 1)
    16311662        submsg = payload[0]
    1632         self.failUnless(isinstance(submsg, Message))
     1663        self.assertTrue(isinstance(submsg, Message))
    16331664        eq(submsg['subject'], 'An enclosed message')
    16341665        eq(submsg.get_payload(), 'Here is the body of the message.\n')
     
    16361667    def test_dsn(self):
    16371668        eq = self.assertEqual
    1638         unless = self.failUnless
     1669        unless = self.assertTrue
    16391670        # msg 16 is a Delivery Status Notification, see RFC 1894
    16401671        msg = self._msgobj('msg_16.txt')
     
    18751906
    18761907
    1877 
    18781908# A general test of parser->model->generator idempotency.  IOW, read a message
    18791909# in, parse it into a message object tree, then without touching the tree,
     
    18991929
    19001930    def test_parse_text_message(self):
    1901         eq = self.assertEquals
     1931        eq = self.assertEqual
    19021932        msg, text = self._msgobj('msg_01.txt')
    19031933        eq(msg.get_content_type(), 'text/plain')
     
    19111941
    19121942    def test_parse_untyped_message(self):
    1913         eq = self.assertEquals
     1943        eq = self.assertEqual
    19141944        msg, text = self._msgobj('msg_03.txt')
    19151945        eq(msg.get_content_type(), 'text/plain')
     
    19832013
    19842014    def test_content_type(self):
    1985         eq = self.assertEquals
    1986         unless = self.failUnless
     2015        eq = self.assertEqual
     2016        unless = self.assertTrue
    19872017        # Get a message object and reset the seek pointer for other tests
    19882018        msg, text = self._msgobj('msg_05.txt')
     
    20062036        msg3 = msg.get_payload(2)
    20072037        eq(msg3.get_content_type(), 'message/rfc822')
    2008         self.failUnless(isinstance(msg3, Message))
     2038        self.assertTrue(isinstance(msg3, Message))
    20092039        payload = msg3.get_payload()
    20102040        unless(isinstance(payload, list))
     
    20152045
    20162046    def test_parser(self):
    2017         eq = self.assertEquals
    2018         unless = self.failUnless
     2047        eq = self.assertEqual
     2048        unless = self.assertTrue
    20192049        msg, text = self._msgobj('msg_06.txt')
    20202050        # Check some of the outer headers
     
    20262056        eq(len(payload), 1)
    20272057        msg1 = payload[0]
    2028         self.failUnless(isinstance(msg1, Message))
     2058        self.assertTrue(isinstance(msg1, Message))
    20292059        eq(msg1.get_content_type(), 'text/plain')
    2030         self.failUnless(isinstance(msg1.get_payload(), str))
     2060        self.assertTrue(isinstance(msg1.get_payload(), str))
    20312061        eq(msg1.get_payload(), '\n')
    2032 
    20332062
    20342063
     
    20662095
    20672096    def test_message_from_string_with_class(self):
    2068         unless = self.failUnless
     2097        unless = self.assertTrue
    20692098        fp = openfile('msg_01.txt')
    20702099        try:
     
    20892118
    20902119    def test_message_from_file_with_class(self):
    2091         unless = self.failUnless
     2120        unless = self.assertTrue
    20922121        # Create a subclass
    20932122        class MyMessage(Message):
     
    22322261    def test_charset_richcomparisons(self):
    22332262        eq = self.assertEqual
    2234         ne = self.failIfEqual
     2263        ne = self.assertNotEqual
    22352264        cset1 = Charset()
    22362265        cset2 = Charset()
     
    23592388
    23602389
    2361 
    23622390# Test the iterator/generators
    23632391class TestIterators(TestEmailBase):
     
    24202448
    24212449
    2422 
    24232450class TestParsers(TestEmailBase):
    24242451    def test_header_parser(self):
     
    24332460        eq(msg['to'], 'ppp@zzz.org')
    24342461        eq(msg.get_content_type(), 'multipart/mixed')
    2435         self.failIf(msg.is_multipart())
    2436         self.failUnless(isinstance(msg.get_payload(), str))
     2462        self.assertFalse(msg.is_multipart())
     2463        self.assertTrue(isinstance(msg.get_payload(), str))
    24372464
    24382465    def test_whitespace_continuation(self):
     
    25662593
    25672594
    2568 
    25692595class TestBase64(unittest.TestCase):
    25702596    def test_len(self):
     
    26392665
    26402666
    2641 
    26422667class TestQuopri(unittest.TestCase):
    26432668    def setUp(self):
     
    26552680    def test_header_quopri_check(self):
    26562681        for c in self.hlit:
    2657             self.failIf(quoprimime.header_quopri_check(c))
     2682            self.assertFalse(quoprimime.header_quopri_check(c))
    26582683        for c in self.hnon:
    2659             self.failUnless(quoprimime.header_quopri_check(c))
     2684            self.assertTrue(quoprimime.header_quopri_check(c))
    26602685
    26612686    def test_body_quopri_check(self):
    26622687        for c in self.blit:
    2663             self.failIf(quoprimime.body_quopri_check(c))
     2688            self.assertFalse(quoprimime.body_quopri_check(c))
    26642689        for c in self.bnon:
    2665             self.failUnless(quoprimime.body_quopri_check(c))
     2690            self.assertTrue(quoprimime.body_quopri_check(c))
    26662691
    26672692    def test_header_quopri_len(self):
     
    27502775
    27512776
    2752 
    27532777# Test the Charset class
    27542778class TestCharset(unittest.TestCase):
     
    27832807        c = Charset('us-ascii')
    27842808        eq('hello world', c.body_encode('hello world'))
    2785         # Try the convert argument, where input codec <> output codec
     2809        # Try the convert argument, where input codec != output codec
    27862810        c = Charset('euc-jp')
    27872811        # With apologies to Tokio Kikuchi ;)
     
    28092833
    28102834
    2811 
    28122835# Test multilingual MIME headers.
    28132836class TestHeader(TestEmailBase):
     
    28342857                   maxlinelen=76)
    28352858        for l in h.encode(splitchars=' ').split('\n '):
    2836             self.failUnless(len(l) <= 76)
     2859            self.assertTrue(len(l) <= 76)
    28372860
    28382861    def test_multilingual(self):
     
    29682991    def test_broken_base64_header(self):
    29692992        raises = self.assertRaises
    2970         s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?='
     2993        s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?='
    29712994        raises(errors.HeaderParseError, decode_header, s)
    2972 
    29732995
    29742996
     
    29983020        msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
    29993021                      charset='us-ascii', language='en')
    3000         eq(msg.as_string(), """\
     3022        self.ndiffAssertEqual(msg.as_string(), """\
    30013023Return-Path: <bbb@zzz.org>
    30023024Delivered-To: bbb@zzz.org
    30033025Received: by mail.zzz.org (Postfix, from userid 889)
    3004 \tid 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
     3026 id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
    30053027MIME-Version: 1.0
    30063028Content-Transfer-Encoding: 7bit
     
    30113033Date: Fri, 4 May 2001 14:05:44 -0400
    30123034Content-Type: text/plain; charset=us-ascii;
    3013 \ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
     3035 title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
    30143036
    30153037
     
    30323054Delivered-To: bbb@zzz.org
    30333055Received: by mail.zzz.org (Postfix, from userid 889)
    3034 \tid 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
     3056 id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
    30353057MIME-Version: 1.0
    30363058Content-Transfer-Encoding: 7bit
     
    30413063Date: Fri, 4 May 2001 14:05:44 -0400
    30423064Content-Type: text/plain; charset="us-ascii";
    3043 \ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
     3065 title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
    30443066
    30453067
     
    30653087        msg = email.message_from_string(m)
    30663088        param = msg.get_param('NAME')
    3067         self.failIf(isinstance(param, tuple))
     3089        self.assertFalse(isinstance(param, tuple))
    30683090        self.assertEqual(
    30693091            param,
     
    32183240        msg = email.message_from_string(m)
    32193241        param = msg.get_param('name')
    3220         self.failIf(isinstance(param, tuple))
     3242        self.assertFalse(isinstance(param, tuple))
    32213243        self.assertEqual(param, "Frank's Document")
    32223244
     
    32423264        msg = email.message_from_string(m)
    32433265        param = msg.get_param('name')
    3244         self.failIf(isinstance(param, tuple))
     3266        self.assertFalse(isinstance(param, tuple))
    32453267        self.assertEqual(param, "us-ascii'en-us'Frank's Document")
    32463268
     
    32863308
    32873309
    3288 
    32893310def _testclasses():
    32903311    mod = sys.modules[__name__]
     
    33053326
    33063327
    3307 
    33083328if __name__ == '__main__':
    33093329    unittest.main(defaultTest='suite')
  • python/vendor/current/Lib/email/utils.py

    r2 r388  
    1 # Copyright (C) 2001-2009 Python Software Foundation
     1# Copyright (C) 2001-2010 Python Software Foundation
    22# Author: Barry Warsaw
    33# Contact: email-sig@python.org
     
    6262
    6363def _bdecode(s):
    64     # We can't quite use base64.encodestring() since it tacks on a "courtesy
    65     # newline".  Blech!
     64    """Decodes a base64 string.
     65
     66    This function is equivalent to base64.decodestring and it's retained only
     67    for backward compatibility. It used to remove the last \\n of the decoded
     68    string, if it had any (see issue 7143).
     69    """
    6670    if not s:
    6771        return s
    68     value = base64.decodestring(s)
    69     if not s.endswith('\n') and value.endswith('\n'):
    70         return value[:-1]
    71     return value
     72    return base64.decodestring(s)
    7273
    7374
     
    7576
    7677def fix_eols(s):
    77     """Replace all line-ending characters with \r\n."""
     78    """Replace all line-ending characters with \\r\\n."""
    7879    # Fix newlines with no preceding carriage return
    7980    s = re.sub(r'(?<!\r)\n', CRLF, s)
Note: See TracChangeset for help on using the changeset viewer.