catch syntax/logic issue correctly -> thanks to greg
[certmaster.git] / certmaster / CommonErrors.py
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14 #
15 # Copyright 2005 Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
16
17 from exceptions import Exception
18
19 def canIgnoreSSLError(e):
20 """
21 Identify common network errors that mean we cannot connect to the server
22 """
23
24 # This is a bit complicated by the fact that different versions of
25 # M2Crypto & OpenSSL seem to return different error codes for the
26 # same type of error
27 s = "%s" % e
28 if e[0] == 104: # Connection refused
29 return True
30 elif e[0] == 111: # Connection reset by peer
31 return True
32 elif e[0] == 61: # Connection refused
33 return True
34 elif e[0] == 54: # Connection reset by peer
35 return True
36 elif s == "no certificate returned":
37 return True
38 elif s == "wrong version number":
39 return True
40 elif s == "unexpected eof":
41 return True
42
43 return False
44
45
46 def canIgnoreSocketError(e):
47 """
48 Identify common network errors that mean we cannot connect to the server
49 """
50
51 try:
52 if e[0] == 111: # Connection refused
53 return True
54 elif e[0] == 104: # Connection reset by peer
55 return True
56 elif e[0] == 61: # Connection refused
57 return True
58 except IndexError:
59 return True
60
61 return False
62
63 # FIXME: is anything using this? remove underscores
64 class CertMaster_Client_Exception(Exception):
65 def __init__(self, value=None):
66 Exception.__init__(self)
67 self.value = value
68 def __str__(self):
69 return "%s" %(self.value,)
70