@@ -214,7 +214,7 @@ def test_make_boundary(self):
214214 def test_message_rfc822_only (self ):
215215 # Issue 7970: message/rfc822 not in multipart parsed by
216216 # HeaderParser caused an exception when flattened.
217- with openfile ('msg_46.txt' ) as fp :
217+ with openfile ('msg_46.txt' , encoding = "utf-8" ) as fp :
218218 msgdata = fp .read ()
219219 parser = HeaderParser ()
220220 msg = parser .parsestr (msgdata )
@@ -225,7 +225,7 @@ def test_message_rfc822_only(self):
225225
226226 def test_byte_message_rfc822_only (self ):
227227 # Make sure new bytes header parser also passes this.
228- with openfile ('msg_46.txt' ) as fp :
228+ with openfile ('msg_46.txt' , encoding = "utf-8" ) as fp :
229229 msgdata = fp .read ().encode ('ascii' )
230230 parser = email .parser .BytesHeaderParser ()
231231 msg = parser .parsebytes (msgdata )
@@ -274,7 +274,7 @@ def test_get_payload_n_raises_on_non_multipart(self):
274274 def test_decoded_generator (self ):
275275 eq = self .assertEqual
276276 msg = self ._msgobj ('msg_07.txt' )
277- with openfile ('msg_17.txt' ) as fp :
277+ with openfile ('msg_17.txt' , encoding = "utf-8" ) as fp :
278278 text = fp .read ()
279279 s = StringIO ()
280280 g = DecodedGenerator (s )
@@ -295,7 +295,7 @@ def test__contains__(self):
295295
296296 def test_as_string (self ):
297297 msg = self ._msgobj ('msg_01.txt' )
298- with openfile ('msg_01.txt' ) as fp :
298+ with openfile ('msg_01.txt' , encoding = "utf-8" ) as fp :
299299 text = fp .read ()
300300 self .assertEqual (text , str (msg ))
301301 fullrepr = msg .as_string (unixfrom = True )
@@ -349,7 +349,7 @@ def test_nonascii_as_string_without_content_type_and_cte(self):
349349
350350 def test_as_bytes (self ):
351351 msg = self ._msgobj ('msg_01.txt' )
352- with openfile ('msg_01.txt' ) as fp :
352+ with openfile ('msg_01.txt' , encoding = "utf-8" ) as fp :
353353 data = fp .read ().encode ('ascii' )
354354 self .assertEqual (data , bytes (msg ))
355355 fullrepr = msg .as_bytes (unixfrom = True )
@@ -2436,7 +2436,7 @@ def test_multiline_header(self):
24362436# Test the MIMEMessage class
24372437class TestMIMEMessage (TestEmailBase ):
24382438 def setUp (self ):
2439- with openfile ('msg_11.txt' ) as fp :
2439+ with openfile ('msg_11.txt' , encoding = "utf-8" ) as fp :
24402440 self ._text = fp .read ()
24412441
24422442 def test_type_error (self ):
@@ -2555,7 +2555,7 @@ def test_dsn(self):
25552555
25562556 def test_epilogue (self ):
25572557 eq = self .ndiffAssertEqual
2558- with openfile ('msg_21.txt' ) as fp :
2558+ with openfile ('msg_21.txt' , encoding = "utf-8" ) as fp :
25592559 text = fp .read ()
25602560 msg = Message ()
25612561 msg ['From' ] = 'aperson@dom.ain'
@@ -2610,7 +2610,7 @@ def test_no_nl_preamble(self):
26102610
26112611 def test_default_type (self ):
26122612 eq = self .assertEqual
2613- with openfile ('msg_30.txt' ) as fp :
2613+ with openfile ('msg_30.txt' , encoding = "utf-8" ) as fp :
26142614 msg = email .message_from_file (fp )
26152615 container1 = msg .get_payload (0 )
26162616 eq (container1 .get_default_type (), 'message/rfc822' )
@@ -2627,7 +2627,7 @@ def test_default_type(self):
26272627
26282628 def test_default_type_with_explicit_container_type (self ):
26292629 eq = self .assertEqual
2630- with openfile ('msg_28.txt' ) as fp :
2630+ with openfile ('msg_28.txt' , encoding = "utf-8" ) as fp :
26312631 msg = email .message_from_file (fp )
26322632 container1 = msg .get_payload (0 )
26332633 eq (container1 .get_default_type (), 'message/rfc822' )
@@ -2753,7 +2753,7 @@ class TestIdempotent(TestEmailBase):
27532753 linesep = '\n '
27542754
27552755 def _msgobj (self , filename ):
2756- with openfile (filename ) as fp :
2756+ with openfile (filename , encoding = "utf-8" ) as fp :
27572757 data = fp .read ()
27582758 msg = email .message_from_string (data )
27592759 return msg , data
@@ -2909,7 +2909,7 @@ def test_parser(self):
29092909# Test various other bits of the package's functionality
29102910class TestMiscellaneous (TestEmailBase ):
29112911 def test_message_from_string (self ):
2912- with openfile ('msg_01.txt' ) as fp :
2912+ with openfile ('msg_01.txt' , encoding = "utf-8" ) as fp :
29132913 text = fp .read ()
29142914 msg = email .message_from_string (text )
29152915 s = StringIO ()
@@ -2920,7 +2920,7 @@ def test_message_from_string(self):
29202920 self .assertEqual (text , s .getvalue ())
29212921
29222922 def test_message_from_file (self ):
2923- with openfile ('msg_01.txt' ) as fp :
2923+ with openfile ('msg_01.txt' , encoding = "utf-8" ) as fp :
29242924 text = fp .read ()
29252925 fp .seek (0 )
29262926 msg = email .message_from_file (fp )
@@ -2932,7 +2932,7 @@ def test_message_from_file(self):
29322932 self .assertEqual (text , s .getvalue ())
29332933
29342934 def test_message_from_string_with_class (self ):
2935- with openfile ('msg_01.txt' ) as fp :
2935+ with openfile ('msg_01.txt' , encoding = "utf-8" ) as fp :
29362936 text = fp .read ()
29372937
29382938 # Create a subclass
@@ -2942,7 +2942,7 @@ class MyMessage(Message):
29422942 msg = email .message_from_string (text , MyMessage )
29432943 self .assertIsInstance (msg , MyMessage )
29442944 # Try something more complicated
2945- with openfile ('msg_02.txt' ) as fp :
2945+ with openfile ('msg_02.txt' , encoding = "utf-8" ) as fp :
29462946 text = fp .read ()
29472947 msg = email .message_from_string (text , MyMessage )
29482948 for subpart in msg .walk ():
@@ -2953,11 +2953,11 @@ def test_message_from_file_with_class(self):
29532953 class MyMessage (Message ):
29542954 pass
29552955
2956- with openfile ('msg_01.txt' ) as fp :
2956+ with openfile ('msg_01.txt' , encoding = "utf-8" ) as fp :
29572957 msg = email .message_from_file (fp , MyMessage )
29582958 self .assertIsInstance (msg , MyMessage )
29592959 # Try something more complicated
2960- with openfile ('msg_02.txt' ) as fp :
2960+ with openfile ('msg_02.txt' , encoding = "utf-8" ) as fp :
29612961 msg = email .message_from_file (fp , MyMessage )
29622962 for subpart in msg .walk ():
29632963 self .assertIsInstance (subpart , MyMessage )
@@ -3386,7 +3386,7 @@ def test_make_msgid_default_domain(self):
33863386
33873387 def test_Generator_linend (self ):
33883388 # Issue 14645.
3389- with openfile ('msg_26.txt' , newline = '\n ' ) as f :
3389+ with openfile ('msg_26.txt' , encoding = "utf-8" , newline = '\n ' ) as f :
33903390 msgtxt = f .read ()
33913391 msgtxt_nl = msgtxt .replace ('\r \n ' , '\n ' )
33923392 msg = email .message_from_string (msgtxt )
@@ -3397,7 +3397,7 @@ def test_Generator_linend(self):
33973397
33983398 def test_BytesGenerator_linend (self ):
33993399 # Issue 14645.
3400- with openfile ('msg_26.txt' , newline = '\n ' ) as f :
3400+ with openfile ('msg_26.txt' , encoding = "utf-8" , newline = '\n ' ) as f :
34013401 msgtxt = f .read ()
34023402 msgtxt_nl = msgtxt .replace ('\r \n ' , '\n ' )
34033403 msg = email .message_from_string (msgtxt_nl )
@@ -3456,7 +3456,7 @@ def test_body_line_iterator(self):
34563456 it = iterators .body_line_iterator (msg )
34573457 lines = list (it )
34583458 eq (len (lines ), 43 )
3459- with openfile ('msg_19.txt' ) as fp :
3459+ with openfile ('msg_19.txt' , encoding = "utf-8" ) as fp :
34603460 neq (EMPTYSTRING .join (lines ), fp .read ())
34613461
34623462 def test_typed_subpart_iterator (self ):
@@ -3597,7 +3597,7 @@ class TestParsers(TestEmailBase):
35973597 def test_header_parser (self ):
35983598 eq = self .assertEqual
35993599 # Parse only the headers of a complex multipart MIME document
3600- with openfile ('msg_02.txt' ) as fp :
3600+ with openfile ('msg_02.txt' , encoding = "utf-8" ) as fp :
36013601 msg = HeaderParser ().parse (fp )
36023602 eq (msg ['from' ], 'ppp-request@zzz.org' )
36033603 eq (msg ['to' ], 'ppp@zzz.org' )
@@ -3631,12 +3631,12 @@ def test_bytes_parser_on_exception_does_not_close_file(self):
36313631 self .assertFalse (fp .closed )
36323632
36333633 def test_parser_does_not_close_file (self ):
3634- with openfile ('msg_02.txt' , 'r' ) as fp :
3634+ with openfile ('msg_02.txt' , encoding = "utf-8" ) as fp :
36353635 email .parser .Parser ().parse (fp )
36363636 self .assertFalse (fp .closed )
36373637
36383638 def test_parser_on_exception_does_not_close_file (self ):
3639- with openfile ('msg_15.txt' , 'r' ) as fp :
3639+ with openfile ('msg_15.txt' , encoding = "utf-8" ) as fp :
36403640 parser = email .parser .Parser
36413641 self .assertRaises (email .errors .StartBoundaryNotFoundDefect ,
36423642 parser (policy = email .policy .strict ).parse , fp )
@@ -3680,7 +3680,7 @@ def test_whitespace_continuation_last_header(self):
36803680
36813681 def test_crlf_separation (self ):
36823682 eq = self .assertEqual
3683- with openfile ('msg_26.txt' , newline = '\n ' ) as fp :
3683+ with openfile ('msg_26.txt' , encoding = "utf-8" , newline = '\n ' ) as fp :
36843684 msg = Parser ().parse (fp )
36853685 eq (len (msg .get_payload ()), 2 )
36863686 part1 = msg .get_payload (0 )
@@ -3691,7 +3691,7 @@ def test_crlf_separation(self):
36913691
36923692 def test_crlf_flatten (self ):
36933693 # Using newline='\n' preserves the crlfs in this input file.
3694- with openfile ('msg_26.txt' , newline = '\n ' ) as fp :
3694+ with openfile ('msg_26.txt' , encoding = "utf-8" , newline = '\n ' ) as fp :
36953695 text = fp .read ()
36963696 msg = email .message_from_string (text )
36973697 s = StringIO ()
@@ -3704,7 +3704,7 @@ def test_crlf_flatten(self):
37043704 def test_multipart_digest_with_extra_mime_headers (self ):
37053705 eq = self .assertEqual
37063706 neq = self .ndiffAssertEqual
3707- with openfile ('msg_28.txt' ) as fp :
3707+ with openfile ('msg_28.txt' , encoding = "utf-8" ) as fp :
37083708 msg = email .message_from_file (fp )
37093709 # Structure is:
37103710 # multipart/digest
@@ -5447,7 +5447,7 @@ def test_should_not_hang_on_invalid_ew_messages(self):
54475447class TestSigned (TestEmailBase ):
54485448
54495449 def _msg_and_obj (self , filename ):
5450- with openfile (filename ) as fp :
5450+ with openfile (filename , encoding = "utf-8" ) as fp :
54515451 original = fp .read ()
54525452 msg = email .message_from_string (original )
54535453 return original , msg
0 commit comments