⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_rfc822.py

📁 minimal python variant for small footprint apps like embedded apps
💻 PY
字号:
from test_support import verboseimport rfc822, systry:    from cStringIO import StringIOexcept ImportError:    from StringIO import StringIOdef test(msg, results):    fp = StringIO()    fp.write(msg)    fp.seek(0)    m = rfc822.Message(fp)    i = 0        for n, a in m.getaddrlist('to') + m.getaddrlist('cc'):        if verbose:            print 'name:', repr(n), 'addr:', repr(a)        try:            mn, ma = results[i][0], results[i][1]        except IndexError:            print 'extra parsed address:', repr(n), repr(a)            continue        i = i + 1        if mn == n and ma == a:            if verbose:                print '    [matched]'        else:            if verbose:                print '    [no match]'            print 'not found:', repr(n), repr(a)    out = m.getdate('date')    if out:        if verbose:            print 'Date:', m.getheader('date')        if out == (1999, 1, 13, 23, 57, 35, 0, 0, 0):            if verbose:                print '    [matched]'        else:            if verbose:                print '    [no match]'            print 'Date conversion failed:', out# Note: all test cases must have the same date (in various formats),# or no date!test('''Date:    Wed, 13 Jan 1999 23:57:35 -0500From:    Guido van Rossum <guido@CNRI.Reston.VA.US>To:      "Guido van	 : Rossum" <guido@python.org>Subject: test2test2''', [('Guido van\n	 : Rossum', 'guido@python.org')])test('''From: Barry <bwarsaw@python.orgTo: guido@python.org (Guido: the Barbarian)Subject: nonsenseDate: Wednesday, January 13 1999 23:57:35 -0500test''', [('Guido: the Barbarian', 'guido@python.org'),          ])test('''From: Barry <bwarsaw@python.orgTo: guido@python.org (Guido: the Barbarian)Cc: "Guido: the Madman" <guido@python.org>Date:  13-Jan-1999 23:57:35 ESTtest''', [('Guido: the Barbarian', 'guido@python.org'),          ('Guido: the Madman', 'guido@python.org')          ])test('''To: "The monster with     the very long name: Guido" <guido@python.org>Date:    Wed, 13 Jan 1999 23:57:35 -0500test''', [('The monster with\n     the very long name: Guido',           'guido@python.org')])test('''To: "Amit J. Patel" <amitp@Theory.Stanford.EDU>CC: Mike Fletcher <mfletch@vrtelecom.com>,        "'string-sig@python.org'" <string-sig@python.org>Cc: fooz@bat.com, bart@toof.comCc: goit@lip.comDate:    Wed, 13 Jan 1999 23:57:35 -0500test''', [('Amit J. Patel', 'amitp@Theory.Stanford.EDU'),          ('Mike Fletcher', 'mfletch@vrtelecom.com'),          ("'string-sig@python.org'", 'string-sig@python.org'),          ('', 'fooz@bat.com'),          ('', 'bart@toof.com'),          ('', 'goit@lip.com'),          ])# This one is just twisted.  I don't know what the proper result should be,# but it shouldn't be to infloop, which is what used to happen!test('''To: <[smtp:dd47@mail.xxx.edu]_at_hmhq@hdq-mdm1-imgout.companay.com>Date:    Wed, 13 Jan 1999 23:57:35 -0500test''', [('', ''),          ('', 'dd47@mail.xxx.edu'),          ('', '_at_hmhq@hdq-mdm1-imgout.companay.com')          ])# This exercises the old commas-in-a-full-name bug, which should be doing the# right thing in recent versions of the module.test('''To: "last, first" <userid@foo.net>test''', [('last, first', 'userid@foo.net'),          ])test('''To: (Comment stuff) "Quoted name"@somewhere.comtest''', [('Comment stuff', '"Quoted name"@somewhere.com'),          ])test('''To: :Cc: goit@lip.comDate:    Wed, 13 Jan 1999 23:57:35 -0500test''', [('', 'goit@lip.com')])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -