]> granicus.if.org Git - python/commitdiff
HeaderParser: A new subclass of Parser which only parses the message
authorBarry Warsaw <barry@python.org>
Thu, 11 Oct 2001 15:43:00 +0000 (15:43 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 11 Oct 2001 15:43:00 +0000 (15:43 +0000)
headers.  It does not parse the body of the message, instead simply
assigning it as a string to the container's payload.  This can be much
faster when you're only interested in a message's header.

Lib/email/Parser.py

index 81763dc0068eebca198a95d0b510b4bd9e71c42f..44a0ca2bdd61a90877480fbf4e153e7971857c41 100644 (file)
@@ -158,3 +158,19 @@ class Parser:
             container.add_payload(msg)
         else:
             container.add_payload(fp.read())
+
+
+\f
+class HeaderParser(Parser):
+    """A subclass of Parser, this one only meaningfully parses message headers.
+
+    This class can be used if all you're interested in is the headers of a
+    message.  While it consumes the message body, it does not parse it, but
+    simply makes it available as a string payload.
+
+    Parsing with this subclass can be considerably faster if all you're
+    interested in is the message headers.
+    """
+    def _parsebody(self, container, fp):
+        # Consume but do not parse, the body
+        container.set_payload(fp.read())