Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 1 | # Copyright (C) 2001,2002 Python Software Foundation |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 2 | # Author: barry@zope.com (Barry Warsaw) |
| 3 | |
| 4 | """Various types of useful iterators and generators. |
| 5 | """ |
| 6 | |
Barry Warsaw | d438574 | 2002-07-19 22:21:47 +0000 | [diff] [blame] | 7 | import sys |
| 8 | |
Barry Warsaw | 8c1aac2 | 2002-05-19 23:44:19 +0000 | [diff] [blame] | 9 | try: |
| 10 | from email._compat22 import body_line_iterator, typed_subpart_iterator |
| 11 | except SyntaxError: |
| 12 | # Python 2.1 doesn't have generators |
| 13 | from email._compat21 import body_line_iterator, typed_subpart_iterator |
Barry Warsaw | 8fa06b5 | 2002-07-09 02:39:07 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | |
Barry Warsaw | 1f84ff1 | 2002-10-01 00:51:47 +0000 | [diff] [blame] | 17 | def _structure(msg, fp=None, level=0): |
Barry Warsaw | 8fa06b5 | 2002-07-09 02:39:07 +0000 | [diff] [blame] | 18 | """A handy debugging aid""" |
Barry Warsaw | d438574 | 2002-07-19 22:21:47 +0000 | [diff] [blame] | 19 | if fp is None: |
| 20 | fp = sys.stdout |
Barry Warsaw | 8fa06b5 | 2002-07-09 02:39:07 +0000 | [diff] [blame] | 21 | tab = ' ' * (level * 4) |
Barry Warsaw | a4ce1cf | 2002-09-01 21:04:43 +0000 | [diff] [blame] | 22 | print >> fp, tab + msg.get_content_type() |
Barry Warsaw | 8fa06b5 | 2002-07-09 02:39:07 +0000 | [diff] [blame] | 23 | if msg.is_multipart(): |
| 24 | for subpart in msg.get_payload(): |
Barry Warsaw | 1f84ff1 | 2002-10-01 00:51:47 +0000 | [diff] [blame] | 25 | _structure(subpart, fp, level+1) |