test_multifile.py
来自「mallet是自然语言处理、机器学习领域的一个开源项目。」· Python 代码 · 共 67 行
PY
67 行
import mimetoolsimport multifileimport cStringIOmsg = """Mime-Version: 1.0Content-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==_.ALTContent-Type: text/plain; charset="us-ascii"; format=flowedtest A--=====================_590453677==_.ALTContent-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==_--"""boundaries = 0linecount = 0def 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 main(): f = cStringIO.StringIO(msg) getMIMEMsg(multifile.MultiFile(f)) assert boundaries == 2 assert linecount == 9if __name__ == '__main__': main()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?