Use six to patch HTTPMessage so that it works on Python 2 and Python 3

This commit is contained in:
Jason R. Coombs 2014-06-08 10:42:42 +01:00
parent ffffe5411e
commit b57a27da28
3 changed files with 21 additions and 0 deletions

View File

@ -15,6 +15,9 @@ setup_params = dict(
url="https://bitbucket.org/jaraco/wolframalpha", url="https://bitbucket.org/jaraco/wolframalpha",
packages=setuptools.find_packages(), packages=setuptools.find_packages(),
zip_safe=False, zip_safe=False,
install_requires=[
'six',
],
setup_requires=[ setup_requires=[
'hgtools', 'hgtools',
'pytest-runner', 'pytest-runner',

View File

@ -7,6 +7,10 @@ except ImportError:
from xml.etree import ElementTree as etree from xml.etree import ElementTree as etree
from . import compat
compat.fix_HTTPMessage()
class Result(object): class Result(object):
def __init__(self, stream): def __init__(self, stream):
self.tree = etree.parse(stream) self.tree = etree.parse(stream)

14
wolframalpha/compat.py Normal file
View File

@ -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