handler: add InvalidMessage.message_id convenience method.
authorW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 12:32:12 +0000 (08:32 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 12:32:12 +0000 (08:32 -0400)
pygrader/handler/__init__.py

index 1837721320975337701c6657d1d376409c855196..3fb7b28aa8ca36963f142b2740bbff99f8da511a 100644 (file)
@@ -11,6 +11,19 @@ class InvalidMessage (ValueError):
         self.message = message
         self.error = error
 
+    def message_id(self):
+        """Return a short string identifying the invalid message.
+        """
+        if self.message is None:
+            return None
+        subject = self.message['Subject']
+        if subject is not None:
+            return repr(subject)
+        message_id = self.message['Message-ID']
+        if message_id is not None:
+            return message_id
+        return None
+
 
 class UnsignedMessage (InvalidMessage):
     def __init__(self, **kwargs):