summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Vagelpohl <jens@plyp.com>2023-01-16 15:42:35 +0100
committerGitHub <noreply@github.com>2023-01-16 15:42:35 +0100
commit5f76805733db926738fd5b29a1d7440c33f2a279 (patch)
treef49614c15222f467da07b49699cafb3e768cd342
parente9b0c56414f127e69095fae6e3773e4217c6145f (diff)
parent5667dd8d1a7a908d37b5b7390bc33ba95d69149b (diff)
downloadzope-security-5f76805733db926738fd5b29a1d7440c33f2a279.tar.gz
Merge pull request #93 from zopefoundation/dataflake/cleanup_py2_names
Remove proxying code for names that no longer exist in Python 3
-rw-r--r--.meta.toml2
-rw-r--r--CHANGES.rst3
-rw-r--r--buildout.cfg2
-rw-r--r--src/zope/security/_proxy.c123
-rw-r--r--src/zope/security/checker.py5
-rw-r--r--src/zope/security/proxy.py6
-rw-r--r--src/zope/security/tests/test_proxy.py51
-rw-r--r--tox.ini2
8 files changed, 14 insertions, 180 deletions
diff --git a/.meta.toml b/.meta.toml
index bf29867..2145952 100644
--- a/.meta.toml
+++ b/.meta.toml
@@ -2,7 +2,7 @@
# https://github.com/zopefoundation/meta/tree/master/config/c-code
[meta]
template = "c-code"
-commit-id = "3c9d0741"
+commit-id = "4f0f7596"
[python]
with-appveyor = true
diff --git a/CHANGES.rst b/CHANGES.rst
index 0e86f75..00352a5 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,6 +5,9 @@
6.0 (unreleased)
================
+- Remove proxying code for names that no longer exist in Python 3.
+ (`#92 <https://github.com/zopefoundation/zope.security/issues/92>`_)
+
- Drop support for Python 2.7, 3.5, 3.6.
diff --git a/buildout.cfg b/buildout.cfg
index 0a7118d..b837e22 100644
--- a/buildout.cfg
+++ b/buildout.cfg
@@ -15,7 +15,7 @@ eggs =
recipe = zc.recipe.egg
eggs =
zope.security [test,zcml,pytz,untrustedpython]
-interpreter = python
+interpreter = py
[coverage-test]
recipe = zc.recipe.testrunner
diff --git a/src/zope/security/_proxy.c b/src/zope/security/_proxy.c
index ce42c54..c17358c 100644
--- a/src/zope/security/_proxy.c
+++ b/src/zope/security/_proxy.c
@@ -46,12 +46,12 @@ static PyObject *__class__str = 0, *__name__str = 0, *__module__str = 0;
#define DECLARE_STRING(N) static PyObject *str_##N
DECLARE_STRING(__3pow__);
+DECLARE_STRING(__bool__);
DECLARE_STRING(__call__);
DECLARE_STRING(check);
DECLARE_STRING(check_getattr);
DECLARE_STRING(check_setattr);
DECLARE_STRING(__cmp__);
-DECLARE_STRING(__coerce__);
DECLARE_STRING(__contains__);
DECLARE_STRING(__delitem__);
DECLARE_STRING(__getitem__);
@@ -60,20 +60,14 @@ DECLARE_STRING(__hash__);
DECLARE_STRING(__iter__);
DECLARE_STRING(__len__);
DECLARE_STRING(next);
-DECLARE_STRING(__nonzero__);
DECLARE_STRING(op_abs);
DECLARE_STRING(op_add);
DECLARE_STRING(op_and);
-DECLARE_STRING(op_div);
DECLARE_STRING(op_divmod);
DECLARE_STRING(op_float);
DECLARE_STRING(op_floordiv);
-DECLARE_STRING(op_hex);
DECLARE_STRING(op_iadd);
DECLARE_STRING(op_iand);
-#if PY_MAJOR_VERSION < 3
-DECLARE_STRING(op_idiv);
-#endif
DECLARE_STRING(op_ifloordiv);
DECLARE_STRING(op_ilshift);
DECLARE_STRING(op_imod);
@@ -86,17 +80,14 @@ DECLARE_STRING(op_irshift);
DECLARE_STRING(op_isub);
DECLARE_STRING(op_itruediv);
DECLARE_STRING(op_ixor);
-DECLARE_STRING(op_long);
DECLARE_STRING(op_lshift);
DECLARE_STRING(op_mod);
DECLARE_STRING(op_mul);
DECLARE_STRING(op_neg);
-DECLARE_STRING(op_oct);
DECLARE_STRING(op_or);
DECLARE_STRING(op_pos);
DECLARE_STRING(op_radd);
DECLARE_STRING(op_rand);
-DECLARE_STRING(op_rdiv);
DECLARE_STRING(op_rdivmod);
DECLARE_STRING(op_rfloordiv);
DECLARE_STRING(op_rlshift);
@@ -462,14 +453,6 @@ proxy_repr(SecurityProxy *self)
return result;
}
-#if PY_MAJOR_VERSION < 3
-static int
-proxy_compare(SecurityProxy *self, PyObject *other)
-{
- return PyObject_Compare(self->proxy.proxy_object, other);
-}
-#endif
-
static long
proxy_hash(SecurityProxy *self)
{
@@ -508,11 +491,6 @@ call_##M(PyObject *self) \
NUMBER_METHOD(int)
NUMBER_METHOD(float)
-#if PY_MAJOR_VERSION < 3
-NUMBER_METHOD(long)
-NUMBER_METHOD(oct)
-NUMBER_METHOD(hex)
-#endif
static PyObject *
call_ipow(PyObject *self, PyObject *other)
@@ -524,9 +502,6 @@ call_ipow(PyObject *self, PyObject *other)
BINOP(add, PyNumber_Add)
BINOP(sub, PyNumber_Subtract)
BINOP(mul, PyNumber_Multiply)
-#if PY_MAJOR_VERSION < 3
-BINOP(div, PyNumber_Divide)
-#endif
BINOP(mod, PyNumber_Remainder)
BINOP(divmod, PyNumber_Divmod)
@@ -576,60 +551,12 @@ BINOP(and, PyNumber_And)
BINOP(xor, PyNumber_Xor)
BINOP(or, PyNumber_Or)
-#if PY_MAJOR_VERSION < 3
-static int
-proxy_coerce(PyObject **p_self, PyObject **p_other)
-{
- PyObject *self = *p_self;
- PyObject *other = *p_other;
-
- assert(Proxy_Check(self));
-
- if (check((SecurityProxy*)self, str_check, str___coerce__) >= 0)
- {
- PyObject *left = ((SecurityProxy*)self)->proxy.proxy_object;
- PyObject *right = other;
- int r;
- r = PyNumber_CoerceEx(&left, &right);
- if (r != 0)
- return r;
- /* Now left and right have been INCREF'ed.
- Any new value that comes out is proxied;
- any unchanged value is left unchanged. */
- if (left == ((SecurityProxy*)self)->proxy.proxy_object) {
- /* Keep the old proxy */
- Py_DECREF(left);
- Py_INCREF(self);
- left = self;
- }
- else {
- PROXY_RESULT(((SecurityProxy*)self), left);
- if (left == NULL) {
- Py_DECREF(right);
- return -1;
- }
- }
- if (right != other) {
- PROXY_RESULT(((SecurityProxy*)self), right);
- if (right == NULL) {
- Py_DECREF(left);
- return -1;
- }
- }
- *p_self = left;
- *p_other = right;
- return 0;
- }
- return -1;
-}
-#endif
-
UNOP(neg, PyNumber_Negative)
UNOP(pos, PyNumber_Positive)
UNOP(abs, PyNumber_Absolute)
static int
-proxy_nonzero(PyObject *self)
+proxy_bool(PyObject *self)
{
return PyObject_IsTrue(((SecurityProxy*)self)->proxy.proxy_object);
}
@@ -637,18 +564,10 @@ proxy_nonzero(PyObject *self)
UNOP(invert, PyNumber_Invert)
UNOP(int, call_int)
UNOP(float, call_float)
-#if PY_MAJOR_VERSION < 3
-UNOP(long, call_long)
-UNOP(oct, call_oct)
-UNOP(hex, call_hex)
-#endif
INPLACE(add, PyNumber_InPlaceAdd)
INPLACE(sub, PyNumber_InPlaceSubtract)
INPLACE(mul, PyNumber_InPlaceMultiply)
-#if PY_MAJOR_VERSION < 3
-INPLACE(div, PyNumber_InPlaceDivide)
-#endif
INPLACE(mod, PyNumber_InPlaceRemainder)
INPLACE(pow, call_ipow)
INPLACE(lshift, PyNumber_InPlaceLshift)
@@ -788,45 +707,28 @@ proxy_as_number = {
proxy_add, /* nb_add */
proxy_sub, /* nb_subtract */
proxy_mul, /* nb_multiply */
-#if PY_MAJOR_VERSION < 3
- proxy_div, /* nb_divide */
-#endif
proxy_mod, /* nb_remainder */
proxy_divmod, /* nb_divmod */
proxy_pow, /* nb_power */
proxy_neg, /* nb_negative */
proxy_pos, /* nb_positive */
proxy_abs, /* nb_absolute */
- proxy_nonzero, /* nb_nonzero */
+ proxy_bool, /* nb_bool */
proxy_invert, /* nb_invert */
proxy_lshift, /* nb_lshift */
proxy_rshift, /* nb_rshift */
proxy_and, /* nb_and */
proxy_xor, /* nb_xor */
proxy_or, /* nb_or */
-#if PY_MAJOR_VERSION < 3
- proxy_coerce, /* nb_coerce */
-#endif
proxy_int, /* nb_int */
-#if PY_MAJOR_VERSION < 3
- proxy_long, /* nb_long */
-#else
- 0, /* nb_reserved */
-#endif
+ 0, /* nb_reserved, formerly nb_long */
proxy_float, /* nb_float */
-#if PY_MAJOR_VERSION < 3
- proxy_oct, /* nb_oct */
- proxy_hex, /* nb_hex */
-#endif
/* Added in release 2.0 */
/* These require the Py_TPFLAGS_HAVE_INPLACEOPS flag */
proxy_iadd, /* nb_inplace_add */
proxy_isub, /* nb_inplace_subtract */
proxy_imul, /* nb_inplace_multiply */
-#if PY_MAJOR_VERSION < 3
- proxy_idiv, /* nb_inplace_divide */
-#endif
proxy_imod, /* nb_inplace_remainder */
(ternaryfunc)proxy_ipow, /* nb_inplace_power */
proxy_ilshift, /* nb_inplace_lshift */
@@ -892,11 +794,7 @@ static PyTypeObject SecurityProxyType = {
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
-#if PY_MAJOR_VERSION < 3
- (cmpfunc)proxy_compare, /* tp_compare */
-#else
- 0, /* tp_reserved */
-#endif
+ 0, /* tp_reserved, was tp_compare */
(reprfunc)proxy_repr, /* tp_repr */
&proxy_as_number, /* tp_as_number */
&proxy_as_sequence, /* tp_as_sequence */
@@ -989,12 +887,12 @@ if((str_##S = INTERN(#S)) == NULL) return MOD_ERROR_VAL
if((str_op_##S = INTERN("__" #S "__")) == NULL) return MOD_ERROR_VAL
INIT_STRING(__3pow__);
+ INIT_STRING(__bool__);
INIT_STRING(__call__);
INIT_STRING(check);
INIT_STRING(check_getattr);
INIT_STRING(check_setattr);
INIT_STRING(__cmp__);
- INIT_STRING(__coerce__);
INIT_STRING(__contains__);
INIT_STRING(__delitem__);
INIT_STRING(__getitem__);
@@ -1003,20 +901,14 @@ if((str_op_##S = INTERN("__" #S "__")) == NULL) return MOD_ERROR_VAL
INIT_STRING(__iter__);
INIT_STRING(__len__);
INIT_STRING(next);
- INIT_STRING(__nonzero__);
INIT_STRING_OP(abs);
INIT_STRING_OP(add);
INIT_STRING_OP(and);
- INIT_STRING_OP(div);
INIT_STRING_OP(divmod);
INIT_STRING_OP(float);
INIT_STRING_OP(floordiv);
- INIT_STRING_OP(hex);
INIT_STRING_OP(iadd);
INIT_STRING_OP(iand);
-#if PY_MAJOR_VERSION < 3
- INIT_STRING_OP(idiv);
-#endif
INIT_STRING_OP(ifloordiv);
INIT_STRING_OP(ilshift);
INIT_STRING_OP(imod);
@@ -1029,17 +921,14 @@ if((str_op_##S = INTERN("__" #S "__")) == NULL) return MOD_ERROR_VAL
INIT_STRING_OP(isub);
INIT_STRING_OP(itruediv);
INIT_STRING_OP(ixor);
- INIT_STRING_OP(long);
INIT_STRING_OP(lshift);
INIT_STRING_OP(mod);
INIT_STRING_OP(mul);
INIT_STRING_OP(neg);
- INIT_STRING_OP(oct);
INIT_STRING_OP(or);
INIT_STRING_OP(pos);
INIT_STRING_OP(radd);
INIT_STRING_OP(rand);
- INIT_STRING_OP(rdiv);
INIT_STRING_OP(rdivmod);
INIT_STRING_OP(rfloordiv);
INIT_STRING_OP(rlshift);
diff --git a/src/zope/security/checker.py b/src/zope/security/checker.py
index db7a167..f969edf 100644
--- a/src/zope/security/checker.py
+++ b/src/zope/security/checker.py
@@ -857,12 +857,11 @@ _default_checkers = {
'__add__', '__radd__',
'__sub__', '__rsub__',
'__mul__', '__rmul__',
- '__div__', '__truediv__',
- '__rdiv__', '__rtruediv__',
+ '__truediv__', '__rtruediv__',
'__divmod__', '__rdivmod__',
'__mod__', '__rmod__',
'__floordiv__', '__rfloordiv__',
- '__float__', '__int__', '__long__',
+ '__float__', '__int__',
'__pow__', '__rpow__',
'adjusted', 'as_tuple', 'compare',
'max', 'min', 'normalize',
diff --git a/src/zope/security/proxy.py b/src/zope/security/proxy.py
index c8db35a..5fc5e81 100644
--- a/src/zope/security/proxy.py
+++ b/src/zope/security/proxy.py
@@ -285,14 +285,10 @@ for name in ['__call__',
'__complex__',
'__int__',
'__float__',
- '__long__',
- '__oct__',
- '__hex__',
'__index__',
'__add__',
'__sub__',
'__mul__',
- '__div__',
'__truediv__',
'__floordiv__',
'__mod__',
@@ -301,7 +297,6 @@ for name in ['__call__',
'__radd__',
'__rsub__',
'__rmul__',
- '__rdiv__',
'__rtruediv__',
'__rfloordiv__',
'__rmod__',
@@ -330,7 +325,6 @@ for name in (
for name in ['__iadd__',
'__isub__',
'__imul__',
- '__idiv__',
'__itruediv__',
'__ifloordiv__',
'__imod__',
diff --git a/src/zope/security/tests/test_proxy.py b/src/zope/security/tests/test_proxy.py
index 68f370a..38126fc 100644
--- a/src/zope/security/tests/test_proxy.py
+++ b/src/zope/security/tests/test_proxy.py
@@ -405,21 +405,6 @@ class AbstractProxyTestBase:
self.assertRaises(ForbiddenAttribute, lambda: proxy * 2)
self.assertEqual(checker._checked, '__mul__')
- def test___div___w_checker_allows(self):
- target = 3
- checker = DummyChecker()
- proxy = self._makeOne(target, checker)
- self.assertEqual(proxy / 2, target / 2)
- self.assertEqual(checker._checked, '__truediv__')
-
- def test___div___w_checker_forbids(self):
- from zope.security.interfaces import ForbiddenAttribute
- target = 3
- checker = DummyChecker(ForbiddenAttribute)
- proxy = self._makeOne(target, checker)
- self.assertRaises(ForbiddenAttribute, lambda: proxy / 2)
- self.assertEqual(checker._checked, '__truediv__')
-
def test___truediv___w_checker_allows(self):
target = 3.0
checker = DummyChecker()
@@ -753,41 +738,6 @@ class AbstractProxyTestBase:
proxy *= 3
self.assertEqual(checker._checked, '__imul__')
- def test___idiv___not_inplace_checker_allows(self):
- target = 6
- checker = DummyChecker()
- proxy = before = self._makeOne(target, checker)
- proxy /= 3
- self.assertIsNot(proxy, before)
- self.assertEqual(proxy, 2)
- self.assertEqual(checker._checked, '__itruediv__')
-
- def test___idiv___inplace_checker_allows(self):
- class Foo:
- def __init__(self, value):
- self.value = value
-
- def __idiv__(self, rhs):
- self.value /= rhs
- return self
- __itruediv__ = __idiv__
- target = Foo(6)
- checker = DummyChecker()
- proxy = before = self._makeOne(target, checker)
- proxy /= 3
- self.assertIs(proxy, before)
- self.assertEqual(target.value, 2)
- self.assertEqual(checker._checked, '__itruediv__')
-
- def test___idiv___w_checker_forbids(self):
- from zope.security.interfaces import ForbiddenAttribute
- target = 6
- checker = DummyChecker(ForbiddenAttribute)
- proxy = self._makeOne(target, checker)
- with self.assertRaises(ForbiddenAttribute):
- proxy /= 3
- self.assertEqual(checker._checked, '__itruediv__')
-
def test___itruediv___not_inplace_checker_allows(self):
target = 6
checker = DummyChecker()
@@ -805,7 +755,6 @@ class AbstractProxyTestBase:
def __itruediv__(self, rhs):
self.value /= rhs
return self
- __idiv__ = __itruediv__
target = Foo(6)
checker = DummyChecker()
proxy = before = self._makeOne(target, checker)
diff --git a/tox.ini b/tox.ini
index 8a47458..ed8ebef 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,7 +1,7 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/c-code
[tox]
-minversion = 3.18
+minversion = 4.0
envlist =
lint
py37,py37-pure