home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / Python / Lib / Python1.5 / test / test_rfc822.py < prev    next >
Encoding:
Python Source  |  1999-01-14  |  2.4 KB  |  83 lines

  1. from test_support import verbose
  2. import rfc822, sys
  3. try:
  4.     from cStringIO import StringIO
  5. except ImportError:
  6.     from StringIO import StringIO
  7.  
  8. def test(msg, results):
  9.     fp = StringIO()
  10.     fp.write(msg)
  11.     fp.seek(0)
  12.     m = rfc822.Message(fp)
  13.     i = 0
  14.     for n, a in m.getaddrlist('to') + m.getaddrlist('cc'):
  15.         if verbose:
  16.             print 'name:', repr(n), 'addr:', repr(a)
  17.         try:
  18.             mn, ma = results[i][0], results[i][1]
  19.         except IndexError:
  20.             print 'extra parsed address:', repr(n), repr(a)
  21.             continue
  22.         i = i + 1
  23.         if mn == n and ma == a:
  24.             if verbose:
  25.                 print '    [matched]'
  26.         else:
  27.             if verbose:
  28.                 print '    [no match]'
  29.             print 'not found:', repr(n), repr(a)
  30.  
  31. test('''Date:    Wed, 13 Jan 1999 23:57:35 -0500
  32. From:    Guido van Rossum <guido@CNRI.Reston.VA.US>
  33. To:      "Guido van
  34.      : Rossum" <guido@python.org>
  35. Subject: test2
  36.  
  37. test2
  38. ''', [('Guido van\n     : Rossum', 'guido@python.org')])
  39.  
  40. test('''From: Barry <bwarsaw@python.org
  41. To: guido@python.org (Guido: the Barbarian)
  42. Subject: nonsense
  43.  
  44. test''', [('Guido: the Barbarian', 'guido@python.org'),
  45.           ])
  46.  
  47. test('''From: Barry <bwarsaw@python.org
  48. To: guido@python.org (Guido: the Barbarian)
  49. Cc: "Guido: the Madman" <guido@python.org>
  50.  
  51. test''', [('Guido: the Barbarian', 'guido@python.org'),
  52.           ('Guido: the Madman', 'guido@python.org')
  53.           ])
  54.  
  55. test('''To: "The monster with
  56.      the very long name: Guido" <guido@python.org>
  57.  
  58. test''', [('The monster with\n     the very long name: Guido',
  59.            'guido@python.org')])
  60.  
  61. test('''To: "Amit J. Patel" <amitp@Theory.Stanford.EDU>
  62. CC: Mike Fletcher <mfletch@vrtelecom.com>,
  63.         "'string-sig@python.org'" <string-sig@python.org>
  64. Cc: fooz@bat.com, bart@toof.com
  65. Cc: goit@lip.com
  66.  
  67. test''', [('Amit J. Patel', 'amitp@Theory.Stanford.EDU'),
  68.           ('Mike Fletcher', 'mfletch@vrtelecom.com'),
  69.           ("'string-sig@python.org'", 'string-sig@python.org'),
  70.           ('', 'fooz@bat.com'),
  71.           ('', 'bart@toof.com'),
  72.           ('', 'goit@lip.com'),
  73.           ])
  74.  
  75. # This one is just twisted.  I don't know what the proper result should be,
  76. # but it shouldn't be to infloop, which is what used to happen!
  77. test('''To: <[smtp:dd47@mail.xxx.edu]_at_hmhq@hdq-mdm1-imgout.companay.com>
  78.  
  79. test''', [('', ''),
  80.           ('', 'dd47@mail.xxx.edu'),
  81.           ('', '_at_hmhq@hdq-mdm1-imgout.companay.com')
  82.           ])
  83.