Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / test / test_multifile.py
CommitLineData
920dae64
AT
1import mimetools
2import multifile
3import cStringIO
4
5msg = """Mime-Version: 1.0
6Content-Type: multipart/mixed;
7 boundary="=====================_590453667==_"
8X-OriginalArrivalTime: 05 Feb 2002 03:43:23.0310 (UTC) FILETIME=[42D88CE0:01C1ADF7]
9
10--=====================_590453667==_
11Content-Type: multipart/alternative;
12 boundary="=====================_590453677==_.ALT"
13
14--=====================_590453677==_.ALT
15Content-Type: text/plain; charset="us-ascii"; format=flowed
16
17test A
18--=====================_590453677==_.ALT
19Content-Type: text/html; charset="us-ascii"
20
21<html>
22<b>test B</font></b></html>
23
24--=====================_590453677==_.ALT--
25
26--=====================_590453667==_
27Content-Type: text/plain; charset="us-ascii"
28Content-Disposition: attachment; filename="att.txt"
29
30Attached Content.
31Attached Content.
32Attached Content.
33Attached Content.
34
35--=====================_590453667==_--
36
37"""
38
39def getMIMEMsg(mf):
40 global boundaries, linecount
41 msg = mimetools.Message(mf)
42
43 #print "TYPE: %s" % msg.gettype()
44 if msg.getmaintype() == 'multipart':
45 boundary = msg.getparam("boundary")
46 boundaries += 1
47
48 mf.push(boundary)
49 while mf.next():
50 getMIMEMsg(mf)
51 mf.pop()
52 else:
53 lines = mf.readlines()
54 linecount += len(lines)
55
56def test_main():
57 global boundaries, linecount
58 boundaries = 0
59 linecount = 0
60 f = cStringIO.StringIO(msg)
61 getMIMEMsg(multifile.MultiFile(f))
62 assert boundaries == 2
63 assert linecount == 9
64
65if __name__ == '__main__':
66 test_main()