durusmail: qp: Minor Python 3.2 related patches for qp, qpy
Minor Python 3.2 related patches for qp, qpy
2011-03-13
Michael Watkins (3 parts)
2011-03-13
2011-03-13
2011-03-13
Minor Python 3.2 related patches for qp, qpy
Michael Watkins
2011-03-13
Before diving into the two attached patches, I wanted to note that
installation runs across a name conflict between the Python lib http package
and the qp.http package. This is is a Python 3.x issue.

Ran across the following when trying to update an app running on 3.1 to Python
3.2:

qpy.compile.compile -- added a do-nothing kw argument ``optimize=-1``; as of
Python 3.2
builtins.compile supports the argument and the Python lib module py_compile
makes a call to builtins.compile passing the argument.

qp.email.rfc822_mailbox -- make encode_header ensure that strings passed to
Python lib email.header.Header() include a newline.

Maybe this is a bug in the Python lib module, maybe it was intentional
(doubtful), but a change in 3.2 over 3.1 gives rise to this trip up when
supplying the Header constructor an empty string '' (as is done in the qp
rfc822_mailbox module):

3.1 email.header.Header.encode - ok with '' passed

   for string, charset in self._chunks:
        lines = string.splitlines()
        for line in lines:
            formatter.feed(line, charset)

3.2 email.header.encode - not ok with ''

    for string, charset in self._chunks:
        lines = string.splitlines()
        formatter.feed(lines[0], charset)

                             ^ ouch

    i.e.
    >>> ''.splitlines()
    []
    >>> ''.splitlines()[0]
    Traceback (most recent call last):
      File "", line 1, in 
    IndexError: list index out of range


I see a similar traceback in this reported issue
http://bugs.python.org/issue11401

Anyway... I'm not sure what the right behaviour is, but the attached patch
ensures that common use like an empty subject line being passed to Header()
doesn't raise an IndexError.

Stuff attached,

Mike
reply