summaryrefslogtreecommitdiffstats
path: root/Lib/rfc822.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-05-22 14:58:10 (GMT)
committerFred Drake <fdrake@acm.org>2001-05-22 14:58:10 (GMT)
commit02959292803415fc5d66838735764aa84de8c0f8 (patch)
tree046846bae113ce878e4d9e656765933d389a16f5 /Lib/rfc822.py
parent706314909b9fcdcdd46dadb389c6c32cdfbbcdb6 (diff)
downloadcpython-02959292803415fc5d66838735764aa84de8c0f8.zip
cpython-02959292803415fc5d66838735764aa84de8c0f8.tar.gz
cpython-02959292803415fc5d66838735764aa84de8c0f8.tar.bz2
Added .get() and .setdefault() support to rfc822.Message.
Diffstat (limited to 'Lib/rfc822.py')
-rw-r--r--Lib/rfc822.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/rfc822.py b/Lib/rfc822.py
index 101013d..9093beb 100644
--- a/Lib/rfc822.py
+++ b/Lib/rfc822.py
@@ -421,6 +421,26 @@ class Message:
for i in list:
del self.headers[i]
+ def get(self, name, default=None):
+ name = name.lower()
+ if self.dict.has_key(name):
+ return self.dict[name]
+ else:
+ return default
+
+ def setdefault(self, name, default=''):
+ lowername = name.lower()
+ if self.dict.has_key(lowername):
+ return self.dict[lowername]
+ else:
+ default = default or ""
+ self.dict[lowername] = default
+ text = "%s: %s" % (name, default)
+ lines = text.split("\n")
+ for line in lines:
+ self.headers.append(line + "\n")
+ return default
+
def has_key(self, name):
"""Determine whether a message contains the named header."""
return self.dict.has_key(name.lower())