[Python-checkins] cpython (merge 3.4 -> default): Merge: #21991: make headerregistry params property MappingProxyType.

r.david.murray python-checkins at python.org
Sat Oct 18 01:33:03 CEST 2014


https://hg.python.org/cpython/rev/5beb1ea76f36
changeset:   93119:5beb1ea76f36
parent:      93117:ccd93c7f2b3c
parent:      93118:fea3ddcaf652
user:        R David Murray <rdmurray at bitdance.com>
date:        Fri Oct 17 19:32:08 2014 -0400
summary:
  Merge: #21991: make headerregistry params property MappingProxyType.

files:
  Lib/email/headerregistry.py                |  3 ++-
  Lib/test/test_email/test_headerregistry.py |  3 +++
  Misc/NEWS                                  |  4 ++++
  3 files changed, 9 insertions(+), 1 deletions(-)


diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py
--- a/Lib/email/headerregistry.py
+++ b/Lib/email/headerregistry.py
@@ -7,6 +7,7 @@
 and will probably change some before that happens.
 
 """
+from types import MappingProxyType
 
 from email import utils
 from email import errors
@@ -456,7 +457,7 @@
 
     @property
     def params(self):
-        return self._params.copy()
+        return MappingProxyType(self._params)
 
 
 class ContentTypeHeader(ParameterizedMIMEHeader):
diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py
--- a/Lib/test/test_email/test_headerregistry.py
+++ b/Lib/test/test_email/test_headerregistry.py
@@ -1,6 +1,7 @@
 import datetime
 import textwrap
 import unittest
+import types
 from email import errors
 from email import policy
 from email.message import Message
@@ -235,6 +236,8 @@
         self.assertEqual(h.maintype, maintype)
         self.assertEqual(h.subtype, subtype)
         self.assertEqual(h.params, parmdict)
+        with self.assertRaises(TypeError):
+            h.params['abc'] = 'xyz'   # params is read-only.
         self.assertDefectsEqual(h.defects, defects)
         self.assertEqual(h, decoded)
         self.assertEqual(h.fold(policy=policy.default), folded)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -181,6 +181,10 @@
 Library
 -------
 
+- Issue #21991: Make email.headerregistry's header 'params' attributes
+  be read-only (MappingProxyType).  Previously the dictionary was modifiable
+  but a new one was created on each access of the attribute.
+
 - Issue #22638: SSLv3 is now disabled throughout the standard library.
   It can still be enabled by instantiating a SSLContext manually.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list