From 71b1bb412db77f99dce4cf8969285a6bac404712 Mon Sep 17 00:00:00 2001 From: Torok Gabor Date: Thu, 13 Jul 2017 09:35:45 +0200 Subject: [PATCH 1/4] Make urlencode import Python 2/3 compatible --- Adyen/httpclient.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Adyen/httpclient.py b/Adyen/httpclient.py index 997f29f2..f6a50cb4 100644 --- a/Adyen/httpclient.py +++ b/Adyen/httpclient.py @@ -14,7 +14,13 @@ import urllib2 -from urllib import urlencode +try: + # Python 3 + from urllib.parse import urlencode +except ImportError: + # Python 2 + from urllib import urlencode + from StringIO import StringIO import json as json_lib import re From caef8d3087c8dd3f72ac96e826938f268318830e Mon Sep 17 00:00:00 2001 From: Torok Gabor Date: Thu, 13 Jul 2017 09:42:33 +0200 Subject: [PATCH 2/4] Make urllib2 import Python 2/3 compatible --- Adyen/httpclient.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Adyen/httpclient.py b/Adyen/httpclient.py index f6a50cb4..69a248c7 100644 --- a/Adyen/httpclient.py +++ b/Adyen/httpclient.py @@ -12,14 +12,15 @@ except ImportError: pycurl = None -import urllib2 - try: # Python 3 from urllib.parse import urlencode + from urllib.request import Request + from urllib.error import HTTPError except ImportError: # Python 2 from urllib import urlencode + from urllib2 import Request, urlopen, HTTPError from StringIO import StringIO import json as json_lib @@ -229,7 +230,7 @@ def _urllib_post(self, url, raw_store = json raw_request = json_lib.dumps(json) if json else urlencode(data) - url_request = urllib2.Request(url,data=raw_request) + url_request = Request(url,data=raw_request) if json: url_request.add_header('Content-Type','application/json') elif not data: @@ -254,8 +255,8 @@ def _urllib_post(self, url, #URLlib raises all non 200 responses as en error. try: - response = urllib2.urlopen(url_request, timeout=timeout) - except urllib2.HTTPError as e: + response = urlopen(url_request, timeout=timeout) + except HTTPError as e: raw_response = e.read() return raw_response, raw_request, e.getcode(), e.headers From 21dde655212ba57d56c3459cd91335becd40cdbf Mon Sep 17 00:00:00 2001 From: Torok Gabor Date: Thu, 13 Jul 2017 10:01:53 +0200 Subject: [PATCH 3/4] Make StringIO import Python 2/3 compatible --- Adyen/httpclient.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Adyen/httpclient.py b/Adyen/httpclient.py index 69a248c7..3e9543bc 100644 --- a/Adyen/httpclient.py +++ b/Adyen/httpclient.py @@ -22,7 +22,13 @@ from urllib import urlencode from urllib2 import Request, urlopen, HTTPError -from StringIO import StringIO +try: + # Python 3 + from io import StringIO +except ImportError: + # Python 2 + from StringIO import StringIO + import json as json_lib import re import base64 From 06049aa48020e978e4952b0ac6171a5035cb1dd9 Mon Sep 17 00:00:00 2001 From: Torok Gabor Date: Thu, 13 Jul 2017 10:03:58 +0200 Subject: [PATCH 4/4] Add missing urlopen import --- Adyen/httpclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adyen/httpclient.py b/Adyen/httpclient.py index 3e9543bc..a5c999d7 100644 --- a/Adyen/httpclient.py +++ b/Adyen/httpclient.py @@ -15,7 +15,7 @@ try: # Python 3 from urllib.parse import urlencode - from urllib.request import Request + from urllib.request import Request, urlopen from urllib.error import HTTPError except ImportError: # Python 2