blob: 3ecd632ecf32253cc8aca9efe4ac436fab6ba09d [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 Warsaw1f84ff12002-10-01 00:51:47 +000017def _structure(msg, fp=None, level=0):
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 Warsawa4ce1cf2002-09-01 21:04:43 +000022 print >> fp, tab + msg.get_content_type()
Barry Warsaw8fa06b52002-07-09 02:39:07 +000023 if msg.is_multipart():
24 for subpart in msg.get_payload():
Barry Warsaw1f84ff12002-10-01 00:51:47 +000025 _structure(subpart, fp, level+1)