diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2019-06-21 15:19:41 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2019-06-21 15:19:53 -0400 |
commit | 7f5a6c3f6d15876b7a2a7b298de14d8d807efad2 (patch) | |
tree | 8a30a7f3fc1f0554d2b79501a344eaaf254ffc47 /paramiko/ssh_exception.py | |
parent | e780a781418c4cd6b6bed7ff3427393886d95d55 (diff) | |
download | paramiko-7f5a6c3f6d15876b7a2a7b298de14d8d807efad2.tar.gz |
Enhancements to #1460
- Modern style string formatting please
- Make more sensible use of object attributes, where it can be done backwards incompatibly
- Gussy up the string output to my personal taste
- Add tests
Diffstat (limited to 'paramiko/ssh_exception.py')
-rw-r--r-- | paramiko/ssh_exception.py | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/paramiko/ssh_exception.py b/paramiko/ssh_exception.py index fc71ae2a..77b9efda 100644 --- a/paramiko/ssh_exception.py +++ b/paramiko/ssh_exception.py @@ -58,14 +58,18 @@ class BadAuthenticationType(AuthenticationException): allowed_types = [] + # TODO 3.0: remove explanation kwarg def __init__(self, explanation, types): + # TODO 3.0: remove this supercall unless it's actually required for + # pickling (after fixing pickling) AuthenticationException.__init__(self, explanation, types) + self.explanation = explanation self.allowed_types = types def __str__(self): - msg = "Bad authentication type, allowed types: " - msg += ",".join(self.allowed_types) - return msg + return "{}; allowed types: {!r}".format( + self.explanation, self.allowed_types + ) class PartialAuthentication(AuthenticationException): @@ -80,9 +84,9 @@ class PartialAuthentication(AuthenticationException): self.allowed_types = types def __str__(self): - msg = "Partial authentication, allowed types: " - msg += ",".join(self.allowed_types) - return msg + return "Partial authentication; allowed types: {!r}".format( + self.allowed_types + ) class ChannelException(SSHException): @@ -97,9 +101,10 @@ class ChannelException(SSHException): def __init__(self, code, text): SSHException.__init__(self, code, text) self.code = code + self.text = text def __str__(self): - return "ChannelException: %s, %s" % self.args + return "ChannelException({!r}, {!r})".format(self.code, self.text) class BadHostKeyException(SSHException): @@ -120,9 +125,12 @@ class BadHostKeyException(SSHException): self.expected_key = expected_key def __str__(self): - return "Host key for server %s does not match: got %s, expected %s" % ( + msg = ( + "Host key for server {!r} does not match: got {!r}, expected {!r}" + ) # noqa + return msg.format( self.hostname, - self.got_key.get_base64(), + self.key.get_base64(), self.expected_key.get_base64(), ) @@ -137,11 +145,12 @@ class ProxyCommandFailure(SSHException): def __init__(self, command, error): SSHException.__init__(self, command, error) + self.command = command self.error = error def __str__(self): - return ( - "ProxyCommand (%s) returned non-zero exit status: %s" % self.args + return 'ProxyCommand("{}") returned nonzero exit status: {}'.format( + self.command, self.error ) |