2 from test
import test_support
4 import string
, StringIO
, mimetools
, sets
6 msgtext1
= mimetools
.Message(StringIO
.StringIO(
7 """Content-Type: text/plain; charset=iso-8859-1; format=flowed
8 Content-Transfer-Encoding: 8bit
13 class MimeToolsTest(unittest
.TestCase
):
15 def test_decodeencode(self
):
16 start
= string
.ascii_letters
+ "=" + string
.digits
+ "\n"
17 for enc
in ['7bit','8bit','base64','quoted-printable',
18 'uuencode', 'x-uuencode', 'uue', 'x-uue']:
19 i
= StringIO
.StringIO(start
)
20 o
= StringIO
.StringIO()
21 mimetools
.encode(i
, o
, enc
)
22 i
= StringIO
.StringIO(o
.getvalue())
23 o
= StringIO
.StringIO()
24 mimetools
.decode(i
, o
, enc
)
25 self
.assertEqual(o
.getvalue(), start
)
27 def test_boundary(self
):
30 nb
= mimetools
.choose_boundary()
31 self
.assert_(nb
not in s
)
34 def test_message(self
):
35 msg
= mimetools
.Message(StringIO
.StringIO(msgtext1
))
36 self
.assertEqual(msg
.gettype(), "text/plain")
37 self
.assertEqual(msg
.getmaintype(), "text")
38 self
.assertEqual(msg
.getsubtype(), "plain")
39 self
.assertEqual(msg
.getplist(), ["charset=iso-8859-1", "format=flowed"])
40 self
.assertEqual(msg
.getparamnames(), ["charset", "format"])
41 self
.assertEqual(msg
.getparam("charset"), "iso-8859-1")
42 self
.assertEqual(msg
.getparam("format"), "flowed")
43 self
.assertEqual(msg
.getparam("spam"), None)
44 self
.assertEqual(msg
.getencoding(), "8bit")
47 test_support
.run_unittest(MimeToolsTest
)
49 if __name__
=="__main__":