Mercurial > cpython-lru_cache-weakref
annotate Lib/email/Iterators.py @ 22939:534aab5bccea legacy-trunk
Sync'ing with standalone email package 2.0.1. This adds support for
non-us-ascii character sets in headers and bodies. Some API changes
(with DeprecationWarnings for the old APIs). Better RFC-compliant
implementations of base64 and quoted-printable.
Updated test cases. Documentation updates to follow (after I finish
writing them ;).
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Wed, 10 Apr 2002 21:01:31 +0000 |
| parents | 518e30f90d1f |
| children | 077d44b0405b |
| rev | line source |
|---|---|
|
22939
534aab5bccea
Sync'ing with standalone email package 2.0.1. This adds support for
Barry Warsaw <barry@python.org>
parents:
20426
diff
changeset
|
1 # Copyright (C) 2001,2002 Python Software Foundation |
|
20042
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(): |
|
20426
518e30f90d1f
typed_subpart_iterator(): When getting the main type use 'text' as the
Barry Warsaw <barry@python.org>
parents:
20253
diff
changeset
|
31 if subpart.get_main_type('text') == maintype: |
|
518e30f90d1f
typed_subpart_iterator(): When getting the main type use 'text' as the
Barry Warsaw <barry@python.org>
parents:
20253
diff
changeset
|
32 if subtype is None or subpart.get_subtype('plain') == subtype: |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
33 yield subpart |
