This commit is contained in:
Jephté Clain 2018-05-07 11:12:49 +04:00
parent 1a3550ed9a
commit 6e142b7e61
1 changed files with 34 additions and 22 deletions

View File

@ -43,6 +43,13 @@ def load(prefix=None, icons=True, charset="utf-8"):
]) ])
return u"\n".join(lines) return u"\n".join(lines)
def sa(value, kw, name, default=Undef):
"""si value est indéfini, récupérer la valeur avec le nom court dans kw
"""
if value is Undef and name is not None: value = kw.pop(name, Undef)
if value is Undef: value = default
return value
################################################################################ ################################################################################
# Menu # Menu
@ -246,15 +253,24 @@ class Alert(object):
action = None action = None
showtb = None showtb = None
def __init__(self, msg=None, exc_info=Undef, type="error", closeable=False, escape=None, action=None, showtb=True, **kw): def __init__(self, msg=None, exc_info=Undef, type=Undef, closeable=Undef, escape=Undef, action=None, showtb=True, **kw):
self(msg, exc_info, type, closeable, escape, action, showtb, **kw) exc_info = sa(exc_info, kw, 'e')
if exc_info is Undef: exc_info = sys.exc_info()
if exc_info == (None, None, None): exc_info = None
type = sa(type, kw, 't', "error")
closeable = sa(closeable, kw, 'c', False)
escape = sa(escape, kw, 'x', None)
self.msg = msg
self.exc_info = exc_info
self.type = ALERT_TYPE_MAP.get(type, type)
self.closeable = closeable
self.escape = escape
self.action = action
self.showtb = showtb
def __call__(self, msg=Undef, exc_info=Undef, type=Undef, closeable=Undef, escape=Undef, action=Undef, showtb=Undef, **kw): def __call__(self, msg=Undef, exc_info=Undef, type=Undef, closeable=Undef, escape=Undef, action=Undef, showtb=Undef, **kw):
if exc_info is Undef: exc_info = kw.pop('e', Undef) exc_info = sa(exc_info, kw, 'e')
if type is Undef: type = kw.pop('t', Undef)
if closeable is Undef: closeable = kw.pop('c', Undef)
if escape is Undef: escape = kw.pop('x', Undef)
if msg is Undef: if msg is Undef:
# si on ne spécifie pas de message, alors prendre la valeur actuelle # si on ne spécifie pas de message, alors prendre la valeur actuelle
msg = self.msg msg = self.msg
@ -263,11 +279,11 @@ class Alert(object):
# si on spécifie un message, alors prendre aussi l'exception courante # si on spécifie un message, alors prendre aussi l'exception courante
if exc_info is Undef: exc_info = sys.exc_info() if exc_info is Undef: exc_info = sys.exc_info()
if exc_info == (None, None, None): exc_info = None if exc_info == (None, None, None): exc_info = None
if type is Undef: type = self.type type = sa(type, kw, 't', self.type)
if closeable is Undef: closeable = self.closeable closeable = sa(closeable, kw, 'c', self.closeable)
if escape is Undef: escape = self.escape escape = sa(escape, kw, 'x', self.escape)
if action is Undef: action = self.action action = sa(action, kw, None, self.action)
if showtb is Undef: showtb = self.showtb showtb = sa(showtb, kw, None, self.showtb)
self.msg = msg self.msg = msg
self.exc_info = exc_info self.exc_info = exc_info
@ -279,11 +295,7 @@ class Alert(object):
return self return self
def render(self, msg=Undef, exc_info=Undef, type=Undef, closeable=Undef, escape=Undef, action=Undef, showtb=Undef, **kw): def render(self, msg=Undef, exc_info=Undef, type=Undef, closeable=Undef, escape=Undef, action=Undef, showtb=Undef, **kw):
if exc_info is Undef: exc_info = kw.pop('e', Undef) exc_info = sa(exc_info, kw, 'e')
if type is Undef: type = kw.pop('t', Undef)
if closeable is Undef: closeable = kw.pop('c', Undef)
if escape is Undef: escape = kw.pop('x', Undef)
if msg is Undef: if msg is Undef:
# si on ne spécifie pas de message, alors prendre la valeur initiale # si on ne spécifie pas de message, alors prendre la valeur initiale
msg = self.msg msg = self.msg
@ -291,11 +303,11 @@ class Alert(object):
else: else:
# si on spécifie un message, alors prendre aussi l'exception courante # si on spécifie un message, alors prendre aussi l'exception courante
if exc_info is Undef: exc_info = sys.exc_info() if exc_info is Undef: exc_info = sys.exc_info()
if type is Undef: type = self.type type = sa(type, kw, 't', self.type)
if closeable is Undef: closeable = self.closeable closeable = sa(closeable, kw, 'c', self.closeable)
if escape is Undef: escape = self.escape escape = sa(escape, kw, 'x', self.escape)
if action is Undef: action = self.action action = sa(action, kw, None, self.action)
if showtb is Undef: showtb = self.showtb showtb = sa(showtb, kw, None, self.showtb)
if callable(msg): if callable(msg):
# si msg est callable, par défaut ne pas mettre le résultat en # si msg est callable, par défaut ne pas mettre le résultat en