models: Fix HeaderParser import on python 2.4

Submitted by Jeremy Kerr on Nov. 2, 2010, 5:27 p.m.

Details

Message ID 1288718864.959701.564729447181.1.gpush@pororo
State Accepted
Headers show

Commit Message

Jeremy Kerr Nov. 2, 2010, 5:27 p.m.
We need to add an import for HeaderParser on python 2.4; email.Parser
appears to contain the right stuff.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

---
 apps/patchwork/models.py |    1 +
 1 file changed, 1 insertion(+)

Comments

Sabuj Pattanayek Nov. 8, 2010, 8 p.m.
Hi,

I applied the patch, actually ran git pull (saw that the new models.py
hadd your additions), then manage.py syncdb (verified that the new
entries went into patchwork_patch, e.g. pull_url), then restarted
httpd, but still getting the headerparser import error when clicking
the mbox link for a patch :

Environment:

Request Method: GET
Request URL: http://patchwork.meilerlab.org/patch/313/mbox/
Django Version: 1.2 SVN-14395
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'patchwork',
 'registration']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware')


Traceback:
File "/blue/meilerlab/home/patchwork/lib/python/django/core/handlers/base.py"
in get_response
  100.                     response = callback(request,
*callback_args, **callback_kwargs)
File "/blue/meilerlab/home/patchwork/apps/patchwork/views/patch.py" in mbox
  123.     response.write(patch.mbox().as_string(True))
File "/blue/meilerlab/home/patchwork/apps/patchwork/models.py" in mbox
  277.         orig_headers = HeaderParser().parsestr(str(self.headers))

Exception Type: NameError at /patch/313/mbox/
Exception Value: global name 'HeaderParser' is not defined

Thanks,
Sabuj

On Tue, Nov 2, 2010 at 12:27 PM, Jeremy Kerr <jk@ozlabs.org> wrote:
> We need to add an import for HeaderParser on python 2.4; email.Parser
> appears to contain the right stuff.
>
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
>
> ---
>  apps/patchwork/models.py |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
> index edb52df..6842622 100644
> --- a/apps/patchwork/models.py
> +++ b/apps/patchwork/models.py
> @@ -38,6 +38,7 @@ except ImportError:
>     # Python 2.4 compatibility
>     from email.MIMENonMultipart import MIMENonMultipart
>     from email.Encoders import encode_7or8bit
> +    from email.Parser import HeaderParser
>     import email.Utils
>     email.utils = email.Utils
>
>
Sabuj Pattanayek Nov. 8, 2010, 9:32 p.m.
btw, did test that the new imports work in python 2.4, just some other
error in scope somewhere?

> Traceback:
> File "/blue/meilerlab/home/patchwork/lib/python/django/core/handlers/base.py"
> in get_response
>  100.                     response = callback(request,
> *callback_args, **callback_kwargs)
> File "/blue/meilerlab/home/patchwork/apps/patchwork/views/patch.py" in mbox
>  123.     response.write(patch.mbox().as_string(True))
> File "/blue/meilerlab/home/patchwork/apps/patchwork/models.py" in mbox
>  277.         orig_headers = HeaderParser().parsestr(str(self.headers))
>
> Exception Type: NameError at /patch/313/mbox/
> Exception Value: global name 'HeaderParser' is not defined
Jeremy Kerr Nov. 8, 2010, 10:48 p.m.
Hi Sabuj,

> I applied the patch, actually ran git pull

The git repo does not include this change, you'll need to apply the patch 
manually.

Or did you do that?

Regards,


Jeremy
Sabuj Pattanayek Nov. 8, 2010, 10:55 p.m.
>> I applied the patch, actually ran git pull
>
> The git repo does not include this change, you'll need to apply the patch
> manually.

Ahh, I took a quick glance at the changes in models.py after git pull,
saw "Python 2.4 compatibility" and thought that you had merged it .
Seems like the git pull was basically just missing the one line :

from email.Parser import HeaderParser

After adding that line, the mbox link now works .
Jeremy Kerr Nov. 9, 2010, 12:20 a.m.
Hi Sabuj,

> After adding that line, the mbox link now works .

OK, thanks for testing. I've committed this patch.

Regards,


Jeremy

Patch hide | download patch | download mbox

diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index edb52df..6842622 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -38,6 +38,7 @@  except ImportError:
     # Python 2.4 compatibility
     from email.MIMENonMultipart import MIMENonMultipart
     from email.Encoders import encode_7or8bit
+    from email.Parser import HeaderParser
     import email.Utils
     email.utils = email.Utils