def process_message_arguments(obj, format=None, message=None, **kw): for key, value in kw.items(): if not isinstance(value, six.integer_types): try: kw[key] = unicode(value) except UnicodeError: pass obj.kw = kw name = obj.__class__.__name__ if obj.format is not None and format is not None: raise ValueError('non-generic %r needs format=None; got format=%r' % (name, format)) if message is None: if obj.format is None: if format is None: raise ValueError( '%s.format is None yet format=None, message=None' % name) obj.format = format obj.forwarded = False obj.msg = obj.format % kw if isinstance(obj.format, six.string_types): obj.strerror = ugettext(obj.format) % kw else: obj.strerror = obj.format % kw if 'instructions' in kw: def convert_instructions(value): if isinstance(value, list): result = u'\n'.join(unicode(line) for line in value) return result return value instructions = u'\n'.join( (unicode(_('Additional instructions:')), convert_instructions(kw['instructions']))) obj.strerror = u'\n'.join((obj.strerror, instructions)) else: if isinstance(message, (Gettext, NGettext)): message = unicode(message) elif type(message) is not unicode: raise TypeError(TYPE_ERROR % ('message', unicode, message, type(message))) obj.forwarded = True obj.msg = message obj.strerror = message for (key, value) in kw.items(): assert not hasattr(obj, key), 'conflicting kwarg %s.%s = %r' % ( name, key, value, ) setattr(obj, key, value)
def process_message_arguments(obj, format=None, message=None, **kw): for key, value in kw.items(): if not isinstance(value, six.integer_types): try: kw[key] = unicode(value) except UnicodeError: pass obj.kw = kw name = obj.__class__.__name__ if obj.format is not None and format is not None: raise ValueError( 'non-generic %r needs format=None; got format=%r' % ( name, format) ) if message is None: if obj.format is None: if format is None: raise ValueError( '%s.format is None yet format=None, message=None' % name ) obj.format = format obj.forwarded = False obj.msg = obj.format % kw if isinstance(obj.format, six.string_types): obj.strerror = ugettext(obj.format) % kw else: obj.strerror = obj.format % kw if 'instructions' in kw: def convert_instructions(value): if isinstance(value, list): result = u'\n'.join(unicode(line) for line in value) return result return value instructions = u'\n'.join((unicode(_('Additional instructions:')), convert_instructions(kw['instructions']))) obj.strerror = u'\n'.join((obj.strerror, instructions)) else: if isinstance(message, (Gettext, NGettext)): message = unicode(message) elif type(message) is not unicode: raise TypeError( TYPE_ERROR % ('message', unicode, message, type(message)) ) obj.forwarded = True obj.msg = message obj.strerror = message for (key, value) in kw.items(): assert not hasattr(obj, key), 'conflicting kwarg %s.%s = %r' % ( name, key, value, ) setattr(obj, key, value)