Skip to content

Commit 11351aa

Browse files
refactor(pkg): python 2 support removal
BREAKING CHANGE: drop python 2 support
1 parent fc9143b commit 11351aa

File tree

9 files changed

+49
-56
lines changed

9 files changed

+49
-56
lines changed

Diff for: .travis.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: python
2-
dist: trusty
2+
dist: xenial
33
notifications:
44
email:
55
recipients:
@@ -12,8 +12,10 @@ notifications:
1212
on_success: always
1313
on_failure: always
1414
python:
15-
- '2.7'
15+
- '3.4'
16+
- '3.5'
1617
- '3.6'
18+
- '3.7'
1719
cache:
1820
directories:
1921
- "~/.npm"

Diff for: hexonet/apiconnector/apiclient.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
from hexonet.apiconnector.response import Response
1212
from hexonet.apiconnector.responsetemplatemanager import ResponseTemplateManager as RTM
1313
from hexonet.apiconnector.socketconfig import SocketConfig
14-
from six.moves.urllib.parse import quote, unquote
15-
from six import string_types
14+
from urllib.parse import quote, unquote, urlparse, urlencode
15+
from urllib.request import urlopen, Request
1616
import re
17-
from six.moves.urllib.request import urlopen, Request
18-
from six.moves.urllib.parse import urlparse, urlencode
1917
import copy
2018
import platform
2119

@@ -57,8 +55,8 @@ def getPOSTData(self, cmd):
5755
"""
5856
data = self.__socketConfig.getPOSTData()
5957
tmp = ""
60-
if not isinstance(cmd, string_types):
61-
for key in cmd.keys():
58+
if not isinstance(cmd, str):
59+
for key in sorted(cmd.keys()):
6260
if (cmd[key] is not None):
6361
tmp += ("{0}={1}\n").format(key, re.sub('[\r\n]', '', str(cmd[key])))
6462
return ("{0}{1}={2}").format(data, quote('s_command'), quote(re.sub('\n$', '', tmp)))
@@ -216,11 +214,11 @@ def request(self, cmd):
216214
})
217215
body = urlopen(req, timeout=self.__socketTimeout).read()
218216
if (self.__debugMode):
219-
print(self.__socketURL, data, body, '\n', '\n')
217+
print((self.__socketURL, data, body, '\n', '\n'))
220218
except Exception:
221219
body = rtm.getTemplate("httperror").getPlain()
222220
if (self.__debugMode):
223-
print(self.__socketURL, data, "HTTP communication failed", body, '\n', '\n')
221+
print((self.__socketURL, data, "HTTP communication failed", body, '\n', '\n'))
224222
return Response(body, cmd)
225223

226224
def requestNextResponsePage(self, rr):
@@ -293,6 +291,6 @@ def __toUpperCaseKeys(self, cmd):
293291
Translate all command parameter names to uppercase
294292
"""
295293
newcmd = {}
296-
for k in cmd.keys():
294+
for k in list(cmd.keys()):
297295
newcmd[k.upper()] = cmd[k]
298296
return newcmd

Diff for: hexonet/apiconnector/response.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, raw, cmd=None):
3737

3838
h = self.getHash()
3939
if ("PROPERTY" in h):
40-
colKeys = h["PROPERTY"].keys()
40+
colKeys = list(h["PROPERTY"].keys())
4141
count = 0
4242
for c in colKeys:
4343
d = h["PROPERTY"][c]

Diff for: hexonet/apiconnector/responsetemplatemanager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def getTemplates(self):
7070
Return all available response templates
7171
"""
7272
tpls = {}
73-
for key in self.__templates.keys():
73+
for key in list(self.__templates.keys()):
7474
tpls[key] = RT(self.__templates[key])
7575
return tpls
7676

Diff for: hexonet/apiconnector/socketconfig.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:license: MIT, see LICENSE for more details.
99
"""
1010

11-
from six.moves.urllib.parse import quote, unquote
11+
from urllib.parse import quote, unquote
1212

1313

1414
class SocketConfig(object):

Diff for: requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ m2r==0.2.1
55
pep8==1.7.1
66
pycodestyle==2.5.0
77
-e git://github.com/pytest-dev/pytest-cov@master#egg=pytestcov
8-
six==1.12.0
98
Sphinx==1.8.5
109
sphinxcontrib-log-cabinet==1.0.0
1110
sphinxcontrib-websupport==1.1.0

Diff for: scripts/coverage.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
rm -rf .pytest_cache htmlcov tests/__pycache___
3-
py.test --strict --cov-report html --cov=hexonet.apiconnector --cache-clear -v
3+
py.test --strict --cov-report html --cache-clear -v
44
# NOTE: this does not use the current repository
55
# it uses the last released version's source code
66
# maybe this can be reviewed - but not sure if this is possible

Diff for: setup.py

