class BaseException fixed_args fixed_msg None default_msg args_sep rep

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class BaseException:
fixed_args=()
fixed_msg=None
default_msg=''
args_sep=','
repr_func=str
capitalize_msg=False
sign_after_msg=''
fancy_output=False
def __init__(self,*args,**kwargs):
self.args=args
self.kwargs=kwargs
def __call__(self,*args,**kwargs):
self.__init__(args,kwargs)
return self
def __str__(self):
self.process_opts()
output=self.process_args()
if self.fancy_output:
return '\n\n'+output+'\n'
return output
def process_opts(self):
for name,value in self.kwargs:
setattr(self,name,value)
def process_args(self):
args=self.fixed_args+self.args
if args:
if self.fixed_msg:
msg=self.fixed_msg
_args=args
else:
msg=args[-1]
_args=args[:-1]
if self.capitalize_msg:
msg=msg.capitalize()
if self.sign_after_msg:
msg+=self.sign_after_msg
str_args=self.args_sep.join(self.repr_func(arg) for arg in _args)
if str_args:
return "%(str_args)s: %(msg)s" %locals()
return self.repr_func(msg)
return self.repr_func(self.default_msg)