[ef36c1e] | 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 |
---|
[058f58e] | 8 | protocol= 2 |
---|
[ef36c1e] | 9 | req = 3 |
---|
| 10 | server_config = 4 |
---|
| 11 | internal = 5 |
---|
[3441fe3] | 12 | partial = 6 |
---|
| 13 | federant = 7 |
---|
[9d3e646] | 14 | connect = 8 |
---|
[ef36c1e] | 15 | code_str = { |
---|
| 16 | access : "Access Denied", |
---|
[058f58e] | 17 | protocol : "Protocol Error", |
---|
[ef36c1e] | 18 | req : "Badly Formed Request", |
---|
| 19 | server_config: "Server Configuration Error", |
---|
[3441fe3] | 20 | internal : "Internal Error", |
---|
[9d3e646] | 21 | partial: "Partial Embedding", |
---|
| 22 | federant: "Federant Error", |
---|
| 23 | connect: "Connection Error", |
---|
[ef36c1e] | 24 | } |
---|
| 25 | str_code = dict([ (v, k) for k, v in code_str.iteritems() ]) |
---|
[9d3e646] | 26 | client_errors = ( req, partial) |
---|
| 27 | server_errors = ( access, protocol, server_config, internal, |
---|
| 28 | federant, connect) |
---|
[ef36c1e] | 29 | |
---|
| 30 | def __init__(self, code=None, desc=None, from_string=None): |
---|
| 31 | self.code = code |
---|
| 32 | self.desc = desc |
---|
| 33 | if code == None: |
---|
| 34 | self.set_code_from_string(from_string) |
---|
| 35 | RuntimeError.__init__(self, desc) |
---|
| 36 | |
---|
| 37 | def code_string(self, code=None): |
---|
| 38 | code = code or self.code |
---|
| 39 | return service_error.code_str.get(code) |
---|
| 40 | |
---|
| 41 | def set_code_from_string(self, errstr): |
---|
| 42 | self.code = service_error.str_code.get(errstr, service_error.internal) |
---|
| 43 | return self.code |
---|
| 44 | |
---|
| 45 | def is_client_error(self): |
---|
| 46 | return self.code in service_error.client_errors |
---|
| 47 | |
---|
| 48 | def is_server_error(self): |
---|
| 49 | return self.code in service_error.server_errors |
---|