blob: d5f6eebadedf86c259741634ea9d7bd4127d7b1a [file] [log] [blame]
Barry Warsaw409a4c02002-04-10 21:01:31 +00001# Copyright (C) 2001,2002 Python Software Foundation
Barry Warsawba925802001-09-23 03:17:28 +00002# Author: barry@zope.com (Barry Warsaw)
3
4"""Various types of useful iterators and generators.
5"""
6
Barry Warsawd4385742002-07-19 22:21:47 +00007import sys
8
Barry Warsaw8c1aac22002-05-19 23:44:19 +00009try:
10 from email._compat22 import body_line_iterator, typed_subpart_iterator
11except SyntaxError:
12 # Python 2.1 doesn't have generators
13 from email._compat21 import body_line_iterator, typed_subpart_iterator
Barry Warsaw8fa06b52002-07-09 02:39:07 +000014
15
16
Barry Warsawd4385742002-07-19 22:21:47 +000017def _structure(msg, level=0, fp=None):
Barry Warsaw8fa06b52002-07-09 02:39:07 +000018 """A handy debugging aid"""
Barry Warsawd4385742002-07-19 22:21:47 +000019 if fp is None:
20 fp = sys.stdout
Barry Warsaw8fa06b52002-07-09 02:39:07 +000021 tab = ' ' * (level * 4)
Barry Warsawd4385742002-07-19 22:21:47 +000022 print >> fp, tab + msg.get_type(msg.get_default_type())
Barry Warsaw8fa06b52002-07-09 02:39:07 +000023 if msg.is_multipart():
24 for subpart in msg.get_payload():
Barry Warsawd4385742002-07-19 22:21:47 +000025 _structure(subpart, level+1, fp)