Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[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: Faults.py 5574 2007-10-25 20:33:17Z thierry $
9 #
10
11 import xmlrpclib
12
13 class PLCFault(xmlrpclib.Fault):
14     def __init__(self, faultCode, faultString, extra = None):
15         if extra:
16             faultString += ": " + extra
17         xmlrpclib.Fault.__init__(self, faultCode, faultString)
18
19 class PLCInvalidAPIMethod(PLCFault):
20     def __init__(self, method, role = None, extra = None):
21         faultString = "Invalid method " + method
22         if role:
23             faultString += " for role " + role
24         PLCFault.__init__(self, 100, faultString, extra)
25
26 class PLCInvalidArgumentCount(PLCFault):
27     def __init__(self, got, min, max = min, extra = None):
28         if min != max:
29             expected = "%d-%d" % (min, max)
30         else:
31             expected = "%d" % min
32         faultString = "Expected %s arguments, got %d" % \
33                       (expected, got)
34         PLCFault.__init__(self, 101, faultString, extra)
35
36 class PLCInvalidArgument(PLCFault):
37     def __init__(self, extra = None, name = None):
38         if name is not None:
39             faultString = "Invalid %s value" % name
40         else:
41             faultString = "Invalid argument"
42         PLCFault.__init__(self, 102, faultString, extra)
43
44 class PLCAuthenticationFailure(PLCFault):
45     def __init__(self, extra = None):
46         faultString = "Failed to authenticate call"
47         PLCFault.__init__(self, 103, faultString, extra)
48
49 class PLCDBError(PLCFault):
50     def __init__(self, extra = None):
51         faultString = "Database error"
52         PLCFault.__init__(self, 106, faultString, extra)
53
54 class PLCPermissionDenied(PLCFault):
55     def __init__(self, extra = None):
56         faultString = "Permission denied"
57         PLCFault.__init__(self, 108, faultString, extra)
58
59 class PLCNotImplemented(PLCFault):
60     def __init__(self, extra = None):
61         faultString = "Not fully implemented"
62         PLCFault.__init__(self, 109, faultString, extra)
63
64 class PLCAPIError(PLCFault):
65     def __init__(self, extra = None):
66         faultString = "Internal API error"
67         PLCFault.__init__(self, 111, faultString, extra)