summaryrefslogtreecommitdiffstats
path: root/Lib/email/policy.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-05-29 13:14:44 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-05-29 13:14:44 (GMT)
commitabfc37491cecb0a052d54c3bf0525ac140e94f7e (patch)
tree90ffe814aff0fd3f921e29e619582236f6f3ebe5 /Lib/email/policy.py
parent6066fe1258d7d8dcec7459267f159d5d73d920e2 (diff)
downloadcpython-abfc37491cecb0a052d54c3bf0525ac140e94f7e.zip
cpython-abfc37491cecb0a052d54c3bf0525ac140e94f7e.tar.gz
cpython-abfc37491cecb0a052d54c3bf0525ac140e94f7e.tar.bz2
#10839: raise an error on add of duplicate unique headers in new email policies
This feature was supposed to be part of the initial email6 checkin, but it got lost in my big refactoring. In this patch I'm not providing an easy way to turn off the errors, but they only happen when a header is added programmatically, and it is almost never the right thing to do to allow the duplicate to be added. An application that needs to add duplicates of unique headers can create a policy subclass to allow it.
Diffstat (limited to 'Lib/email/policy.py')
-rw-r--r--Lib/email/policy.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/email/policy.py b/Lib/email/policy.py
index 47ed66b..bfffb45 100644
--- a/Lib/email/policy.py
+++ b/Lib/email/policy.py
@@ -69,6 +69,14 @@ class EmailPolicy(Policy):
object.__setattr__(self, 'header_factory', HeaderRegistry())
super().__init__(**kw)
+ def header_max_count(self, name):
+ """+
+ The implementation for this class returns the max_count attribute from
+ the specialized header class that would be used to construct a header
+ of type 'name'.
+ """
+ return self.header_factory[name].max_count
+
# The logic of the next three methods is chosen such that it is possible to
# switch a Message object between a Compat32 policy and a policy derived
# from this class and have the results stay consistent. This allows a