Skip to content

Commit fa7403a

Browse files
introduced six for py2 and py3 support
1 parent a0f7e2f commit fa7403a

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

hexonet/apiconnector/connection.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
import urllib
1+
from six.moves.urllib import request
2+
from six.moves import urlparse
23
import apiconnector.util
34
from apiconnector.response import Response
4-
try:
5-
# For Python 3.0 and later
6-
from urllib.request import urlopen
7-
except ImportError:
8-
# Fall back to Python 2's urllib2
9-
from urllib2 import urlopen
10-
try:
11-
# For Python 3.0 and later
12-
from urllib import parse as urlparse
13-
except ImportError:
14-
# Fall back to Python 2
15-
from urlparse import urlparse
16-
175

186
"""
197
APICONNECTOR Connection
@@ -46,7 +34,7 @@ def call_raw_http(self, command, config=None):
4634

4735
post['s_command'] = apiconnector.util.command_encode(command)
4836
post = urlparse.urlencode(post)
49-
response = urlopen(self._config['url'], post.encode('UTF-8'))
37+
response = request.urlopen(self._config['url'], post.encode('UTF-8'))
5038
content = response.read()
5139
return content
5240

hexonet/apiconnector/util.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import re
2-
from datetime import datetime
32
import time
4-
try:
5-
# For Python 3.0 and later
6-
from urllib import parse as urlparse
7-
except ImportError:
8-
# Fall back to Python 2
9-
from urlparse import urlparse
103
import base64
4+
from six.moves import urlparse
5+
from datetime import datetime
116

127

138
def command_encode(command):

0 commit comments

Comments
 (0)