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 "<stdin>", line 1, in <module>
    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
diff -r 0daabcdc0340 compile.py
--- a/compile.py	Tue Nov 10 10:39:47 2009 -0800
+++ b/compile.py	Sat Mar 12 16:38:59 2011 -0800
@@ -134,12 +134,12 @@
             if self.template_type_stack[-1] == 'xml':
                 return_accumulation = deepcopy(self.return_xml)
                 # trim __xml_template__
-                function_name_node[1] = function_name_node[1][:-16] 
+                function_name_node[1] = function_name_node[1][:-16]
             else:
                 assert self.template_type_stack[-1] == 'str'
                 return_accumulation = deepcopy(self.return_str)
-                # trim __str_template__                
-                function_name_node[1] = function_name_node[1][:-16] 
+                # trim __str_template__
+                function_name_node[1] = function_name_node[1][:-16]
             func_suite.insert(-1, return_accumulation)
         elif (self.template_type_stack[-1] == 'xml' and
             node[0] == symbol.power and
@@ -151,8 +151,8 @@
             # xml_power looks like
             # [power
             #     [atom [STRING "_qpy_xml" 1]
-            #     [trailer 
-            #         LPAR ... 
+            #     [trailer
+            #         LPAR ...
             #         [arglist ... [power [atom [STRING "X"]]]]
             #         RPAR]]]
             argument = get_argument(xml_power)
@@ -210,7 +210,10 @@
     output_name = splitext(source_name)[0] + ".pyc"
     builtins_compile = builtins.compile
     try:
-        def qpycompile(source, source_name, extra='exec'):
+        # added the do-nothing kwarg ``optimize`` to avoid missing keyword
+        # argument complaints caused by other callers of builtins.compile.
+        # -1 supplied as default value per conventions in Python lib modules.
+        def qpycompile(source, source_name, extra='exec', optimize=-1):
             assert extra == 'exec'
             return get_code(source, source_name)
         builtins.compile = qpycompile
diff -r faca3f5c1848 mail/rfc822_mailbox.py
--- a/mail/rfc822_mailbox.py	Tue Nov 10 10:41:41 2009 -0800
+++ b/mail/rfc822_mailbox.py	Fri Mar 11 13:41:18 2011 -0800
@@ -18,6 +18,8 @@
 decode_header # quiet checker.
 
 def encode_header(s):
+    if s == '':
+        s += '\n'
     return Header(stringify(s)).encode()
 
 class RFC822Mailbox:
_______________________________________________
QP mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/qp

Reply via email to