source: cred_printer/cred_printer/service_error.py

Last change on this file was 02dcba5, checked in by Ted Faber <faber@…>, 13 years ago

Add credential printer

  • Property mode set to 100644
File size: 1.6 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.
6# Cribbed directly from fedd, because it's so convenient.  Some of the error
7# codes are inapplicable to the credential interpreter.
8class service_error(RuntimeError):
9    access = 1
10    protocol= 2
11    req = 3
12    server_config = 4
13    internal = 5
14    partial = 6
15    federant = 7
16    connect = 8
17    code_str = { 
18        access : "Access Denied",
19        protocol : "Protocol Error",
20        req : "Badly Formed Request",
21        server_config: "Server Configuration Error",
22        internal : "Internal Error",
23        partial: "Partial Embedding",
24        federant: "Federant Error",
25        connect: "Connection Error",
26    }
27    str_code = dict([ (v, k) for k, v in code_str.iteritems() ])
28    client_errors = ( req, partial)
29    server_errors = ( access, protocol, server_config, internal,
30            federant, connect)
31
32    def __init__(self, code=None, desc=None, from_string=None, proof=None):
33        self.code = code
34        self.desc = desc
35        self.proof = proof or []
36        if not isinstance (self.proof, list): self.proof = [ proof ]
37        if code == None:
38            self.set_code_from_string(from_string)
39        RuntimeError.__init__(self, desc)
40
41    def code_string(self, code=None):
42        code = code or self.code
43        return service_error.code_str.get(code)
44   
45    def set_code_from_string(self, errstr):
46        self.code = service_error.str_code.get(errstr, service_error.internal)
47        return self.code
48   
49    def is_client_error(self):
50        return self.code in service_error.client_errors
51
52    def is_server_error(self):
53        return self.code in service_error.server_errors
Note: See TracBrowser for help on using the repository browser.