Revision 4ba5e843 ncclient/transport/error.py

b/ncclient/transport/error.py
12 12
# See the License for the specific language governing permissions and
13 13
# limitations under the License.
14 14

  
15
from ncclient import ClientError
15
from ncclient import TransportError
16 16

  
17
class SessionError(ClientError):
17
class SSHError(TransportError):
18 18
    pass
19 19

  
20
class SSHError(SessionError):
20
class SSHAuthenticationError(SSHError):
21 21
    pass
22 22

  
23 23
class SSHUnknownHostError(SSHError):
24 24
    
25 25
    def __init__(self, hostname, key):
26
        from binascii import hexlify
27
        SSHError(self, 'Unknown host key [%s] for [%s]'
28
                 % (hexlify(key.get_fingerprint()), hostname))
26 29
        self.hostname = hostname
27 30
        self.key = key
28 31
    
29
    def __str__(self):
30
        from binascii import hexlify
31
        return ('Unknown host key [%s] for [%s]' %
32
                (hexlify(self.key.get_fingerprint()), self.hostname))
33

  
34
class SSHAuthenticationError(SSHError):
35
    pass
36

  
37 32
class SSHSessionClosedError(SSHError):
38 33
    
39 34
    def __init__(self, in_buf, out_buf=None):
40
        SessionError.__init__(self, "Unexpected session close.")
41
        self._in_buf, self._out_buf = in_buf, out_buf
42
        
43
    def __str__(self):
44
        msg = SessionError(self).__str__()
45
        if self._in_buf:
46
            msg += '\nIN_BUFFER: %s' % self._in_buf
47
        if self._out_buf:
48
            msg += '\nOUT_BUFFER: %s' % self._out_buf
49
        return msg
35
        msg = 'Unexpected session close.'
36
        if in_buf:
37
            msg += '\nIN_BUFFER: %s' % in_buf
38
        if out_buf:
39
            msg += '\nOUT_BUFFER: %s' % out_buf
40
        SSHError.__init__(self, msg)

Also available in: Unified diff