From 25affca94cc9e6979e2e43430d71a0d32de627df Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 2 Sep 2012 11:30:50 -0400 Subject: [PATCH] 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. --- pygrader/mailpipe.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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) -- 2.26.2