summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-03-10 16:05:11 +0000
committerGitHub <noreply@github.com>2022-03-10 16:05:11 +0000
commit876d5b9d5f99700564794f8e4f4f2c00aba8cfb9 (patch)
tree57291d4262b83103ef6ef64e95db6c31379e1445
parente7cb2fbb8bdbe839a0d5b097cfe16a208fa9b17b (diff)
parent779c5db040759de3fb51e80f90f9805d1e093e1c (diff)
downloadzope-security-876d5b9d5f99700564794f8e4f4f2c00aba8cfb9.tar.gz
Merge pull request #81 from cjwatson/default-method-wrapper-checker
Fix default checker for method-wrapper on Python 3
-rw-r--r--CHANGES.rst5
-rw-r--r--src/zope/security/checker.py3
-rw-r--r--src/zope/security/tests/test_proxy.py5
3 files changed, 11 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 72b74fe..5a7e37a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,7 +5,10 @@
5.3 (unreleased)
================
-- Nothing changed yet.
+- Allow calling bound methods of some built-in objects such as ``().__repr__``
+ and ``{}.__repr__`` by default. This worked on Python 2, but raised
+ ``ForbiddenAttribute`` on Python 3. See `issue 75
+ <https://github.com/zopefoundation/zope.security/issues/75>`_.
5.2 (2022-03-10)
diff --git a/src/zope/security/checker.py b/src/zope/security/checker.py
index c337a18..fbc0b2a 100644
--- a/src/zope/security/checker.py
+++ b/src/zope/security/checker.py
@@ -882,6 +882,8 @@ _default_checkers = {
types.MethodType: _callableChecker,
types.BuiltinFunctionType: _callableChecker,
types.BuiltinMethodType: _callableChecker,
+ # method-wrapper
+ type(().__repr__): _callableChecker,
type: _typeChecker,
types.ModuleType: lambda module: _checkers.get(module, _namedChecker),
type(iter([])): _iteratorChecker, # Same types in Python 2.2.1,
@@ -912,7 +914,6 @@ if PYTHON2: # pragma: no cover
_default_checkers[types.ClassType] = _typeChecker
_default_checkers[types.InstanceType] = _instanceChecker
# slot description
- _default_checkers[type(().__getslice__)] = _callableChecker
_default_checkers[type({}.iteritems())] = _iteratorChecker
_default_checkers[type({}.iterkeys())] = _iteratorChecker
_default_checkers[type({}.itervalues())] = _iteratorChecker
diff --git a/src/zope/security/tests/test_proxy.py b/src/zope/security/tests/test_proxy.py
index adbb4f2..d646f54 100644
--- a/src/zope/security/tests/test_proxy.py
+++ b/src/zope/security/tests/test_proxy.py
@@ -2171,6 +2171,11 @@ class ProxyFactoryTests(unittest.TestCase):
self.assertEqual(list(IFoo), ['x'])
self.assertEqual(list(proxy), list(IFoo))
+ def test_method_wrapper(self):
+ from zope.security.proxy import ProxyFactory
+
+ self.assertEqual(ProxyFactory({}).__repr__(), '{}')
+
def test_using_mapping_slots_hack():
"""The security proxy will use mapping slots, on the checker to go faster