From: W. Trevor King Date: Sun, 2 Sep 2012 15:30:50 +0000 (-0400) Subject: mailpipe: add extra attributes to errors even if current attribute is None. X-Git-Tag: v0.3~10 X-Git-Url: http://git.tremily.us/?p=pygrader.git;a=commitdiff_plain;h=25affca94cc9e6979e2e43430d71a0d32de627df mailpipe: add extra attributes to errors even if current attribute is None. With the old impementation, a default value of None would keep the attribute from being added. For example, if the error is raised with error.subject == None `mailpipe` and `_parse_message` would not override that with their known value. Now they will. --- diff --git a/pygrader/mailpipe.py b/pygrader/mailpipe.py index 3f9f7c3..f2a9671 100644 --- a/pygrader/mailpipe.py +++ b/pygrader/mailpipe.py @@ -590,12 +590,12 @@ def mailpipe(basedir, course, stream=None, mailbox=None, input_=None, except _InvalidMessage as error: error.course = course error.message = original - if person is not None and not hasattr(error, 'person'): - error.person = person - if subject is not None and not hasattr(error, 'subject'): - error.subject = subject - if target is not None and not hasattr(error, 'target'): - error.target = target + for attribute,value in [('person', person), + ('subject', subject), + ('target', target)]: + if (value is not None and + getattr(error, attribute, None) is None): + setattr(error, attribute, value) _LOG.warn('invalid message {}'.format(error.message_id())) if not continue_after_invalid_message: raise @@ -710,12 +710,12 @@ def _parse_message(course, message, trust_email_infrastructure=False): except _InvalidMessage as error: error.course = course error.message = original - if person is not None and not hasattr(error, 'person'): - error.person = person - if subject is not None and not hasattr(error, 'subject'): - error.subject = subject - if target is not None and not hasattr(error, 'target'): - error.target = target + for attribute,value in [('person', person), + ('subject', subject), + ('target', target)]: + if (value is not None and + getattr(error, attribute, None) is None): + setattr(error, attribute, value) raise return (original, message, person, subject, target)