source: fedd/Makefile/federation/service_error.py @ 98f99fb

version-3.01version-3.02
Last change on this file since 98f99fb was 88e7f2f, checked in by Ted Faber <faber@…>, 14 years ago

version bump

  • Property mode set to 100644
File size: 1.4 KB
Line 
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
6class 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    connect = 8
15    code_str = { 
16        access : "Access Denied",
17        protocol : "Protocol Error",
18        req : "Badly Formed Request",
19        server_config: "Server Configuration Error",
20        internal : "Internal Error",
21        partial: "Partial Embedding",
22        federant: "Federant Error",
23        connect: "Connection Error",
24    }
25    str_code = dict([ (v, k) for k, v in code_str.iteritems() ])
26    client_errors = ( req, partial)
27    server_errors = ( access, protocol, server_config, internal,
28            federant, connect)
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
Note: See TracBrowser for help on using the repository browser.