Changeset 388 for python/vendor/current/Lib/email
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- Location:
- python/vendor/current/Lib/email
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/email/__init__.py
r2 r388 5 5 """A package for parsing, handling, and generating email messages.""" 6 6 7 __version__ = '4.0. 1'7 __version__ = '4.0.3' 8 8 9 9 __all__ = [ -
python/vendor/current/Lib/email/_parseaddr.py
r2 r388 14 14 ] 15 15 16 import time 16 import time, calendar 17 17 18 18 SPACE = ' ' … … 108 108 except ValueError: 109 109 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 110 122 tzoffset = None 111 123 tz = tz.upper() … … 139 151 140 152 def mktime_tz(data): 141 """Turn a 10-tuple as returned by parsedate_tz() into a UTCtimestamp."""153 """Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.""" 142 154 if data[9] is None: 143 155 # No zone info, so localtime is better assumption than GMT 144 156 return time.mktime(data[:8] + (-1,)) 145 157 else: 146 t = time.mktime(data[:8] + (0,))147 return t - data[9] - time.timezone158 t = calendar.timegm(data) 159 return t - data[9] 148 160 149 161 150 162 def 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 """ 152 169 return str.replace('\\', '\\\\').replace('"', '\\"') 153 170 … … 307 324 self.pos += 1 308 325 elif self.field[self.pos] == '"': 309 aslist.append('"%s"' % self.getquote())326 aslist.append('"%s"' % quote(self.getquote())) 310 327 elif self.field[self.pos] in self.atomends: 311 328 break -
python/vendor/current/Lib/email/base64mime.py
r2 r388 134 134 135 135 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 directly136 this to "\\r\\n" if you will be using the result of this function directly 137 137 in an email. 138 138 """ -
python/vendor/current/Lib/email/charset.py
r2 r388 10 10 ] 11 11 12 import codecs 12 13 import email.base64mime 13 14 import email.quoprimime … … 187 188 body_encoding. 188 189 189 output_charset: Some character sets must be converted before the can be190 output_charset: Some character sets must be converted before they can be 190 191 used in email headers or bodies. If the input_charset is 191 192 one of them, this attribute will contain the name of the … … 213 214 except UnicodeError: 214 215 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 217 223 self.input_charset = ALIASES.get(input_charset, input_charset) 218 224 # We can try to guess which encoding and conversion to use by the -
python/vendor/current/Lib/email/encoders.py
r2 r388 77 77 orig.encode('ascii') 78 78 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' 86 80 else: 87 81 msg['Content-Transfer-Encoding'] = '7bit' -
python/vendor/current/Lib/email/feedparser.py
r2 r388 14 14 This completes the parsing and returns the root message object. 15 15 16 The other advantage of this parser is that it will never throwa parsing16 The other advantage of this parser is that it will never raise a parsing 17 17 exception. Instead, when it finds something unexpected, it adds a 'defect' to 18 18 the current message. Defects are just instances that live on the message … … 29 29 NLCRE = re.compile('\r\n|\r|\n') 30 30 NLCRE_bol = re.compile('(\r\n|\r|\n)') 31 NLCRE_eol = re.compile('(\r\n|\r|\n) $')31 NLCRE_eol = re.compile('(\r\n|\r|\n)\Z') 32 32 NLCRE_crack = re.compile('(\r\n|\r|\n)') 33 33 # RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character … … 106 106 # this is the empty string. 107 107 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() 108 112 # parts is a list of strings, alternating between the line contents 109 113 # and the eol character(s). Gather up a list of lines after … … 213 217 self._parse_headers(headers) 214 218 # Headers-only parsing is a backwards compatibility hack, which was 215 # necessary in the older parser, which could throwerrors. All219 # necessary in the older parser, which could raise errors. All 216 220 # remaining lines in the input are thrown into the message body. 217 221 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 3 2 # Contact: email-sig@python.org 4 3 … … 158 157 print >> self._fp, v 159 158 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. 161 164 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() 164 166 # A blank line always separates headers from body 165 167 print >> self._fp … … 202 204 g.flatten(part, unixfrom=False) 203 205 msgtexts.append(s.getvalue()) 204 # Now make sure the boundary we've selected doesn't appear in any of205 # the message texts.206 alltext = NL.join(msgtexts)207 206 # 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) 216 213 msg.set_boundary(boundary) 217 214 # If there's a preamble, write it out, with a trailing CRLF 218 215 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 220 221 # dash-boundary transport-padding CRLF 221 222 print >> self._fp, '--' + boundary … … 235 236 if msg.epilogue is not None: 236 237 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) 238 243 239 244 def _handle_multipart_signed(self, msg): … … 293 298 294 299 class DecodedGenerator(Generator): 295 """Generat ora text representation of a message.300 """Generates a text representation of a message. 296 301 297 302 Like the Generator base class, except that non-text parts are substituted -
python/vendor/current/Lib/email/header.py
r2 r388 47 47 # For use with .match() 48 48 fcre = 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]+:') 49 53 50 54 … … 95 99 dec = email.quoprimime.header_decode(encoded) 96 100 elif encoding == 'b': 101 paderr = len(encoded) % 4 # Postel's law: add missing padding 102 if paderr: 103 encoded += '==='[:4 - paderr] 97 104 try: 98 105 dec = email.base64mime.decode(encoded) … … 405 412 lastchunk, lastcharset = newchunks[-1] 406 413 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 408 419 409 420 -
python/vendor/current/Lib/email/message.py
r2 r388 40 40 """Convenience function to format and return a key=value pair. 41 41 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. 43 45 """ 44 46 if value is not None and len(value) > 0: … … 64 66 s = s[1:] 65 67 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: 67 69 end = s.find(';', end + 1) 68 70 if end < 0: … … 100 102 101 103 Message objects implement part of the `mapping' interface, which assumes 102 there is exactly one occurr ance of the header per message. Some headers104 there is exactly one occurrence of the header per message. Some headers 103 105 do in fact appear multiple times (e.g. Received) and for those headers, 104 106 you must use the explicit API to set or get all the headers. Not all of … … 252 254 # Charset constructor? 253 255 self._charset = charset 254 if not self.has_key('MIME-Version'):256 if 'MIME-Version' not in self: 255 257 self.add_header('MIME-Version', '1.0') 256 if not self.has_key('Content-Type'):258 if 'Content-Type' not in self: 257 259 self.add_header('Content-Type', 'text/plain', 258 260 charset=charset.get_output_charset()) 259 261 else: 260 262 self.set_param('charset', charset.get_output_charset()) 263 if isinstance(self._payload, unicode): 264 self._payload = self._payload.encode(charset.output_charset) 261 265 if str(charset) != charset.get_output_charset(): 262 266 self._payload = charset.body_encode(self._payload) 263 if not self.has_key('Content-Transfer-Encoding'):267 if 'Content-Transfer-Encoding' not in self: 264 268 cte = charset.get_body_encoding() 265 269 try: … … 287 291 288 292 Note that if the header appeared multiple times, exactly which 289 occurr ance gets returned is undefined. Use get_all() to get all293 occurrence gets returned is undefined. Use get_all() to get all 290 294 the values matching a header field name. 291 295 """ … … 390 394 additional parameters for the header field, with underscores converted 391 395 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. 393 400 394 401 Example: … … 554 561 to False. 555 562 """ 556 if not self.has_key(header):563 if header not in self: 557 564 return failobj 558 565 for k, v in self._get_params_preserve(failobj, header): … … 585 592 value = (charset, language, value) 586 593 587 if not self.has_key(header)and header.lower() == 'content-type':594 if header not in self and header.lower() == 'content-type': 588 595 ctype = 'text/plain' 589 596 else: … … 620 627 header. 621 628 """ 622 if not self.has_key(header):629 if header not in self: 623 630 return 624 631 new_ctype = '' … … 656 663 del self['mime-version'] 657 664 self['MIME-Version'] = '1.0' 658 if not self.has_key(header):665 if header not in self: 659 666 self[header] = type 660 667 return -
python/vendor/current/Lib/email/mime/application.py
r2 r388 18 18 """Create an application/* type MIME document. 19 19 20 _data is a string containing the raw applicat oin data.20 _data is a string containing the raw application data. 21 21 22 22 _subtype is the MIME content type subtype, defaulting to -
python/vendor/current/Lib/email/mime/nonmultipart.py
r2 r388 16 16 """Base class for MIME multipart/* type messages.""" 17 17 18 __pychecker__ = 'unusednames=payload'19 20 18 def attach(self, payload): 21 19 # The public API prohibits attaching multiple subparts to MIMEBase … … 24 22 raise errors.MultipartConversionError( 25 23 'Cannot attach additional subparts to non-multipart/*') 26 27 del __pychecker__ -
python/vendor/current/Lib/email/quoprimime.py
r2 r388 339 339 """ 340 340 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 27 27 --BOUNDARY 28 28 Content-Type: text/plain; charset="iso-8859-1" 29 Content-Transfer-Encoding: Base64 30 31 VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UuCg== 32 33 34 --BOUNDARY 35 Content-Type: text/plain; charset="iso-8859-1" 29 36 30 37 This has no Content-Transfer-Encoding: header. -
python/vendor/current/Lib/email/test/test_email.py
r2 r388 1 # Copyright (C) 2001-20 07Python Software Foundation1 # Copyright (C) 2001-2010 Python Software Foundation 2 2 # Contact: email-sig@python.org 3 3 # email package unit tests … … 10 10 import unittest 11 11 import warnings 12 import textwrap 12 13 from cStringIO import StringIO 13 14 … … 42 43 43 44 44 45 45 def openfile(filename, mode='r'): 46 46 path = os.path.join(os.path.dirname(landmark), 'data', filename) … … 49 49 50 50 51 52 51 # Base test class 53 52 class TestEmailBase(unittest.TestCase): 54 53 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: 57 56 sfirst = str(first) 58 57 ssecond = str(second) … … 69 68 fp.close() 70 69 return msg 71 72 70 73 71 … … 183 181 msg.set_boundary, 'BOUNDARY') 184 182 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 185 194 def test_message_rfc822_only(self): 186 195 # Issue 7970: message/rfc822 not in multipart parsed by … … 209 218 eq(msg.get_payload(2).get_payload(decode=True), 210 219 '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). 212 222 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), 213 226 'This has no Content-Transfer-Encoding: header.\n') 214 227 … … 255 268 msg['to'] = 'You' 256 269 # 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) 263 276 264 277 def test_as_string(self): … … 267 280 fp = openfile('msg_01.txt') 268 281 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', ' ') 270 292 finally: 271 293 fp.close() … … 273 295 fullrepr = str(msg) 274 296 lines = fullrepr.split('\n') 275 self. failUnless(lines[0].startswith('From '))297 self.assertTrue(lines[0].startswith('From ')) 276 298 eq(text, NL.join(lines[1:])) 277 299 … … 342 364 '"Jim&&Jill"') 343 365 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 344 374 def test_has_key(self): 345 375 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')) 350 380 351 381 def test_set_param(self): … … 525 555 self.assertEqual('us-ascii', msg.get_content_charset()) 526 556 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) 528 568 529 569 … … 538 578 def test_default_cte(self): 539 579 eq = self.assertEqual 580 # 7bit data and the default us-ascii _charset 540 581 msg = MIMEText('hello world') 541 582 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 549 584 msg = MIMEText('hello \xf8 world') 550 585 eq(msg['content-transfer-encoding'], '8bit') … … 553 588 eq(msg['content-transfer-encoding'], 'quoted-printable') 554 589 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') 556 597 557 598 … … 572 613 eq(sfp.getvalue(), """\ 573 614 Subject: bug demonstration 574 \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789575 \tmore text615 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 616 more text 576 617 577 618 test … … 673 714 Content-Transfer-Encoding: 7bit 674 715 X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals"; 675 \tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"716 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey" 676 717 677 718 ''') … … 689 730 From: test@dom.ain 690 731 References: <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> 692 733 693 734 Test""") … … 767 808 eq(msg.as_string(0), '''\ 768 809 To: "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> 772 813 773 814 ''') … … 812 853 \tWed, 05 Mar 2003 18:10:18 -0700 813 854 Received-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 -0700855 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP; 856 Wed, 05 Mar 2003 18:10:18 -0700 816 857 817 858 """) … … 820 861 h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")' 821 862 msg = Message() 822 msg['Received -1'] = Header(h, header_name='Received-1',823 824 msg['Received -2'] = h825 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(), """\ 867 Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> 827 868 \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")869 Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> 870 (David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100") 830 871 831 872 """) … … 841 882 eq(msg.as_string(), """\ 842 883 Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9 843 \tlocQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp884 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp 844 885 Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9 845 886 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp … … 851 892 m = '''\ 852 893 Received: 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''' 854 895 msg = email.message_from_string(m) 855 896 eq(msg.as_string(), '''\ 856 897 Received: 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 -0700898 Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700 858 899 859 900 ''') … … 869 910 eq(msg.as_string(), """\ 870 911 List: 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> 872 913 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>, 873 914 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe> 874 915 875 916 """) 876 877 917 878 918 … … 910 950 """) 911 951 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) 913 974 914 975 … … 942 1003 def test_add_header(self): 943 1004 eq = self.assertEqual 944 unless = self. failUnless1005 unless = self.assertTrue 945 1006 self._au.add_header('Content-Disposition', 'attachment', 946 1007 filename='audiotest.au') … … 962 1023 963 1024 964 965 1025 # Test the basic MIMEImage class 966 1026 class TestMIMEImage(unittest.TestCase): … … 986 1046 def test_add_header(self): 987 1047 eq = self.assertEqual 988 unless = self. failUnless1048 unless = self.assertTrue 989 1049 self._im.add_header('Content-Disposition', 'attachment', 990 1050 filename='dingusfish.gif') … … 1006 1066 1007 1067 1008 1009 1068 # Test the basic MIMEText class 1010 1069 class TestMIMEText(unittest.TestCase): … … 1014 1073 def test_types(self): 1015 1074 eq = self.assertEqual 1016 unless = self. failUnless1075 unless = self.assertTrue 1017 1076 eq(self._msg.get_content_type(), 'text/plain') 1018 1077 eq(self._msg.get_param('charset'), 'us-ascii') … … 1024 1083 def test_payload(self): 1025 1084 self.assertEqual(self._msg.get_payload(), 'hello there') 1026 self. failUnless(not self._msg.is_multipart())1085 self.assertTrue(not self._msg.is_multipart()) 1027 1086 1028 1087 def test_charset(self): … … 1032 1091 eq(msg['content-type'], 'text/plain; charset="us-ascii"') 1033 1092 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) 1034 1117 1035 1118 … … 1069 1152 else: 1070 1153 sign = '+' 1071 tzoffset = ' %s%04d' % (sign, tzsecs / 36)1154 tzoffset = ' %s%04d' % (sign, tzsecs // 36) 1072 1155 container['Date'] = time.strftime( 1073 1156 '%a, %d %b %Y %H:%M:%S', … … 1080 1163 # convenience 1081 1164 eq = self.assertEqual 1082 unless = self. failUnless1165 unless = self.assertTrue 1083 1166 raises = self.assertRaises 1084 1167 # tests … … 1394 1477 -- XXXX-- 1395 1478 ''') 1396 self. failUnless(msg.is_multipart())1479 self.assertTrue(msg.is_multipart()) 1397 1480 eq(msg.get_boundary(), ' XXXX') 1398 1481 eq(len(msg.get_payload()), 2) … … 1410 1493 YXNkZg== 1411 1494 --===============0012394164==--""") 1412 self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==') 1413 1495 self.assertEqual(m.get_payload(0).get_payload(), 'YXNkZg==') 1414 1496 1415 1497 … … 1425 1507 1426 1508 def test_same_boundary_inner_outer(self): 1427 unless = self. failUnless1509 unless = self.assertTrue 1428 1510 msg = self._msgobj('msg_15.txt') 1429 1511 # XXX We can probably eventually do better … … 1435 1517 1436 1518 def test_multipart_no_boundary(self): 1437 unless = self. failUnless1519 unless = self.assertTrue 1438 1520 msg = self._msgobj('msg_25.txt') 1439 1521 unless(isinstance(msg.get_payload(), str)) … … 1493 1575 1494 1576 def test_lying_multipart(self): 1495 unless = self. failUnless1577 unless = self.assertTrue 1496 1578 msg = self._msgobj('msg_41.txt') 1497 1579 unless(hasattr(msg, 'defects')) … … 1513 1595 bad = outer.get_payload(1).get_payload(0) 1514 1596 self.assertEqual(len(bad.defects), 1) 1515 self. failUnless(isinstance(bad.defects[0],1597 self.assertTrue(isinstance(bad.defects[0], 1516 1598 Errors.StartBoundaryNotFoundDefect)) 1517 1599 … … 1523 1605 eq(msg.get_payload(), 'Line 2\nLine 3') 1524 1606 eq(len(msg.defects), 1) 1525 self. failUnless(isinstance(msg.defects[0],1607 self.assertTrue(isinstance(msg.defects[0], 1526 1608 Errors.FirstHeaderLineIsContinuationDefect)) 1527 1609 eq(msg.defects[0].line, ' Line 1\n') 1528 1529 1610 1530 1611 … … 1576 1657 ('sbord', None)]) 1577 1658 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')]) 1579 1674 1580 1675 … … 1593 1688 def test_valid_argument(self): 1594 1689 eq = self.assertEqual 1595 unless = self. failUnless1690 unless = self.assertTrue 1596 1691 subject = 'A sub-message' 1597 1692 m = Message() … … 1637 1732 def test_parse_message_rfc822(self): 1638 1733 eq = self.assertEqual 1639 unless = self. failUnless1734 unless = self.assertTrue 1640 1735 msg = self._msgobj('msg_11.txt') 1641 1736 eq(msg.get_content_type(), 'message/rfc822') … … 1644 1739 eq(len(payload), 1) 1645 1740 submsg = payload[0] 1646 self. failUnless(isinstance(submsg, Message))1741 self.assertTrue(isinstance(submsg, Message)) 1647 1742 eq(submsg['subject'], 'An enclosed message') 1648 1743 eq(submsg.get_payload(), 'Here is the body of the message.\n') … … 1650 1745 def test_dsn(self): 1651 1746 eq = self.assertEqual 1652 unless = self. failUnless1747 unless = self.assertTrue 1653 1748 # msg 16 is a Delivery Status Notification, see RFC 1894 1654 1749 msg = self._msgobj('msg_16.txt') … … 1892 1987 1893 1988 1894 1895 1989 # A general test of parser->model->generator idempotency. IOW, read a message 1896 1990 # in, parse it into a message object tree, then without touching the tree, … … 1916 2010 1917 2011 def test_parse_text_message(self): 1918 eq = self.assertEqual s2012 eq = self.assertEqual 1919 2013 msg, text = self._msgobj('msg_01.txt') 1920 2014 eq(msg.get_content_type(), 'text/plain') … … 1928 2022 1929 2023 def test_parse_untyped_message(self): 1930 eq = self.assertEqual s2024 eq = self.assertEqual 1931 2025 msg, text = self._msgobj('msg_03.txt') 1932 2026 eq(msg.get_content_type(), 'text/plain') … … 2000 2094 2001 2095 def test_content_type(self): 2002 eq = self.assertEqual s2003 unless = self. failUnless2096 eq = self.assertEqual 2097 unless = self.assertTrue 2004 2098 # Get a message object and reset the seek pointer for other tests 2005 2099 msg, text = self._msgobj('msg_05.txt') … … 2023 2117 msg3 = msg.get_payload(2) 2024 2118 eq(msg3.get_content_type(), 'message/rfc822') 2025 self. failUnless(isinstance(msg3, Message))2119 self.assertTrue(isinstance(msg3, Message)) 2026 2120 payload = msg3.get_payload() 2027 2121 unless(isinstance(payload, list)) … … 2032 2126 2033 2127 def test_parser(self): 2034 eq = self.assertEqual s2035 unless = self. failUnless2128 eq = self.assertEqual 2129 unless = self.assertTrue 2036 2130 msg, text = self._msgobj('msg_06.txt') 2037 2131 # Check some of the outer headers … … 2043 2137 eq(len(payload), 1) 2044 2138 msg1 = payload[0] 2045 self. failUnless(isinstance(msg1, Message))2139 self.assertTrue(isinstance(msg1, Message)) 2046 2140 eq(msg1.get_content_type(), 'text/plain') 2047 self. failUnless(isinstance(msg1.get_payload(), str))2141 self.assertTrue(isinstance(msg1.get_payload(), str)) 2048 2142 eq(msg1.get_payload(), '\n') 2049 2050 2143 2051 2144 … … 2083 2176 2084 2177 def test_message_from_string_with_class(self): 2085 unless = self. failUnless2178 unless = self.assertTrue 2086 2179 fp = openfile('msg_01.txt') 2087 2180 try: … … 2106 2199 2107 2200 def test_message_from_file_with_class(self): 2108 unless = self. failUnless2201 unless = self.assertTrue 2109 2202 # Create a subclass 2110 2203 class MyMessage(Message): … … 2193 2286 eq(int(time.strftime('%Y', timetup[:9])), 2003) 2194 2287 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 2195 2307 def test_parseaddr_empty(self): 2196 2308 self.assertEqual(Utils.parseaddr('<>'), ('', '')) … … 2227 2339 self.assertEqual(Utils.formataddr((a, b)), y) 2228 2340 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 2229 2359 def test_multiline_from_comment(self): 2230 2360 x = """\ … … 2248 2378 def test_charset_richcomparisons(self): 2249 2379 eq = self.assertEqual 2250 ne = self. failIfEqual2380 ne = self.assertNotEqual 2251 2381 cset1 = Charset() 2252 2382 cset2 = Charset() … … 2375 2505 2376 2506 2377 2378 2507 # Test the iterator/generators 2379 2508 class TestIterators(TestEmailBase): … … 2434 2563 """) 2435 2564 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)) 2436 2597 2437 2598 … … 2449 2610 eq(msg['to'], 'ppp@zzz.org') 2450 2611 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)) 2453 2614 2454 2615 def test_whitespace_continuation(self): … … 2580 2741 eq(msg.get_payload(), 'body') 2581 2742 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')) 2583 2761 2584 2762 … … 2655 2833 2656 2834 2657 2658 2835 class TestQuopri(unittest.TestCase): 2659 2836 def setUp(self): … … 2671 2848 def test_header_quopri_check(self): 2672 2849 for c in self.hlit: 2673 self. failIf(quopriMIME.header_quopri_check(c))2850 self.assertFalse(quopriMIME.header_quopri_check(c)) 2674 2851 for c in self.hnon: 2675 self. failUnless(quopriMIME.header_quopri_check(c))2852 self.assertTrue(quopriMIME.header_quopri_check(c)) 2676 2853 2677 2854 def test_body_quopri_check(self): 2678 2855 for c in self.blit: 2679 self. failIf(quopriMIME.body_quopri_check(c))2856 self.assertFalse(quopriMIME.body_quopri_check(c)) 2680 2857 for c in self.bnon: 2681 self. failUnless(quopriMIME.body_quopri_check(c))2858 self.assertTrue(quopriMIME.body_quopri_check(c)) 2682 2859 2683 2860 def test_header_quopri_len(self): … … 2766 2943 2767 2944 2768 2769 2945 # Test the Charset class 2770 2946 class TestCharset(unittest.TestCase): … … 2799 2975 c = Charset('us-ascii') 2800 2976 eq('hello world', c.body_encode('hello world')) 2801 # Try the convert argument, where input codec <>output codec2977 # Try the convert argument, where input codec != output codec 2802 2978 c = Charset('euc-jp') 2803 2979 # With apologies to Tokio Kikuchi ;) … … 2823 2999 self.assertRaises(Errors.CharsetError, Charset, 'asc\xffii') 2824 3000 2825 3001 def test_codecs_aliases_accepted(self): 3002 charset = Charset('utf8') 3003 self.assertEqual(str(charset), 'utf-8') 2826 3004 2827 3005 … … 2850 3028 maxlinelen=76) 2851 3029 for l in h.encode(splitchars=' ').split('\n '): 2852 self. failUnless(len(l) <= 76)3030 self.assertTrue(len(l) <= 76) 2853 3031 2854 3032 def test_multilingual(self): … … 2984 3162 def test_broken_base64_header(self): 2985 3163 raises = self.assertRaises 2986 s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I Q?='3164 s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=' 2987 3165 raises(Errors.HeaderParseError, decode_header, s) 2988 3166 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) 2990 3189 2991 3190 … … 3014 3213 msg.set_param('title', 'This is even more ***fun*** isn\'t it!', 3015 3214 charset='us-ascii', language='en') 3016 eq(msg.as_string(), """\3215 self.ndiffAssertEqual(msg.as_string(), """\ 3017 3216 Return-Path: <bbb@zzz.org> 3018 3217 Delivered-To: bbb@zzz.org 3019 3218 Received: 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) 3021 3220 MIME-Version: 1.0 3022 3221 Content-Transfer-Encoding: 7bit … … 3027 3226 Date: Fri, 4 May 2001 14:05:44 -0400 3028 3227 Content-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" 3030 3229 3031 3230 … … 3048 3247 Delivered-To: bbb@zzz.org 3049 3248 Received: 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) 3051 3250 MIME-Version: 1.0 3052 3251 Content-Transfer-Encoding: 7bit … … 3057 3256 Date: Fri, 4 May 2001 14:05:44 -0400 3058 3257 Content-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" 3060 3259 3061 3260 … … 3081 3280 msg = email.message_from_string(m) 3082 3281 param = msg.get_param('NAME') 3083 self. failIf(isinstance(param, tuple))3282 self.assertFalse(isinstance(param, tuple)) 3084 3283 self.assertEqual( 3085 3284 param, … … 3234 3433 msg = email.message_from_string(m) 3235 3434 param = msg.get_param('name') 3236 self. failIf(isinstance(param, tuple))3435 self.assertFalse(isinstance(param, tuple)) 3237 3436 self.assertEqual(param, "Frank's Document") 3238 3437 … … 3258 3457 msg = email.message_from_string(m) 3259 3458 param = msg.get_param('name') 3260 self. failIf(isinstance(param, tuple))3459 self.assertFalse(isinstance(param, tuple)) 3261 3460 self.assertEqual(param, "us-ascii'en-us'Frank's Document") 3262 3461 … … 3299 3498 eq(language, 'en-us') 3300 3499 eq(s, 'My Document For You') 3301 3302 3500 3303 3501 … … 3339 3537 3340 3538 3341 3342 3539 def _testclasses(): 3343 3540 mod = sys.modules[__name__] … … 3358 3555 3359 3556 3360 3361 3557 if __name__ == '__main__': 3362 3558 unittest.main(defaultTest='suite') -
python/vendor/current/Lib/email/test/test_email_codecs.py
r2 r388 4 4 5 5 import unittest 6 from test.test_support import TestSkipped,run_unittest6 from test.test_support import run_unittest 7 7 8 8 from email.test.test_email import TestEmailBase … … 16 16 unicode('foo', 'euc-jp') 17 17 except LookupError: 18 raise TestSkipped18 raise unittest.SkipTest 19 19 20 20 -
python/vendor/current/Lib/email/test/test_email_codecs_renamed.py
r2 r388 4 4 5 5 import unittest 6 from test.test_support import TestSkipped,run_unittest6 from test.test_support import run_unittest 7 7 8 8 from email.test.test_email import TestEmailBase … … 16 16 unicode('foo', 'euc-jp') 17 17 except LookupError: 18 raise TestSkipped18 raise unittest.SkipTest 19 19 20 20 -
python/vendor/current/Lib/email/test/test_email_renamed.py
r2 r388 43 43 44 44 45 46 45 def openfile(filename, mode='r'): 47 46 path = os.path.join(os.path.dirname(landmark), 'data', filename) … … 50 49 51 50 52 53 51 # Base test class 54 52 class TestEmailBase(unittest.TestCase): 55 53 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: 58 56 sfirst = str(first) 59 57 ssecond = str(second) … … 70 68 fp.close() 71 69 return msg 72 73 70 74 71 … … 198 195 eq(msg.get_payload(2).get_payload(decode=True), 199 196 '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). 201 199 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), 202 203 'This has no Content-Transfer-Encoding: header.\n') 203 204 … … 231 232 msg['to'] = 'You' 232 233 # 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) 239 240 240 241 def test_as_string(self): … … 243 244 fp = openfile('msg_01.txt') 244 245 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', ' ') 246 256 finally: 247 257 fp.close() 248 eq(text, msg.as_string())258 self.ndiffAssertEqual(text, msg.as_string()) 249 259 fullrepr = str(msg) 250 260 lines = fullrepr.split('\n') 251 self. failUnless(lines[0].startswith('From '))261 self.assertTrue(lines[0].startswith('From ')) 252 262 eq(text, NL.join(lines[1:])) 253 263 … … 320 330 def test_has_key(self): 321 331 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')) 326 336 327 337 def test_set_param(self): … … 496 506 497 507 498 499 508 # Test the email.encoders module 500 509 class TestEncoders(unittest.TestCase): … … 524 533 525 534 526 527 535 # Test long header wrapping 528 536 class TestLongHeaders(TestEmailBase): … … 541 549 eq(sfp.getvalue(), """\ 542 550 Subject: bug demonstration 543 \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789544 \tmore text551 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 552 more text 545 553 546 554 test … … 642 650 Content-Transfer-Encoding: 7bit 643 651 X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals"; 644 \tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"652 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey" 645 653 646 654 ''') … … 658 666 From: test@dom.ain 659 667 References: <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> 661 669 662 670 Test""") … … 736 744 eq(msg.as_string(0), '''\ 737 745 To: "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> 741 749 742 750 ''') … … 776 784 msg['Received-1'] = Header(h, continuation_ws='\t') 777 785 msg['Received-2'] = h 778 self. assertEqual(msg.as_string(), """\786 self.ndiffAssertEqual(msg.as_string(), """\ 779 787 Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by 780 788 \throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP; 781 789 \tWed, 05 Mar 2003 18:10:18 -0700 782 790 Received-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 -0700791 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP; 792 Wed, 05 Mar 2003 18:10:18 -0700 785 793 786 794 """) … … 789 797 h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")' 790 798 msg = Message() 791 msg['Received -1'] = Header(h, header_name='Received-1',792 793 msg['Received -2'] = h794 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(), """\ 803 Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> 796 804 \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")805 Received: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> 806 (David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100") 799 807 800 808 """) … … 810 818 eq(msg.as_string(), """\ 811 819 Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9 812 \tlocQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp820 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp 813 821 Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9 814 822 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp … … 820 828 m = '''\ 821 829 Received: 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''' 823 831 msg = email.message_from_string(m) 824 832 eq(msg.as_string(), '''\ 825 833 Received: 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 -0700834 Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700 827 835 828 836 ''') … … 836 844 msg['List'] = h 837 845 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(), """\ 841 847 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>, 842 848 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe> 849 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>, 850 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe> 843 851 844 852 """) 845 846 853 847 854 … … 878 885 Blah blah blah 879 886 """) 880 881 887 882 888 … … 911 917 def test_add_header(self): 912 918 eq = self.assertEqual 913 unless = self. failUnless919 unless = self.assertTrue 914 920 self._au.add_header('Content-Disposition', 'attachment', 915 921 filename='audiotest.au') … … 931 937 932 938 933 934 939 # Test the basic MIMEImage class 935 940 class TestMIMEImage(unittest.TestCase): … … 955 960 def test_add_header(self): 956 961 eq = self.assertEqual 957 unless = self. failUnless962 unless = self.assertTrue 958 963 self._im.add_header('Content-Disposition', 'attachment', 959 964 filename='dingusfish.gif') … … 975 980 976 981 977 978 982 # Test the basic MIMEApplication class 979 983 class TestMIMEApplication(unittest.TestCase): … … 991 995 eq(msg.get_payload(decode=True), bytes) 992 996 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) 994 1029 995 1030 … … 1001 1036 def test_types(self): 1002 1037 eq = self.assertEqual 1003 unless = self. failUnless1038 unless = self.assertTrue 1004 1039 eq(self._msg.get_content_type(), 'text/plain') 1005 1040 eq(self._msg.get_param('charset'), 'us-ascii') … … 1011 1046 def test_payload(self): 1012 1047 self.assertEqual(self._msg.get_payload(), 'hello there') 1013 self. failUnless(not self._msg.is_multipart())1048 self.assertTrue(not self._msg.is_multipart()) 1014 1049 1015 1050 def test_charset(self): … … 1018 1053 eq(msg.get_charset().input_charset, 'us-ascii') 1019 1054 eq(msg['content-type'], 'text/plain; charset="us-ascii"') 1020 1021 1055 1022 1056 … … 1056 1090 else: 1057 1091 sign = '+' 1058 tzoffset = ' %s%04d' % (sign, tzsecs / 36)1092 tzoffset = ' %s%04d' % (sign, tzsecs // 36) 1059 1093 container['Date'] = time.strftime( 1060 1094 '%a, %d %b %Y %H:%M:%S', … … 1067 1101 # convenience 1068 1102 eq = self.assertEqual 1069 unless = self. failUnless1103 unless = self.assertTrue 1070 1104 raises = self.assertRaises 1071 1105 # tests … … 1381 1415 -- XXXX-- 1382 1416 ''') 1383 self. failUnless(msg.is_multipart())1417 self.assertTrue(msg.is_multipart()) 1384 1418 eq(msg.get_boundary(), ' XXXX') 1385 1419 eq(len(msg.get_payload()), 2) … … 1397 1431 YXNkZg== 1398 1432 --===============0012394164==--""") 1399 self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==') 1400 1433 self.assertEqual(m.get_payload(0).get_payload(), 'YXNkZg==') 1401 1434 1402 1435 … … 1412 1445 1413 1446 def test_same_boundary_inner_outer(self): 1414 unless = self. failUnless1447 unless = self.assertTrue 1415 1448 msg = self._msgobj('msg_15.txt') 1416 1449 # XXX We can probably eventually do better … … 1422 1455 1423 1456 def test_multipart_no_boundary(self): 1424 unless = self. failUnless1457 unless = self.assertTrue 1425 1458 msg = self._msgobj('msg_25.txt') 1426 1459 unless(isinstance(msg.get_payload(), str)) … … 1480 1513 1481 1514 def test_lying_multipart(self): 1482 unless = self. failUnless1515 unless = self.assertTrue 1483 1516 msg = self._msgobj('msg_41.txt') 1484 1517 unless(hasattr(msg, 'defects')) … … 1500 1533 bad = outer.get_payload(1).get_payload(0) 1501 1534 self.assertEqual(len(bad.defects), 1) 1502 self. failUnless(isinstance(bad.defects[0],1535 self.assertTrue(isinstance(bad.defects[0], 1503 1536 errors.StartBoundaryNotFoundDefect)) 1504 1537 … … 1510 1543 eq(msg.get_payload(), 'Line 2\nLine 3') 1511 1544 eq(len(msg.defects), 1) 1512 self. failUnless(isinstance(msg.defects[0],1545 self.assertTrue(isinstance(msg.defects[0], 1513 1546 errors.FirstHeaderLineIsContinuationDefect)) 1514 1547 eq(msg.defects[0].line, ' Line 1\n') 1515 1516 1548 1517 1549 … … 1564 1596 1565 1597 1566 1567 1598 # Test the MIMEMessage class 1568 1599 class TestMIMEMessage(TestEmailBase): … … 1579 1610 def test_valid_argument(self): 1580 1611 eq = self.assertEqual 1581 unless = self. failUnless1612 unless = self.assertTrue 1582 1613 subject = 'A sub-message' 1583 1614 m = Message() … … 1623 1654 def test_parse_message_rfc822(self): 1624 1655 eq = self.assertEqual 1625 unless = self. failUnless1656 unless = self.assertTrue 1626 1657 msg = self._msgobj('msg_11.txt') 1627 1658 eq(msg.get_content_type(), 'message/rfc822') … … 1630 1661 eq(len(payload), 1) 1631 1662 submsg = payload[0] 1632 self. failUnless(isinstance(submsg, Message))1663 self.assertTrue(isinstance(submsg, Message)) 1633 1664 eq(submsg['subject'], 'An enclosed message') 1634 1665 eq(submsg.get_payload(), 'Here is the body of the message.\n') … … 1636 1667 def test_dsn(self): 1637 1668 eq = self.assertEqual 1638 unless = self. failUnless1669 unless = self.assertTrue 1639 1670 # msg 16 is a Delivery Status Notification, see RFC 1894 1640 1671 msg = self._msgobj('msg_16.txt') … … 1875 1906 1876 1907 1877 1878 1908 # A general test of parser->model->generator idempotency. IOW, read a message 1879 1909 # in, parse it into a message object tree, then without touching the tree, … … 1899 1929 1900 1930 def test_parse_text_message(self): 1901 eq = self.assertEqual s1931 eq = self.assertEqual 1902 1932 msg, text = self._msgobj('msg_01.txt') 1903 1933 eq(msg.get_content_type(), 'text/plain') … … 1911 1941 1912 1942 def test_parse_untyped_message(self): 1913 eq = self.assertEqual s1943 eq = self.assertEqual 1914 1944 msg, text = self._msgobj('msg_03.txt') 1915 1945 eq(msg.get_content_type(), 'text/plain') … … 1983 2013 1984 2014 def test_content_type(self): 1985 eq = self.assertEqual s1986 unless = self. failUnless2015 eq = self.assertEqual 2016 unless = self.assertTrue 1987 2017 # Get a message object and reset the seek pointer for other tests 1988 2018 msg, text = self._msgobj('msg_05.txt') … … 2006 2036 msg3 = msg.get_payload(2) 2007 2037 eq(msg3.get_content_type(), 'message/rfc822') 2008 self. failUnless(isinstance(msg3, Message))2038 self.assertTrue(isinstance(msg3, Message)) 2009 2039 payload = msg3.get_payload() 2010 2040 unless(isinstance(payload, list)) … … 2015 2045 2016 2046 def test_parser(self): 2017 eq = self.assertEqual s2018 unless = self. failUnless2047 eq = self.assertEqual 2048 unless = self.assertTrue 2019 2049 msg, text = self._msgobj('msg_06.txt') 2020 2050 # Check some of the outer headers … … 2026 2056 eq(len(payload), 1) 2027 2057 msg1 = payload[0] 2028 self. failUnless(isinstance(msg1, Message))2058 self.assertTrue(isinstance(msg1, Message)) 2029 2059 eq(msg1.get_content_type(), 'text/plain') 2030 self. failUnless(isinstance(msg1.get_payload(), str))2060 self.assertTrue(isinstance(msg1.get_payload(), str)) 2031 2061 eq(msg1.get_payload(), '\n') 2032 2033 2062 2034 2063 … … 2066 2095 2067 2096 def test_message_from_string_with_class(self): 2068 unless = self. failUnless2097 unless = self.assertTrue 2069 2098 fp = openfile('msg_01.txt') 2070 2099 try: … … 2089 2118 2090 2119 def test_message_from_file_with_class(self): 2091 unless = self. failUnless2120 unless = self.assertTrue 2092 2121 # Create a subclass 2093 2122 class MyMessage(Message): … … 2232 2261 def test_charset_richcomparisons(self): 2233 2262 eq = self.assertEqual 2234 ne = self. failIfEqual2263 ne = self.assertNotEqual 2235 2264 cset1 = Charset() 2236 2265 cset2 = Charset() … … 2359 2388 2360 2389 2361 2362 2390 # Test the iterator/generators 2363 2391 class TestIterators(TestEmailBase): … … 2420 2448 2421 2449 2422 2423 2450 class TestParsers(TestEmailBase): 2424 2451 def test_header_parser(self): … … 2433 2460 eq(msg['to'], 'ppp@zzz.org') 2434 2461 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)) 2437 2464 2438 2465 def test_whitespace_continuation(self): … … 2566 2593 2567 2594 2568 2569 2595 class TestBase64(unittest.TestCase): 2570 2596 def test_len(self): … … 2639 2665 2640 2666 2641 2642 2667 class TestQuopri(unittest.TestCase): 2643 2668 def setUp(self): … … 2655 2680 def test_header_quopri_check(self): 2656 2681 for c in self.hlit: 2657 self. failIf(quoprimime.header_quopri_check(c))2682 self.assertFalse(quoprimime.header_quopri_check(c)) 2658 2683 for c in self.hnon: 2659 self. failUnless(quoprimime.header_quopri_check(c))2684 self.assertTrue(quoprimime.header_quopri_check(c)) 2660 2685 2661 2686 def test_body_quopri_check(self): 2662 2687 for c in self.blit: 2663 self. failIf(quoprimime.body_quopri_check(c))2688 self.assertFalse(quoprimime.body_quopri_check(c)) 2664 2689 for c in self.bnon: 2665 self. failUnless(quoprimime.body_quopri_check(c))2690 self.assertTrue(quoprimime.body_quopri_check(c)) 2666 2691 2667 2692 def test_header_quopri_len(self): … … 2750 2775 2751 2776 2752 2753 2777 # Test the Charset class 2754 2778 class TestCharset(unittest.TestCase): … … 2783 2807 c = Charset('us-ascii') 2784 2808 eq('hello world', c.body_encode('hello world')) 2785 # Try the convert argument, where input codec <>output codec2809 # Try the convert argument, where input codec != output codec 2786 2810 c = Charset('euc-jp') 2787 2811 # With apologies to Tokio Kikuchi ;) … … 2809 2833 2810 2834 2811 2812 2835 # Test multilingual MIME headers. 2813 2836 class TestHeader(TestEmailBase): … … 2834 2857 maxlinelen=76) 2835 2858 for l in h.encode(splitchars=' ').split('\n '): 2836 self. failUnless(len(l) <= 76)2859 self.assertTrue(len(l) <= 76) 2837 2860 2838 2861 def test_multilingual(self): … … 2968 2991 def test_broken_base64_header(self): 2969 2992 raises = self.assertRaises 2970 s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I Q?='2993 s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=' 2971 2994 raises(errors.HeaderParseError, decode_header, s) 2972 2973 2995 2974 2996 … … 2998 3020 msg.set_param('title', 'This is even more ***fun*** isn\'t it!', 2999 3021 charset='us-ascii', language='en') 3000 eq(msg.as_string(), """\3022 self.ndiffAssertEqual(msg.as_string(), """\ 3001 3023 Return-Path: <bbb@zzz.org> 3002 3024 Delivered-To: bbb@zzz.org 3003 3025 Received: 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) 3005 3027 MIME-Version: 1.0 3006 3028 Content-Transfer-Encoding: 7bit … … 3011 3033 Date: Fri, 4 May 2001 14:05:44 -0400 3012 3034 Content-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" 3014 3036 3015 3037 … … 3032 3054 Delivered-To: bbb@zzz.org 3033 3055 Received: 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) 3035 3057 MIME-Version: 1.0 3036 3058 Content-Transfer-Encoding: 7bit … … 3041 3063 Date: Fri, 4 May 2001 14:05:44 -0400 3042 3064 Content-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" 3044 3066 3045 3067 … … 3065 3087 msg = email.message_from_string(m) 3066 3088 param = msg.get_param('NAME') 3067 self. failIf(isinstance(param, tuple))3089 self.assertFalse(isinstance(param, tuple)) 3068 3090 self.assertEqual( 3069 3091 param, … … 3218 3240 msg = email.message_from_string(m) 3219 3241 param = msg.get_param('name') 3220 self. failIf(isinstance(param, tuple))3242 self.assertFalse(isinstance(param, tuple)) 3221 3243 self.assertEqual(param, "Frank's Document") 3222 3244 … … 3242 3264 msg = email.message_from_string(m) 3243 3265 param = msg.get_param('name') 3244 self. failIf(isinstance(param, tuple))3266 self.assertFalse(isinstance(param, tuple)) 3245 3267 self.assertEqual(param, "us-ascii'en-us'Frank's Document") 3246 3268 … … 3286 3308 3287 3309 3288 3289 3310 def _testclasses(): 3290 3311 mod = sys.modules[__name__] … … 3305 3326 3306 3327 3307 3308 3328 if __name__ == '__main__': 3309 3329 unittest.main(defaultTest='suite') -
python/vendor/current/Lib/email/utils.py
r2 r388 1 # Copyright (C) 2001-20 09Python Software Foundation1 # Copyright (C) 2001-2010 Python Software Foundation 2 2 # Author: Barry Warsaw 3 3 # Contact: email-sig@python.org … … 62 62 63 63 def _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 """ 66 70 if not s: 67 71 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) 72 73 73 74 … … 75 76 76 77 def fix_eols(s): 77 """Replace all line-ending characters with \ r\n."""78 """Replace all line-ending characters with \\r\\n.""" 78 79 # Fix newlines with no preceding carriage return 79 80 s = re.sub(r'(?<!\r)\n', CRLF, s)
Note:
See TracChangeset
for help on using the changeset viewer.