diff options
| author | Lieuwe <lieuwemo@gmail.com> | 2011-03-18 16:04:51 (GMT) |
|---|---|---|
| committer | Lieuwe <lieuwemo@gmail.com> | 2011-03-18 16:04:51 (GMT) |
| commit | 9c39875ef09d439ef51716dba091188f72977f5e (patch) | |
| tree | fb0fd27a1bcd3e54a1913852c23aa137ee5eb30b /src/python/stdlib/test/test_multifile.py | |
| parent | bc8af4e2101ac93bdc51b59ee64fa43ecb2442f3 (diff) | |
| download | powder-9c39875ef09d439ef51716dba091188f72977f5e.zip powder-9c39875ef09d439ef51716dba091188f72977f5e.tar.gz | |
...
Diffstat (limited to 'src/python/stdlib/test/test_multifile.py')
| -rw-r--r-- | src/python/stdlib/test/test_multifile.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/python/stdlib/test/test_multifile.py b/src/python/stdlib/test/test_multifile.py new file mode 100644 index 0000000..043075b --- /dev/null +++ b/src/python/stdlib/test/test_multifile.py @@ -0,0 +1,67 @@ +from test import test_support +mimetools = test_support.import_module('mimetools', deprecated=True) +multifile = test_support.import_module('multifile', deprecated=True) +import cStringIO + +msg = """Mime-Version: 1.0 +Content-Type: multipart/mixed; + boundary="=====================_590453667==_" +X-OriginalArrivalTime: 05 Feb 2002 03:43:23.0310 (UTC) FILETIME=[42D88CE0:01C1ADF7] + +--=====================_590453667==_ +Content-Type: multipart/alternative; + boundary="=====================_590453677==_.ALT" + +--=====================_590453677==_.ALT +Content-Type: text/plain; charset="us-ascii"; format=flowed + +test A +--=====================_590453677==_.ALT +Content-Type: text/html; charset="us-ascii" + +<html> +<b>test B</font></b></html> + +--=====================_590453677==_.ALT-- + +--=====================_590453667==_ +Content-Type: text/plain; charset="us-ascii" +Content-Disposition: attachment; filename="att.txt" + +Attached Content. +Attached Content. +Attached Content. +Attached Content. + +--=====================_590453667==_-- + +""" + +def getMIMEMsg(mf): + global boundaries, linecount + msg = mimetools.Message(mf) + + #print "TYPE: %s" % msg.gettype() + if msg.getmaintype() == 'multipart': + boundary = msg.getparam("boundary") + boundaries += 1 + + mf.push(boundary) + while mf.next(): + getMIMEMsg(mf) + mf.pop() + else: + lines = mf.readlines() + linecount += len(lines) + +def test_main(): + global boundaries, linecount + boundaries = 0 + linecount = 0 + f = cStringIO.StringIO(msg) + getMIMEMsg(multifile.MultiFile(f)) + assert boundaries == 2 + assert linecount == 9 + +if __name__ == '__main__': + test_main() |
