Mercurial > cpython-lru_cache-weakref
annotate Lib/email/Iterators.py @ 20253:d96cd38a3fec legacy-trunk
Give me back my page breaks.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Thu, 04 Oct 2001 17:05:11 +0000 |
| parents | 5c4261e74478 |
| children | 518e30f90d1f |
| rev | line source |
|---|---|
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1 # Copyright (C) 2001 Python Software Foundation |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
2 # Author: barry@zope.com (Barry Warsaw) |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
3 |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
4 """Various types of useful iterators and generators. |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
5 """ |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
6 |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
7 from __future__ import generators |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
8 from cStringIO import StringIO |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
9 from types import StringType |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
10 |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
11 |
|
20253
d96cd38a3fec
Give me back my page breaks.
Barry Warsaw <barry@python.org>
parents:
20240
diff
changeset
|
12 |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
13 def body_line_iterator(msg): |
|
20102
6009d859fb57
Updated docstrings. Also,
Barry Warsaw <barry@python.org>
parents:
20042
diff
changeset
|
14 """Iterate over the parts, returning string payloads line-by-line.""" |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
15 for subpart in msg.walk(): |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
16 payload = subpart.get_payload() |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
17 if type(payload) is StringType: |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
18 for line in StringIO(payload): |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
19 yield line |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
20 |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
21 |
|
20253
d96cd38a3fec
Give me back my page breaks.
Barry Warsaw <barry@python.org>
parents:
20240
diff
changeset
|
22 |
|
20102
6009d859fb57
Updated docstrings. Also,
Barry Warsaw <barry@python.org>
parents:
20042
diff
changeset
|
23 def typed_subpart_iterator(msg, maintype='text', subtype=None): |
|
6009d859fb57
Updated docstrings. Also,
Barry Warsaw <barry@python.org>
parents:
20042
diff
changeset
|
24 """Iterate over the subparts with a given MIME type. |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
25 |
|
20102
6009d859fb57
Updated docstrings. Also,
Barry Warsaw <barry@python.org>
parents:
20042
diff
changeset
|
26 Use `maintype' as the main MIME type to match against; this defaults to |
|
6009d859fb57
Updated docstrings. Also,
Barry Warsaw <barry@python.org>
parents:
20042
diff
changeset
|
27 "text". Optional `subtype' is the MIME subtype to match against; if |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
28 omitted, only the main type is matched. |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
29 """ |
|
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
30 for subpart in msg.walk(): |
|
20102
6009d859fb57
Updated docstrings. Also,
Barry Warsaw <barry@python.org>
parents:
20042
diff
changeset
|
31 if subpart.get_main_type() == maintype: |
|
6009d859fb57
Updated docstrings. Also,
Barry Warsaw <barry@python.org>
parents:
20042
diff
changeset
|
32 if subtype is None or subpart.get_subtype() == subtype: |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
33 yield subpart |
