From b57a27da28857de656a9b9d68112e0c1eaf45670 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 8 Jun 2014 10:42:42 +0100 Subject: [PATCH] Use six to patch HTTPMessage so that it works on Python 2 and Python 3 --- setup.py | 3 +++ wolframalpha/__init__.py | 4 ++++ wolframalpha/compat.py | 14 ++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 wolframalpha/compat.py diff --git a/setup.py b/setup.py index 8a88889..b29bf3c 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,9 @@ setup_params = dict( url="https://bitbucket.org/jaraco/wolframalpha", packages=setuptools.find_packages(), zip_safe=False, + install_requires=[ + 'six', + ], setup_requires=[ 'hgtools', 'pytest-runner', diff --git a/wolframalpha/__init__.py b/wolframalpha/__init__.py index ca57430..c05eed3 100644 --- a/wolframalpha/__init__.py +++ b/wolframalpha/__init__.py @@ -7,6 +7,10 @@ except ImportError: from xml.etree import ElementTree as etree +from . import compat + +compat.fix_HTTPMessage() + class Result(object): def __init__(self, stream): self.tree = etree.parse(stream) diff --git a/wolframalpha/compat.py b/wolframalpha/compat.py new file mode 100644 index 0000000..be52d21 --- /dev/null +++ b/wolframalpha/compat.py @@ -0,0 +1,14 @@ +import six +from six.moves import http_client + +def fix_HTTPMessage(): + """ + Python 2 uses a deprecated method signature and doesn't provide the + forward compatibility. + Add it. + """ + if six.PY3: + return + + http_client.HTTPMessage.get_content_type = http_client.HTTPMessage.gettype + http_client.HTTPMessage.get_param = http_client.HTTPMessage.getparam