Skip to content

Commit c061a34

Browse files
author
Dan
committed
Py3 compatibility changes for code, tests and embedded server. Updated travis config and setup.py to not use 2to3 anymore
1 parent 56ef8e9 commit c061a34

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*~
12
*.py[cod]
23

34
# C extensions

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ install:
1414
- pip install coveralls
1515
script:
1616
- python setup.py nosetests --with-coverage --cover-package=pssh
17-
# If using py3, run 2to3 on embedded server and tests and run nosetests for new test dir
18-
- python -c 'import sys; sys.version_info >= (3,) and sys.exit(1)' || eval "2to3 -nw embedded_server/*.py && 2to3 tests/*.py -o tests3 -nw && cp tests/test_client_private_key* tests3/ && python setup.py nosetests -w tests3 --with-coverage --cover-package=pssh"
1917
after_success:
2018
- coveralls
2119
deploy:

pssh/pssh_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939

4040
logger = logging.getLogger('pssh')
4141

42+
try:
43+
xrange
44+
except NameError:
45+
xrange = range
46+
4247

4348
class ParallelSSHClient(object):
4449
"""Uses :py:class:`pssh.ssh_client.SSHClient`, performs tasks over SSH on multiple hosts in \
@@ -731,7 +736,7 @@ def get_output(self, cmd, output, encoding='utf-8'):
731736
except IndexError as _ex:
732737
logger.error("Got exception with no host argument - "
733738
"cannot update output data with %s", _ex)
734-
raise exc[1], None, exc[2]
739+
raise exc[1]
735740
self._update_host_output(output, host, None, None, None, None, None, cmd,
736741
exception=ex)
737742
raise

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ versionfile_source = pssh/_version.py
55
tag_prefix = ''
66

77
[bdist_wheel]
8-
universal = 0
8+
universal = 1

setup.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1515

1616
from setuptools import setup, find_packages
17-
import sys
1817

1918
import versioneer
2019

21-
convert_2_to_3 = {}
22-
if sys.version_info >= (3,):
23-
convert_2_to_3['use_2to3'] = True
24-
2520
setup(name='parallel-ssh',
2621
version=versioneer.get_version(),
2722
cmdclass=versioneer.get_cmdclass(),
@@ -47,5 +42,4 @@
4742
'Operating System :: POSIX :: BSD',
4843
'Operating System :: Microsoft :: Windows',
4944
],
50-
**convert_2_to_3
5145
)

tests/test_pssh_client.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
pssh_logger.setLevel(logging.DEBUG)
4949
logging.basicConfig()
5050

51+
52+
try:
53+
xrange
54+
except NameError:
55+
xrange = range
56+
57+
5158
class ParallelSSHClientTest(unittest.TestCase):
5259

5360
def setUp(self):
@@ -280,7 +287,7 @@ def test_pssh_client_retries(self):
280287
self.assertRaises(ConnectionErrorException, client.run_command, 'blah')
281288
try:
282289
client.run_command('blah')
283-
except ConnectionErrorException, ex:
290+
except ConnectionErrorException as ex:
284291
num_tries = ex.args[-1:][0]
285292
self.assertEqual(expected_num_tries, num_tries,
286293
msg="Got unexpected number of retries %s - "
@@ -377,7 +384,7 @@ def test_pssh_client_copy_file_failure(self):
377384
test_file.write('testing\n')
378385
test_file.close()
379386
# Permission errors on writing into dir
380-
mask = 0111 if sys.version_info <= (2,) else 0o111
387+
mask = int('0111') if sys.version_info <= (2,) else 0o111
381388
os.chmod(remote_test_path, mask)
382389
client = ParallelSSHClient([self.host], port=self.listen_port,
383390
pkey=self.user_key)
@@ -692,7 +699,7 @@ def test_connection_error_exception(self):
692699
host,))
693700
try:
694701
raise output[host]['exception']
695-
except ConnectionErrorException, ex:
702+
except ConnectionErrorException as ex:
696703
self.assertEqual(ex.args[1], host,
697704
msg="Exception host argument is %s, should be %s" % (
698705
ex.args[1], host,))
@@ -717,7 +724,7 @@ def test_authentication_exception(self):
717724
self.host,))
718725
try:
719726
raise output[self.host]['exception']
720-
except AuthenticationException, ex:
727+
except AuthenticationException as ex:
721728
self.assertEqual(ex.args[1], self.host,
722729
msg="Exception host argument is %s, should be %s" % (
723730
ex.args[1], self.host,))
@@ -744,7 +751,7 @@ def test_ssh_exception(self):
744751
host,))
745752
try:
746753
raise output[host]['exception']
747-
except SSHException, ex:
754+
except SSHException as ex:
748755
self.assertEqual(ex.args[1], host,
749756
msg="Exception host argument is %s, should be %s" % (
750757
ex.args[1], host,))
@@ -824,7 +831,7 @@ def test_host_config(self):
824831
self.assertTrue(host in output)
825832
try:
826833
raise output[hosts[1]]['exception']
827-
except AuthenticationException, ex:
834+
except AuthenticationException as ex:
828835
pass
829836
else:
830837
raise AssertionError("Expected AutnenticationException on host %s",
@@ -952,11 +959,15 @@ def test_ssh_client_utf_encoding(self):
952959
client = ParallelSSHClient([self.host], port=server_port,
953960
pkey=self.user_key)
954961
# File is already set to utf-8, cannot use utf-16 only representations
955-
# Using ascii characters encoded as utf-16 instead
962+
# Using ascii characters decoded as utf-16 on py2
963+
# and utf-8 encoded ascii decoded to utf-16 on py3
956964
output = client.run_command(self.fake_cmd, encoding='utf-16')
957965
stdout = list(output[self.host]['stdout'])
958-
# import ipdb; ipdb.set_trace()
959-
self.assertEqual([self.fake_resp.decode('utf-16')], stdout)
966+
if type(self.fake_resp) == bytes:
967+
self.assertEqual([self.fake_resp.decode('utf-16')], stdout)
968+
else:
969+
self.assertEqual([self.fake_resp.encode('utf-8').decode('utf-16')],
970+
stdout)
960971

961972
def test_pty(self):
962973
cmd = "exit 0"

0 commit comments

Comments
 (0)