summaryrefslogtreecommitdiffstats
path: root/ipalib/errors.py
diff options
context:
space:
mode:
authorAlexander Bokovoy <abokovoy@redhat.com>2012-10-12 12:13:59 +0300
committerRob Crittenden <rcritten@redhat.com>2012-10-11 16:30:58 -0400
commit88262a75ffe7a25640333dcc4da2100830cae821 (patch)
tree2d36698091fc5494c53f031551127f474d44c10c /ipalib/errors.py
parent1907f720d527b07a12a9525f5ae8680b6c21cd57 (diff)
downloadfreeipa-88262a75ffe7a25640333dcc4da2100830cae821.tar.gz
freeipa-88262a75ffe7a25640333dcc4da2100830cae821.tar.xz
freeipa-88262a75ffe7a25640333dcc4da2100830cae821.zip
Add instructions support to PublicError
When long additional text should follow the error message, one can supply instructions parameter to a class derived from PublicError. This will cause following text added to the error message: Additional instructions: <additional text> `instructions' optional parameter could be a list or anything that coerces into unicode(). List entries will be joined with '\n'. https://fedorahosted.org/freeipa/ticket/3167
Diffstat (limited to 'ipalib/errors.py')
-rw-r--r--ipalib/errors.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/ipalib/errors.py b/ipalib/errors.py
index 7f1113200..a6c8e7683 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -265,17 +265,20 @@ class PublicError(StandardError):
)
self.format = format
self.forwarded = False
- def convert_keyword(value):
- if isinstance(value, list):
- result=u'\n'.join(map(lambda line: unicode(line), value))
- return result
- return value
- kwargs = dict(map(lambda (k,v): (k, convert_keyword(v)), kw.items()))
- self.msg = self.format % kwargs
+ self.msg = self.format % kw
if isinstance(self.format, basestring):
- self.strerror = ugettext(self.format) % kwargs
+ self.strerror = ugettext(self.format) % kw
else:
- self.strerror = self.format % kwargs
+ self.strerror = self.format % kw
+ if 'instructions' in kw:
+ def convert_instructions(value):
+ if isinstance(value, list):
+ result=u'\n'.join(map(lambda line: unicode(line), value))
+ return result
+ return value
+ instructions = u'\n'.join((unicode(_('Additional instructions:')),
+ convert_instructions(kw['instructions'])))
+ self.strerror = u'\n'.join((self.strerror, instructions))
else:
if isinstance(message, (Gettext, NGettext)):
message = unicode(message)