@@ -92,44 +92,6 @@ def test_set_payload_with_charset(self):
9292 msg .set_payload ('This is a string payload' , charset )
9393 self .assertEqual (msg .get_charset ().input_charset , 'iso-8859-1' )
9494
95- def test_set_payload_with_8bit_data_and_charset (self ):
96- data = b'\xd0 \x90 \xd0 \x91 \xd0 \x92 '
97- charset = Charset ('utf-8' )
98- msg = Message ()
99- msg .set_payload (data , charset )
100- self .assertEqual (msg ['content-transfer-encoding' ], 'base64' )
101- self .assertEqual (msg .get_payload (decode = True ), data )
102- self .assertEqual (msg .get_payload (), '0JDQkdCS\n ' )
103-
104- def test_set_payload_with_non_ascii_and_charset_body_encoding_none (self ):
105- data = b'\xd0 \x90 \xd0 \x91 \xd0 \x92 '
106- charset = Charset ('utf-8' )
107- charset .body_encoding = None # Disable base64 encoding
108- msg = Message ()
109- msg .set_payload (data .decode ('utf-8' ), charset )
110- self .assertEqual (msg ['content-transfer-encoding' ], '8bit' )
111- self .assertEqual (msg .get_payload (decode = True ), data )
112-
113- def test_set_payload_with_8bit_data_and_charset_body_encoding_none (self ):
114- data = b'\xd0 \x90 \xd0 \x91 \xd0 \x92 '
115- charset = Charset ('utf-8' )
116- charset .body_encoding = None # Disable base64 encoding
117- msg = Message ()
118- msg .set_payload (data , charset )
119- self .assertEqual (msg ['content-transfer-encoding' ], '8bit' )
120- self .assertEqual (msg .get_payload (decode = True ), data )
121-
122- def test_set_payload_to_list (self ):
123- msg = Message ()
124- msg .set_payload ([])
125- self .assertEqual (msg .get_payload (), [])
126-
127- def test_set_payload_with_non_ascii_and_no_charset_raises (self ):
128- data = b'\xd0 \x90 \xd0 \x91 \xd0 \x92 ' .decode ('utf-8' )
129- msg = Message ()
130- with self .assertRaises (TypeError ):
131- msg .set_payload (data )
132-
13395 def test_get_charsets (self ):
13496 eq = self .assertEqual
13597
@@ -596,10 +558,20 @@ def test_broken_base64_payload(self):
596558 self .assertIsInstance (msg .defects [0 ],
597559 errors .InvalidBase64CharactersDefect )
598560
561+ def test_broken_unicode_payload (self ):
562+ # This test improves coverage but is not a compliance test.
563+ # The behavior in this situation is currently undefined by the API.
564+ x = 'this is a br\xf6 ken thing to do'
565+ msg = Message ()
566+ msg ['content-type' ] = 'text/plain'
567+ msg ['content-transfer-encoding' ] = '8bit'
568+ msg .set_payload (x )
569+ self .assertEqual (msg .get_payload (decode = True ),
570+ bytes (x , 'raw-unicode-escape' ))
571+
599572 def test_questionable_bytes_payload (self ):
600573 # This test improves coverage but is not a compliance test,
601- # since it involves poking inside the black box in a way
602- # that actually breaks the model invariants.
574+ # since it involves poking inside the black box.
603575 x = 'this is a quéstionable thing to do' .encode ('utf-8' )
604576 msg = Message ()
605577 msg ['content-type' ] = 'text/plain; charset="utf-8"'
0 commit comments