Fix version output when missing.
[plcapi.git] / PLC / Faults.py
1 #
2 # PLCAPI XML-RPC faults
3 #
4 # Aaron Klingaman <alk@absarokasoft.com>
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 #
7 # Copyright (C) 2004-2006 The Trustees of Princeton University
8 # $Id$
9 # $URL$
10 #
11
12 import xmlrpclib
13
14 class PLCFault(xmlrpclib.Fault):
15     def __init__(self, faultCode, faultString, extra = None):
16         if extra:
17             faultString += ": " + extra
18         xmlrpclib.Fault.__init__(self, faultCode, faultString)
19
20 class PLCInvalidAPIMethod(PLCFault):
21     def __init__(self, method, role = None, extra = None):
22         faultString = "Invalid method " + method
23         if role:
24             faultString += " for role " + role
25         PLCFault.__init__(self, 100, faultString, extra)
26
27 class PLCInvalidArgumentCount(PLCFault):
28     def __init__(self, got, min, max = min, extra = None):
29         if min != max:
30             expected = "%d-%d" % (min, max)
31         else:
32             expected = "%d" % min
33         faultString = "Expected %s arguments, got %d" % \
34                       (expected, got)
35         PLCFault.__init__(self, 101, faultString, extra)
36
37 class PLCInvalidArgument(PLCFault):
38     def __init__(self, extra = None, name = None):
39         if name is not None:
40             faultString = "Invalid %s value" % name
41         else:
42             faultString = "Invalid argument"
43         PLCFault.__init__(self, 102, faultString, extra)
44
45 class PLCAuthenticationFailure(PLCFault):
46     def __init__(self, extra = None):
47         faultString = "Failed to authenticate call"
48         PLCFault.__init__(self, 103, faultString, extra)
49
50 class PLCDBError(PLCFault):
51     def __init__(self, extra = None):
52         faultString = "Database error"
53         PLCFault.__init__(self, 106, faultString, extra)
54
55 class PLCPermissionDenied(PLCFault):
56     def __init__(self, extra = None):
57         faultString = "Permission denied"
58         PLCFault.__init__(self, 108, faultString, extra)
59
60 class PLCNotImplemented(PLCFault):
61     def __init__(self, extra = None):
62         faultString = "Not fully implemented"
63         PLCFault.__init__(self, 109, faultString, extra)
64
65 class PLCAPIError(PLCFault):
66     def __init__(self, extra = None):
67         faultString = "Internal API error"
68         PLCFault.__init__(self, 111, faultString, extra)