summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-10-11 15:43:00 (GMT)
committerBarry Warsaw <barry@python.org>2001-10-11 15:43:00 (GMT)
commite552882960e4caa26ec80465ee501da17bc29e51 (patch)
tree4dfbf32c7f2cad5071a576b58c50d925aff5e9b6 /Lib
parent4819e97a48e3e6584035c482d24953018bf2f851 (diff)
downloadcpython-e552882960e4caa26ec80465ee501da17bc29e51.zip
cpython-e552882960e4caa26ec80465ee501da17bc29e51.tar.gz
cpython-e552882960e4caa26ec80465ee501da17bc29e51.tar.bz2
HeaderParser: A new subclass of Parser which only parses the message
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/email/Parser.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/email/Parser.py b/Lib/email/Parser.py
index 81763dc..44a0ca2 100644
--- a/Lib/email/Parser.py
+++ b/Lib/email/Parser.py
@@ -158,3 +158,19 @@ class Parser:
container.add_payload(msg)
else:
container.add_payload(fp.read())
+
+
+
+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())