-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def find_version(*file_paths):
4242
url='https://github.com/hexonet/python-sdk/',
4343
install_require=[
4444
'autopep8',
45-
'six',
4645
'guzzle_sphinx_theme',
4746
'pycodestyle',
4847
'sphinx',
@@ -51,7 +50,6 @@ def find_version(*file_paths):
5150
],
5251
setup_requires=[
5352
'autopep8',
54-
'six',
5553
'guzzle_sphinx_theme',
5654
'pycodestyle',
5755
'sphinx',
@@ -63,7 +61,6 @@ def find_version(*file_paths):
6361
scripts=[],
6462
zip_safe=True,
6563
classifiers=(
66-
"Programming Language :: Python :: 2",
6764
"Programming Language :: Python :: 3",
6865
"License :: OSI Approved :: MIT License",
6966
"Operating System :: OS Independent"

Diff for: tests/test_apiclient.py

+34-37
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ def test_apiclientmethods():
1010
rtm = RTM.getInstance()
1111
rtm.addTemplate(
1212
'login200',
13-
'[RESPONSE]\r\nPROPERTY[SESSION][0]=h8JLZZHdF2WgWWXlwbKWzEG3XrzoW4y'
14-
+ 'shhvtqyg0LCYiX55QnhgYX9cB0W4mlpbx\r\nDESCRIPTION=Command completed'
15-
+ ' successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.169\r\nEOF\r'
16-
+ '\n'
13+
'[RESPONSE]\r\nPROPERTY[SESSION][0]=h8JLZZHdF2WgWWXlwbKWzEG3XrzoW4y' +
14+
'shhvtqyg0LCYiX55QnhgYX9cB0W4mlpbx\r\nDESCRIPTION=Command completed' +
15+
' successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.169\r\nEOF\r' +
16+
'\n'
1717
)
1818
rtm.addTemplate(
1919
'login500',
@@ -25,50 +25,50 @@ def test_apiclientmethods():
2525
)
2626
rtm.addTemplate(
2727
'listP0',
28-
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=2701\r\nPROPERTY[FIRST][0]=0\r\nP'
29-
+ 'ROPERTY[DOMAIN][0]=0-60motorcycletimes.com\r\nPROPERTY[DOMAIN][1]='
30-
+ '0-be-s01-0.com\r\nPROPERTY[COUNT][0]=2\r\nPROPERTY[LAST][0]=1\r\nP'
31-
+ 'ROPERTY[LIMIT][0]=2\r\nDESCRIPTION=Command completed successfully'
32-
+ '\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.023\r\nEOF\r\n'
28+
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=2701\r\nPROPERTY[FIRST][0]=0\r\nP' +
29+
'ROPERTY[DOMAIN][0]=0-60motorcycletimes.com\r\nPROPERTY[DOMAIN][1]=' +
30+
'0-be-s01-0.com\r\nPROPERTY[COUNT][0]=2\r\nPROPERTY[LAST][0]=1\r\nP' +
31+
'ROPERTY[LIMIT][0]=2\r\nDESCRIPTION=Command completed successfully' +
32+
'\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.023\r\nEOF\r\n'
3333
)
3434
rtm.addTemplate(
3535
'listP1',
36-
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=2701\r\nPROPERTY[FIRST][0]=2\r\nP'
37-
+ 'ROPERTY[DOMAIN][0]=0-qas-ao17-0.org\r\nPROPERTY[DOMAIN][1]=0-sunny'
38-
+ 'da222y.com\r\nPROPERTY[COUNT][0]=2\r\nPROPERTY[LAST][0]=3\r\nPROPE'
39-
+ 'RTY[LIMIT][0]=2\r\nDESCRIPTION=Command completed successfully\r\nC'
40-
+ 'ODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.032\r\nEOF\r\n'
36+
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=2701\r\nPROPERTY[FIRST][0]=2\r\nP' +
37+
'ROPERTY[DOMAIN][0]=0-qas-ao17-0.org\r\nPROPERTY[DOMAIN][1]=0-sunny' +
38+
'da222y.com\r\nPROPERTY[COUNT][0]=2\r\nPROPERTY[LAST][0]=3\r\nPROPE' +
39+
'RTY[LIMIT][0]=2\r\nDESCRIPTION=Command completed successfully\r\nC' +
40+
'ODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.032\r\nEOF\r\n'
4141
)
4242
rtm.addTemplate(
4343
'listFP0',
44-
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=3\r\nPROPERTY[FIRST][0]=0\r\nPROP'
45-
+ 'ERTY[DOMAIN][0]=0-60motorcycletimes.com\r\nPROPERTY[COUNT][0]=1\r'
46-
+ '\nPROPERTY[LAST][0]=1\r\nPROPERTY[LIMIT][0]=1\r\nDESCRIPTION=Comma'
47-
+ 'nd completed successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.'
48-
+ '023\r\nEOF\r\n'
44+
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=3\r\nPROPERTY[FIRST][0]=0\r\nPROP' +
45+
'ERTY[DOMAIN][0]=0-60motorcycletimes.com\r\nPROPERTY[COUNT][0]=1\r' +
46+
'\nPROPERTY[LAST][0]=1\r\nPROPERTY[LIMIT][0]=1\r\nDESCRIPTION=Comma' +
47+
'nd completed successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.' +
48+
'023\r\nEOF\r\n'
4949
)
5050
rtm.addTemplate(
5151
'listFP1',
52-
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=3\r\nPROPERTY[FIRST][0]=1\r\nPROP'
53-
+ 'ERTY[DOMAIN][0]=0-be-s01-0.com\r\nPROPERTY[COUNT][0]=1\r\nPROPERTY'
54-
+ '[LAST][0]=2\r\nPROPERTY[LIMIT][0]=1\r\nDESCRIPTION=Command complet'
55-
+ 'ed successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.032\r\nEOF'
56-
+ '\r\n'
52+
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=3\r\nPROPERTY[FIRST][0]=1\r\nPROP' +
53+
'ERTY[DOMAIN][0]=0-be-s01-0.com\r\nPROPERTY[COUNT][0]=1\r\nPROPERTY' +
54+
'[LAST][0]=2\r\nPROPERTY[LIMIT][0]=1\r\nDESCRIPTION=Command complet' +
55+
'ed successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.032\r\nEOF' +
56+
'\r\n'
5757
)
5858
rtm.addTemplate(
5959
'listFP2',
60-
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=3\r\nPROPERTY[FIRST][0]=2\r\nPROP'
61-
+ 'ERTY[DOMAIN][0]=0-qas-ao17-0.org\r\nPROPERTY[COUNT][0]=2\r\nPROPER'
62-
+ 'TY[LAST][0]=3\r\nPROPERTY[LIMIT][0]=1\r\nDESCRIPTION=Command compl'
63-
+ 'eted successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.032\r\nE'
64-
+ 'OF\r\n'
60+
'[RESPONSE]\r\nPROPERTY[TOTAL][0]=3\r\nPROPERTY[FIRST][0]=2\r\nPROP' +
61+
'ERTY[DOMAIN][0]=0-qas-ao17-0.org\r\nPROPERTY[COUNT][0]=2\r\nPROPER' +
62+
'TY[LAST][0]=3\r\nPROPERTY[LIMIT][0]=1\r\nDESCRIPTION=Command compl' +
63+
'eted successfully\r\nCODE=200\r\nQUEUETIME=0\r\nRUNTIME=0.032\r\nE' +
64+
'OF\r\n'
6565
)
6666

6767
# #.getPOSTData()
6868
# test object input with special chars
6969
validate = (
70-
's_entity=54cd&s_command=COMMAND%3DModifyDomain%0AAUTH%3Dgwrgwqg%25'
71-
+ '%26%5C44t3%2A'
70+
's_entity=54cd&s_command=AUTH%3Dgwrgwqg%25' +
71+
'%26%5C44t3%2A%0ACOMMAND%3DModifyDomain'
7272
)
7373
enc = cl.getPOSTData({
7474
'COMMAND': 'ModifyDomain',
@@ -193,8 +193,7 @@ def test_apiclientmethods():
193193
'COMMAND': 'StatusAccount'
194194
})
195195
exp = (
196-
's_entity=54cd&s_remoteaddr=10.10.10.10&s_command=COMMAND%3DStatusA'
197-
+ 'ccount'
196+
's_entity=54cd&s_remoteaddr=10.10.10.10&s_command=COMMAND%3DStatusAccount'
198197
)
199198
assert tmp == exp
200199

@@ -212,8 +211,7 @@ def test_apiclientmethods():
212211
'COMMAND': 'StatusAccount'
213212
})
214213
exp = (
215-
's_entity=54cd&s_login=myaccountid&s_pw=mypassword&s_command=COMMAN'
216-
+ 'D%3DStatusAccount'
214+
's_entity=54cd&s_login=myaccountid&s_pw=mypassword&s_command=COMMAND%3DStatusAccount'
217215
)
218216
assert tmp == exp
219217

@@ -231,8 +229,7 @@ def test_apiclientmethods():
231229
'COMMAND': 'StatusAccount'
232230
})
233231
exp = (
234-
's_entity=54cd&s_login=myaccountid%21myroleid&s_pw=mypassword&s_com'
235-
+ 'mand=COMMAND%3DStatusAccount'
232+
's_entity=54cd&s_login=myaccountid%21myroleid&s_pw=mypassword&s_command=COMMAND%3DStatusAccount'
236233
)
237234
assert tmp == exp
238235

0 commit comments

Comments
 (0)