Skip to content

Commit 53106ad

Browse files
make compatible with python 3
1 parent 043998f commit 53106ad

8 files changed

Lines changed: 37 additions & 18 deletions

File tree

.coveragerc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[run]
22
source = hyperwallet
3-
omit = venv/*
4-
omit = hyperwallet/tests/*
3+
omit =
4+
venv/*
5+
hyperwallet/tests/*

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
1.1.2 (current)
5+
------------------
6+
7+
- Added bank card endpoint
8+
49
1.1.1 (2017-10-11)
510
------------------
611

hyperwallet/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__email__ = 'devsupport@hyperwallet.com'
77
__copyright__ = 'Copyright (c) 2017 Hyperwallet'
88
__license__ = 'MIT'
9-
__version__ = '1.1.1'
9+
__version__ = '1.1.2'
1010
__url__ = 'https://github.com/hyperwallet/python-sdk'
1111
__download_url__ = 'https://pypi.python.org/pypi/hyperwallet-sdk'
1212
__description__ = 'A Python wrapper around the Hyperwallet API'

hyperwallet/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import os
44

5-
from config import SERVER
6-
from exceptions import HyperwalletException
7-
from utils import ApiClient
5+
from .config import SERVER
6+
from .exceptions import HyperwalletException
7+
from .utils import ApiClient
88

99
from hyperwallet import (
1010
User,

hyperwallet/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ class HyperwalletException(Exception):
66
An Exception raised when the SDK is used incorrectly.
77
'''
88

9+
@property
10+
def message(self):
11+
return self.__dict__.get('message', None) or getattr(self, 'args')[0]
12+
913

1014
class HyperwalletAPIException(Exception):
1115
'''
1216
An Exception raised when the API response is an error.
1317
'''
18+
19+
@property
20+
def message(self):
21+
return self.__dict__.get('message', None) or getattr(self, 'args')[0]

hyperwallet/tests/test_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ def test_receive_valid_json_response(self, session_mock):
9191
content=json.dumps(data)
9292
)
9393

94+
encoded = json.dumps(data)
95+
if hasattr(encoded, 'decode'): # Python 2
96+
encoded = encoded.decode('utf-8')
97+
9498
self.assertEqual(
9599
self.client._makeRequest(),
96-
json.loads(json.dumps(data).decode('utf-8'))
100+
json.loads(encoded)
97101
)
98102

99103

hyperwallet/tests/test_models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import json
44
import unittest
5-
import hyperwallet
6-
7-
from hyperwallet.exceptions import HyperwalletException
85

96
from hyperwallet import (
107
HyperwalletModel,
@@ -374,7 +371,7 @@ def test_transfer_method_configuration_model(self):
374371
transfer_method_configuration_data
375372
)
376373

377-
print transfer_method_configuration_data.get('countries')
374+
print(transfer_method_configuration_data.get('countries'))
378375
self.assertEqual(
379376
test_transfer_method_configuration.__repr__(),
380377
'TransferMethodConfiguration({country}, {type})'.format(

hyperwallet/utils/apiclient.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env python
22

3-
import sys
43
import ssl
54
import json
6-
import urlparse
75
import requests
86

97
from hyperwallet.exceptions import HyperwalletAPIException
108
from requests_toolbelt.adapters.ssl import SSLAdapter
119
from hyperwallet import __version__
10+
try:
11+
from urllib.parse import urljoin
12+
except ImportError:
13+
from urlparse import urljoin # Python 2
1214

1315

1416
class ApiClient(object):
@@ -42,7 +44,7 @@ def __init__(self, username, password, server):
4244
self.server = server
4345

4446
# The complete base URL of the API.
45-
self.baseUrl = urlparse.urljoin(self.server, '/rest/v3/')
47+
self.baseUrl = urljoin(self.server, '/rest/v3/')
4648

4749
# The default connection to persist authentication and SSL settings.
4850
defaultSession = requests.Session()
@@ -81,7 +83,7 @@ def _makeRequest(self,
8183
try:
8284
response = self.session.request(
8385
method=method,
84-
url=urlparse.urljoin(self.baseUrl, url),
86+
url=urljoin(self.baseUrl, url),
8587
data=data,
8688
headers=headers,
8789
params=params
@@ -93,15 +95,17 @@ def _makeRequest(self,
9395
'code': 'COMMUNICATION_ERROR',
9496
'message': 'Connection to {} failed: {}'.format(
9597
self.server,
96-
e.message
98+
e.args[0]
9799
)
98100
}]
99101
})
100102

101103
if response.status_code is 204:
102104
return {}
103105

104-
content = response.content.decode('utf-8')
106+
content = response.content
107+
if hasattr(content, 'decode'): # Python 2
108+
content = content.decode('utf-8')
105109

106110
try:
107111
json_body = json.loads(content)
@@ -110,7 +114,7 @@ def _makeRequest(self,
110114
raise HyperwalletAPIException({
111115
'errors': [{
112116
'code': 'GARBAGE_RESPONSE',
113-
'message': 'Invalid response: {}'.format(e.message)
117+
'message': 'Invalid response: {}'.format(e.args[0])
114118
}]
115119
})
116120

0 commit comments

Comments
 (0)