obj.py: InitErrors: allow selected exceptions to be passed through
This commit is contained in:
parent
2f6e5f1fc2
commit
c27c464a87
4 changed files with 10 additions and 4 deletions
|
|
@ -133,7 +133,9 @@ class InitErrors:
|
|||
if m2:
|
||||
errmsg = repr(m2) + '\n' + errmsg
|
||||
|
||||
if hasattr(cls,'exc'):
|
||||
if hasattr(cls,'passthru_excs') and type(e) in cls.passthru_excs:
|
||||
raise
|
||||
elif hasattr(cls,'exc'):
|
||||
raise cls.exc(errmsg)
|
||||
else:
|
||||
raise ObjectInitError(errmsg)
|
||||
|
|
@ -684,6 +686,7 @@ class TwMMGenID(str,Hilite,InitErrors,MMGenObject):
|
|||
# non-displaying container for TwMMGenID,TwComment
|
||||
class TwLabel(str,InitErrors,MMGenObject):
|
||||
exc = BadTwLabel
|
||||
passthru_excs = (BadTwComment,)
|
||||
def __new__(cls,proto,text):
|
||||
if type(text) == cls:
|
||||
return text
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ def CUR_RIGHT(n): return '\033[{}C'.format(n)
|
|||
|
||||
def get_tw_label(proto,s):
|
||||
"""
|
||||
We must fail only on malformed comment, not on empty label.
|
||||
Otherwise, listaddresses showempty=1 will fail.
|
||||
raise an exception on a malformed comment, return None on an empty or invalid label
|
||||
"""
|
||||
try:
|
||||
return TwLabel(proto,s)
|
||||
|
|
|
|||
|
|
@ -72,6 +72,10 @@ def run_test(test,arg,input_data,arg1,exc_name):
|
|||
ret_chk = arg['ret']
|
||||
del arg['ret']
|
||||
del arg_copy['ret']
|
||||
if 'exc_name' in arg:
|
||||
exc_name = arg['exc_name']
|
||||
del arg['exc_name']
|
||||
del arg_copy['exc_name']
|
||||
if 'ret_idx' in arg:
|
||||
ret_idx = arg['ret_idx']
|
||||
del arg['ret_idx']
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ tests = {
|
|||
{'text':tw_pfx+' x', 'proto':proto},
|
||||
{'text':tw_pfx+'я x', 'proto':proto},
|
||||
{'text':utf8_ctrl[:40], 'proto':proto},
|
||||
{'text':'F00BAA12:S:1 '+ utf8_ctrl[:40], 'proto':proto, },
|
||||
{'text':'F00BAA12:S:1 ' + utf8_ctrl[:40], 'proto':proto, 'exc_name': 'BadTwComment'},
|
||||
),
|
||||
'good': (
|
||||
{'text':'F00BAA12:99 a comment', 'proto':proto, 'ret':'F00BAA12:L:99 a comment'},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue