Package paramiko :: Module ssh_exception
[frames] | no frames]

Source Code for Module paramiko.ssh_exception

  1  # Copyright (C) 2003-2007  Robey Pointer <robeypointer@gmail.com> 
  2  # 
  3  # This file is part of paramiko. 
  4  # 
  5  # Paramiko is free software; you can redistribute it and/or modify it under the 
  6  # terms of the GNU Lesser General Public License as published by the Free 
  7  # Software Foundation; either version 2.1 of the License, or (at your option) 
  8  # any later version. 
  9  # 
 10  # Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY 
 11  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
 12  # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
 13  # details. 
 14  # 
 15  # You should have received a copy of the GNU Lesser General Public License 
 16  # along with Paramiko; if not, write to the Free Software Foundation, Inc., 
 17  # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. 
 18   
 19  """ 
 20  Exceptions defined by paramiko. 
 21  """ 
 22   
 23   
24 -class SSHException (Exception):
25 """ 26 Exception raised by failures in SSH2 protocol negotiation or logic errors. 27 """ 28 pass
29 30
31 -class AuthenticationException (SSHException):
32 """ 33 Exception raised when authentication failed for some reason. It may be 34 possible to retry with different credentials. (Other classes specify more 35 specific reasons.) 36 37 @since: 1.6 38 """ 39 pass
40 41
42 -class PasswordRequiredException (AuthenticationException):
43 """ 44 Exception raised when a password is needed to unlock a private key file. 45 """ 46 pass
47 48
49 -class BadAuthenticationType (AuthenticationException):
50 """ 51 Exception raised when an authentication type (like password) is used, but 52 the server isn't allowing that type. (It may only allow public-key, for 53 example.) 54 55 @ivar allowed_types: list of allowed authentication types provided by the 56 server (possible values are: C{"none"}, C{"password"}, and 57 C{"publickey"}). 58 @type allowed_types: list 59 60 @since: 1.1 61 """ 62 allowed_types = [] 63
64 - def __init__(self, explanation, types):
65 AuthenticationException.__init__(self, explanation) 66 self.allowed_types = types
67
68 - def __str__(self):
69 return SSHException.__str__(self) + ' (allowed_types=%r)' % self.allowed_types
70 71
72 -class PartialAuthentication (AuthenticationException):
73 """ 74 An internal exception thrown in the case of partial authentication. 75 """ 76 allowed_types = [] 77
78 - def __init__(self, types):
79 AuthenticationException.__init__(self, 'partial authentication') 80 self.allowed_types = types
81 82
83 -class ChannelException (SSHException):
84 """ 85 Exception raised when an attempt to open a new L{Channel} fails. 86 87 @ivar code: the error code returned by the server 88 @type code: int 89 90 @since: 1.6 91 """
92 - def __init__(self, code, text):
93 SSHException.__init__(self, text) 94 self.code = code
95 96
97 -class BadHostKeyException (SSHException):
98 """ 99 The host key given by the SSH server did not match what we were expecting. 100 101 @ivar hostname: the hostname of the SSH server 102 @type hostname: str 103 @ivar key: the host key presented by the server 104 @type key: L{PKey} 105 @ivar expected_key: the host key expected 106 @type expected_key: L{PKey} 107 108 @since: 1.6 109 """
110 - def __init__(self, hostname, got_key, expected_key):
111 SSHException.__init__(self, 'Host key for server %s does not match!' % hostname) 112 self.hostname = hostname 113 self.key = got_key 114 self.expected_key = expected_key
115