Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue14740] get_payload(n, True) returns None

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

May 7, 2012, 6:36 AM

Post #1 of 3 (52 views)
Permalink
[issue14740] get_payload(n, True) returns None

New submission from Bob Glickstein <bob.glickstein [at] gmail>:

Passing both a value for i and decode=True to email.message.Message.get_payload(), when self is a multipart, returns None when it should return a string. The reason is that an is_multipart() test is done on self when it should instead be done on the selected payload part. Here's a patch that fixes this:


--- /usr/lib64/python2.7/email/message.py 2011-10-26 18:40:36.000000000 -0700
+++ /home/bobg/tmp/message.py 2012-05-07 06:34:28.579401481 -0700
@@ -192,9 +192,9 @@
else:
payload = self._payload[i]
if decode:
- if self.is_multipart():
+ if payload.is_multipart():
return None
- cte = self.get('content-transfer-encoding', '').lower()
+ cte = payload.get('content-transfer-encoding', '').lower()
if cte == 'quoted-printable':
return utils._qdecode(payload)
elif cte == 'base64':

----------
components: Library (Lib)
messages: 160144
nosy: Bob.Glickstein
priority: normal
severity: normal
status: open
title: get_payload(n, True) returns None
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14740>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 7, 2012, 6:37 AM

Post #2 of 3 (47 views)
Permalink
[issue14740] get_payload(n, True) returns None [In reply to]

Bob Glickstein <bob.glickstein [at] gmail> added the comment:

Incidentally, a workaround is:

msg.get_payload(n).get_payload(decode=True)

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14740>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 7, 2012, 6:57 AM

Post #3 of 3 (46 views)
Permalink
[issue14740] get_payload(n, True) returns None [In reply to]

R. David Murray <rdmurray [at] bitdance> added the comment:

Thanks for the report and patch suggestion, but...

This is actually the way it is designed to work. get_payload(i) returns the ith element of a multipart payload. Your workaround is in fact the correct way to do this operation. decode=True is documented to return None if is_multipart is True.

You will note that if decode=False, you get back the Message sub-object, not a string. Since decoding a Message object (as opposed to its payload) is not a meaningful operation, None is returned for decode=True. Arguably we should raise a TypeError or ValueError instead, but we don't for historical reasons.

----------
nosy: +r.david.murray
resolution: -> invalid
stage: -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14740>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.