changeset: 93118:fea3ddcaf652 branch: 3.4 parent: 93115:9ec84f9b61c6 user: R David Murray date: Fri Oct 17 19:30:13 2014 -0400 files: Lib/email/headerregistry.py Lib/test/test_email/test_headerregistry.py Misc/NEWS description: #21991: make headerregistry params property MappingProxyType. It is unlikely anyone is using the fact that the dictionary returned by the 'params' attribute was previously writable, but even if someone is the API is provisional so this kind of change is acceptable (and needed, to get the API "right" before it becomes official). Patch by Stéphane Wirtel. diff -r 9ec84f9b61c6 -r fea3ddcaf652 Lib/email/headerregistry.py --- a/Lib/email/headerregistry.py Sat Oct 18 00:35:00 2014 +0200 +++ b/Lib/email/headerregistry.py Fri Oct 17 19:30:13 2014 -0400 @@ -7,6 +7,7 @@ and will probably change some before that happens. """ +from types import MappingProxyType from email import utils from email import errors @@ -454,7 +455,7 @@ @property def params(self): - return self._params.copy() + return MappingProxyType(self._params) class ContentTypeHeader(ParameterizedMIMEHeader): diff -r 9ec84f9b61c6 -r fea3ddcaf652 Lib/test/test_email/test_headerregistry.py --- a/Lib/test/test_email/test_headerregistry.py Sat Oct 18 00:35:00 2014 +0200 +++ b/Lib/test/test_email/test_headerregistry.py Fri Oct 17 19:30:13 2014 -0400 @@ -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 -r 9ec84f9b61c6 -r fea3ddcaf652 Misc/NEWS --- a/Misc/NEWS Sat Oct 18 00:35:00 2014 +0200 +++ b/Misc/NEWS Fri Oct 17 19:30:13 2014 -0400 @@ -33,6 +33,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 #22641: In asyncio, the default SSL context for client connections is now created using ssl.create_default_context(), for stronger security.