summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-04-02 21:33:20 (GMT)
committerGuido van Rossum <guido@python.org>1998-04-02 21:33:20 (GMT)
commit75d92c18646ff7bfbfe39b21cc38dfb0b12e00d7 (patch)
tree911fafc497790b8b64ee330ff5c59661658b29f3
parent58b2bfd0bfeaad6bc0f0b7d4d0af6fd7194e3c3d (diff)
downloadcpython-75d92c18646ff7bfbfe39b21cc38dfb0b12e00d7.zip
cpython-75d92c18646ff7bfbfe39b21cc38dfb0b12e00d7.tar.gz
cpython-75d92c18646ff7bfbfe39b21cc38dfb0b12e00d7.tar.bz2
Added a __delitem__ to the Message class.
(Still no __setitem__, until I get a request to add it!)
-rw-r--r--Lib/rfc822.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/rfc822.py b/Lib/rfc822.py
index e6e0696..9d76f6d 100644
--- a/Lib/rfc822.py
+++ b/Lib/rfc822.py
@@ -284,6 +284,28 @@ class Message:
"""Get a specific header, as from a dictionary."""
return self.dict[string.lower(name)]
+ def __delitem__(self, name):
+ """Delete all occurrences of a specific header, if it is present."""
+ name = string.lower(name)
+ if not self.dict.has_key(name):
+ return
+ del self.dict[name]
+ name = name + ':'
+ n = len(name)
+ list = []
+ hit = 0
+ for i in range(len(self.headers)):
+ line = self.headers[i]
+ if string.lower(line[:n]) == name:
+ hit = 1
+ elif line[:1] not in string.whitespace:
+ hit = 0
+ if hit:
+ list.append(i)
+ list.reverse()
+ for i in list:
+ del self.headers[i]
+
def has_key(self, name):
"""Determine whether a message contains the named header."""
return self.dict.has_key(string.lower(name))