diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2014-03-05 17:03:37 -0800 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2014-03-05 17:03:37 -0800 |
commit | b2be63ec623b5944f9b84cac8b8f41aeb2b42fb7 (patch) | |
tree | 389e17b0c08cd34872a2e3afbc34860ab44fb3ed /paramiko/client.py | |
parent | bd61c7c0a9a4a2020d0acfb6a01e9ec85bb43b8e (diff) | |
parent | ae078f51d622931954e47e78029a889c4e721a05 (diff) | |
download | paramiko-b2be63ec623b5944f9b84cac8b8f41aeb2b42fb7.tar.gz |
Merge remote-tracking branch 'scottkmaxwell/py3-support-without-py25' into python3
Conflicts:
dev-requirements.txt
paramiko/__init__.py
paramiko/file.py
paramiko/hostkeys.py
paramiko/message.py
paramiko/proxy.py
paramiko/server.py
paramiko/transport.py
paramiko/util.py
paramiko/win_pageant.py
setup.py
Diffstat (limited to 'paramiko/client.py')
-rw-r--r-- | paramiko/client.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/paramiko/client.py b/paramiko/client.py index b5929e6e..2bb7c4bc 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -132,11 +132,10 @@ class SSHClient (object): if self._host_keys_filename is not None: self.load_host_keys(self._host_keys_filename) - f = open(filename, 'w') - for hostname, keys in self._host_keys.iteritems(): - for keytype, key in keys.iteritems(): + with open(filename, 'w') as f: + for hostname, keys in self._host_keys.items(): + for keytype, key in keys.items(): f.write('%s %s %s\n' % (hostname, keytype, key.get_base64())) - f.close() def get_host_keys(self): """ @@ -266,7 +265,7 @@ class SSHClient (object): if key_filename is None: key_filenames = [] - elif isinstance(key_filename, (str, unicode)): + elif isinstance(key_filename, string_types): key_filenames = [ key_filename ] else: key_filenames = key_filename @@ -310,8 +309,8 @@ class SSHClient (object): chan.settimeout(timeout) chan.exec_command(command) stdin = chan.makefile('wb', bufsize) - stdout = chan.makefile('rb', bufsize) - stderr = chan.makefile_stderr('rb', bufsize) + stdout = chan.makefile('r', bufsize) + stderr = chan.makefile_stderr('r', bufsize) return stdin, stdout, stderr def invoke_shell(self, term='vt100', width=80, height=24, width_pixels=0, @@ -377,7 +376,7 @@ class SSHClient (object): two_factor = (allowed_types == ['password']) if not two_factor: return - except SSHException, e: + except SSHException as e: saved_exception = e if not two_factor: @@ -391,7 +390,7 @@ class SSHClient (object): if not two_factor: return break - except SSHException, e: + except SSHException as e: saved_exception = e if not two_factor and allow_agent: @@ -407,7 +406,7 @@ class SSHClient (object): if not two_factor: return break - except SSHException, e: + except SSHException as e: saved_exception = e if not two_factor: @@ -439,17 +438,15 @@ class SSHClient (object): if not two_factor: return break - except SSHException, e: - saved_exception = e - except IOError, e: + except (SSHException, IOError) as e: saved_exception = e if password is not None: try: self._transport.auth_password(username, password) return - except SSHException, e: - saved_exception = e + except SSHException: + saved_exception = sys.exc_info()[1] elif two_factor: raise SSHException('Two-factor authentication requires a password') |