@@ -214,7 +214,7 @@ def test_make_boundary(self):
214
214
def test_message_rfc822_only (self ):
215
215
# Issue 7970: message/rfc822 not in multipart parsed by
216
216
# 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 :
218
218
msgdata = fp .read ()
219
219
parser = HeaderParser ()
220
220
msg = parser .parsestr (msgdata )
@@ -225,7 +225,7 @@ def test_message_rfc822_only(self):
225
225
226
226
def test_byte_message_rfc822_only (self ):
227
227
# 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 :
229
229
msgdata = fp .read ().encode ('ascii' )
230
230
parser = email .parser .BytesHeaderParser ()
231
231
msg = parser .parsebytes (msgdata )
@@ -274,7 +274,7 @@ def test_get_payload_n_raises_on_non_multipart(self):
274
274
def test_decoded_generator (self ):
275
275
eq = self .assertEqual
276
276
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 :
278
278
text = fp .read ()
279
279
s = StringIO ()
280
280
g = DecodedGenerator (s )
@@ -295,7 +295,7 @@ def test__contains__(self):
295
295
296
296
def test_as_string (self ):
297
297
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 :
299
299
text = fp .read ()
300
300
self .assertEqual (text , str (msg ))
301
301
fullrepr = msg .as_string (unixfrom = True )
@@ -349,7 +349,7 @@ def test_nonascii_as_string_without_content_type_and_cte(self):
349
349
350
350
def test_as_bytes (self ):
351
351
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 :
353
353
data = fp .read ().encode ('ascii' )
354
354
self .assertEqual (data , bytes (msg ))
355
355
fullrepr = msg .as_bytes (unixfrom = True )
@@ -2436,7 +2436,7 @@ def test_multiline_header(self):
2436
2436
# Test the MIMEMessage class
2437
2437
class TestMIMEMessage (TestEmailBase ):
2438
2438
def setUp (self ):
2439
- with openfile ('msg_11.txt' ) as fp :
2439
+ with openfile ('msg_11.txt' , encoding = "utf-8" ) as fp :
2440
2440
self ._text = fp .read ()
2441
2441
2442
2442
def test_type_error (self ):
@@ -2555,7 +2555,7 @@ def test_dsn(self):
2555
2555
2556
2556
def test_epilogue (self ):
2557
2557
eq = self .ndiffAssertEqual
2558
- with openfile ('msg_21.txt' ) as fp :
2558
+ with openfile ('msg_21.txt' , encoding = "utf-8" ) as fp :
2559
2559
text = fp .read ()
2560
2560
msg = Message ()
2561
2561
msg ['From' ] = 'aperson@dom.ain'
@@ -2610,7 +2610,7 @@ def test_no_nl_preamble(self):
2610
2610
2611
2611
def test_default_type (self ):
2612
2612
eq = self .assertEqual
2613
- with openfile ('msg_30.txt' ) as fp :
2613
+ with openfile ('msg_30.txt' , encoding = "utf-8" ) as fp :
2614
2614
msg = email .message_from_file (fp )
2615
2615
container1 = msg .get_payload (0 )
2616
2616
eq (container1 .get_default_type (), 'message/rfc822' )
@@ -2627,7 +2627,7 @@ def test_default_type(self):
2627
2627
2628
2628
def test_default_type_with_explicit_container_type (self ):
2629
2629
eq = self .assertEqual
2630
- with openfile ('msg_28.txt' ) as fp :
2630
+ with openfile ('msg_28.txt' , encoding = "utf-8" ) as fp :
2631
2631
msg = email .message_from_file (fp )
2632
2632
container1 = msg .get_payload (0 )
2633
2633
eq (container1 .get_default_type (), 'message/rfc822' )
@@ -2753,7 +2753,7 @@ class TestIdempotent(TestEmailBase):
2753
2753
linesep = '\n '
2754
2754
2755
2755
def _msgobj (self , filename ):
2756
- with openfile (filename ) as fp :
2756
+ with openfile (filename , encoding = "utf-8" ) as fp :
2757
2757
data = fp .read ()
2758
2758
msg = email .message_from_string (data )
2759
2759
return msg , data
@@ -2909,7 +2909,7 @@ def test_parser(self):
2909
2909
# Test various other bits of the package's functionality
2910
2910
class TestMiscellaneous (TestEmailBase ):
2911
2911
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 :
2913
2913
text = fp .read ()
2914
2914
msg = email .message_from_string (text )
2915
2915
s = StringIO ()
@@ -2920,7 +2920,7 @@ def test_message_from_string(self):
2920
2920
self .assertEqual (text , s .getvalue ())
2921
2921
2922
2922
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 :
2924
2924
text = fp .read ()
2925
2925
fp .seek (0 )
2926
2926
msg = email .message_from_file (fp )
@@ -2932,7 +2932,7 @@ def test_message_from_file(self):
2932
2932
self .assertEqual (text , s .getvalue ())
2933
2933
2934
2934
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 :
2936
2936
text = fp .read ()
2937
2937
2938
2938
# Create a subclass
@@ -2942,7 +2942,7 @@ class MyMessage(Message):
2942
2942
msg = email .message_from_string (text , MyMessage )
2943
2943
self .assertIsInstance (msg , MyMessage )
2944
2944
# Try something more complicated
2945
- with openfile ('msg_02.txt' ) as fp :
2945
+ with openfile ('msg_02.txt' , encoding = "utf-8" ) as fp :
2946
2946
text = fp .read ()
2947
2947
msg = email .message_from_string (text , MyMessage )
2948
2948
for subpart in msg .walk ():
@@ -2953,11 +2953,11 @@ def test_message_from_file_with_class(self):
2953
2953
class MyMessage (Message ):
2954
2954
pass
2955
2955
2956
- with openfile ('msg_01.txt' ) as fp :
2956
+ with openfile ('msg_01.txt' , encoding = "utf-8" ) as fp :
2957
2957
msg = email .message_from_file (fp , MyMessage )
2958
2958
self .assertIsInstance (msg , MyMessage )
2959
2959
# Try something more complicated
2960
- with openfile ('msg_02.txt' ) as fp :
2960
+ with openfile ('msg_02.txt' , encoding = "utf-8" ) as fp :
2961
2961
msg = email .message_from_file (fp , MyMessage )
2962
2962
for subpart in msg .walk ():
2963
2963
self .assertIsInstance (subpart , MyMessage )
@@ -3386,7 +3386,7 @@ def test_make_msgid_default_domain(self):
3386
3386
3387
3387
def test_Generator_linend (self ):
3388
3388
# 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 :
3390
3390
msgtxt = f .read ()
3391
3391
msgtxt_nl = msgtxt .replace ('\r \n ' , '\n ' )
3392
3392
msg = email .message_from_string (msgtxt )
@@ -3397,7 +3397,7 @@ def test_Generator_linend(self):
3397
3397
3398
3398
def test_BytesGenerator_linend (self ):
3399
3399
# 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 :
3401
3401
msgtxt = f .read ()
3402
3402
msgtxt_nl = msgtxt .replace ('\r \n ' , '\n ' )
3403
3403
msg = email .message_from_string (msgtxt_nl )
@@ -3456,7 +3456,7 @@ def test_body_line_iterator(self):
3456
3456
it = iterators .body_line_iterator (msg )
3457
3457
lines = list (it )
3458
3458
eq (len (lines ), 43 )
3459
- with openfile ('msg_19.txt' ) as fp :
3459
+ with openfile ('msg_19.txt' , encoding = "utf-8" ) as fp :
3460
3460
neq (EMPTYSTRING .join (lines ), fp .read ())
3461
3461
3462
3462
def test_typed_subpart_iterator (self ):
@@ -3597,7 +3597,7 @@ class TestParsers(TestEmailBase):
3597
3597
def test_header_parser (self ):
3598
3598
eq = self .assertEqual
3599
3599
# 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 :
3601
3601
msg = HeaderParser ().parse (fp )
3602
3602
eq (msg ['from' ], 'ppp-request@zzz.org' )
3603
3603
eq (msg ['to' ], 'ppp@zzz.org' )
@@ -3631,12 +3631,12 @@ def test_bytes_parser_on_exception_does_not_close_file(self):
3631
3631
self .assertFalse (fp .closed )
3632
3632
3633
3633
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 :
3635
3635
email .parser .Parser ().parse (fp )
3636
3636
self .assertFalse (fp .closed )
3637
3637
3638
3638
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 :
3640
3640
parser = email .parser .Parser
3641
3641
self .assertRaises (email .errors .StartBoundaryNotFoundDefect ,
3642
3642
parser (policy = email .policy .strict ).parse , fp )
@@ -3680,7 +3680,7 @@ def test_whitespace_continuation_last_header(self):
3680
3680
3681
3681
def test_crlf_separation (self ):
3682
3682
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 :
3684
3684
msg = Parser ().parse (fp )
3685
3685
eq (len (msg .get_payload ()), 2 )
3686
3686
part1 = msg .get_payload (0 )
@@ -3691,7 +3691,7 @@ def test_crlf_separation(self):
3691
3691
3692
3692
def test_crlf_flatten (self ):
3693
3693
# 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 :
3695
3695
text = fp .read ()
3696
3696
msg = email .message_from_string (text )
3697
3697
s = StringIO ()
@@ -3704,7 +3704,7 @@ def test_crlf_flatten(self):
3704
3704
def test_multipart_digest_with_extra_mime_headers (self ):
3705
3705
eq = self .assertEqual
3706
3706
neq = self .ndiffAssertEqual
3707
- with openfile ('msg_28.txt' ) as fp :
3707
+ with openfile ('msg_28.txt' , encoding = "utf-8" ) as fp :
3708
3708
msg = email .message_from_file (fp )
3709
3709
# Structure is:
3710
3710
# multipart/digest
@@ -5447,7 +5447,7 @@ def test_should_not_hang_on_invalid_ew_messages(self):
5447
5447
class TestSigned (TestEmailBase ):
5448
5448
5449
5449
def _msg_and_obj (self , filename ):
5450
- with openfile (filename ) as fp :
5450
+ with openfile (filename , encoding = "utf-8" ) as fp :
5451
5451
original = fp .read ()
5452
5452
msg = email .message_from_string (original )
5453
5453
return original , msg
0 commit comments