Kaydet (Commit) 12dc230c authored tarafından Barry Warsaw's avatar Barry Warsaw

body_line_iterator(): Accept optional decode argument, pass through to

Message.get_payload().
üst 52b39f5b
......@@ -37,11 +37,14 @@ def _isstring(obj):
# These two functions are imported into the Iterators.py interface module.
# The Python 2.2 version uses generators for efficiency.
def body_line_iterator(msg):
"""Iterate over the parts, returning string payloads line-by-line."""
def body_line_iterator(msg, decode=False):
"""Iterate over the parts, returning string payloads line-by-line.
Optional decode (default False) is passed through to .get_payload().
"""
lines = []
for subpart in msg.walk():
payload = subpart.get_payload()
payload = subpart.get_payload(decode=decode)
if _isstring(payload):
for line in StringIO(payload).readlines():
lines.append(line)
......
......@@ -38,10 +38,13 @@ def _isstring(obj):
# These two functions are imported into the Iterators.py interface module.
# The Python 2.2 version uses generators for efficiency.
def body_line_iterator(msg):
"""Iterate over the parts, returning string payloads line-by-line."""
def body_line_iterator(msg, decode=False):
"""Iterate over the parts, returning string payloads line-by-line.
Optional decode (default False) is passed through to .get_payload().
"""
for subpart in msg.walk():
payload = subpart.get_payload()
payload = subpart.get_payload(decode=decode)
if _isstring(payload):
for line in StringIO(payload):
yield line
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment