1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | # This is used to make the service error reporting independent of the |
---|
4 | # transport. The XMLRPC and SOAP dispatchers will convert it into |
---|
5 | # transport-specific errors |
---|
6 | class service_error(RuntimeError): |
---|
7 | access = 1 |
---|
8 | protocol= 2 |
---|
9 | req = 3 |
---|
10 | server_config = 4 |
---|
11 | internal = 5 |
---|
12 | partial = 6 |
---|
13 | federant = 7 |
---|
14 | code_str = { |
---|
15 | access : "Access Denied", |
---|
16 | protocol : "Protocol Error", |
---|
17 | req : "Badly Formed Request", |
---|
18 | server_config: "Server Configuration Error", |
---|
19 | internal : "Internal Error", |
---|
20 | partial: "Partial embedding", |
---|
21 | federant: "Federant error" |
---|
22 | } |
---|
23 | str_code = dict([ (v, k) for k, v in code_str.iteritems() ]) |
---|
24 | client_errors = ( req ) |
---|
25 | server_errors = ( access, protocol, server_config, internal) |
---|
26 | |
---|
27 | def __init__(self, code=None, desc=None, from_string=None): |
---|
28 | self.code = code |
---|
29 | self.desc = desc |
---|
30 | if code == None: |
---|
31 | self.set_code_from_string(from_string) |
---|
32 | RuntimeError.__init__(self, desc) |
---|
33 | |
---|
34 | def code_string(self, code=None): |
---|
35 | code = code or self.code |
---|
36 | return service_error.code_str.get(code) |
---|
37 | |
---|
38 | def set_code_from_string(self, errstr): |
---|
39 | self.code = service_error.str_code.get(errstr, service_error.internal) |
---|
40 | return self.code |
---|
41 | |
---|
42 | def is_client_error(self): |
---|
43 | return self.code in service_error.client_errors |
---|
44 | |
---|
45 | def is_server_error(self): |
---|
46 | return self.code in service_error.server_errors |
---|