Skip to content

Commit

Permalink
Make py_sameProxiedObjects handle zope.security proxies
Browse files Browse the repository at this point in the history
By effectively bypassing them to access `_wrapped`.

Fixes #15.
  • Loading branch information
jamadden committed Apr 16, 2017
1 parent ba25030 commit c53a19d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 44 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ python:
- 3.5
- pypy
install:
- pip install .
- pip install zope.security
- pip install -e .[test]
script:
- python setup.py test -q
notifications:
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ Changes
4.2.1 (unreleased)
------------------

- TBD
- Make the pure-Python implementation of ``sameProxiedObjects`` handle
``zope.security`` proxies. See `issue 15 <https://github.com/zopefoundation/zope.proxy/issues/15>`_.

4.2.0 (2016-05-05)
------------------

- Correctly strip ``zope.security`` proxies in ``removeAllProxies``.
See `issue 13 <https://github.com/zopefoundation/zope.proxy/pull/13>`_.

- Avoid poisoning the user's global wheel cache when testing ``PURE_PYTHON``
environments under ``tox``,
Expand Down
14 changes: 9 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from setuptools import setup, Extension, Feature

def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()

Cwrapper = Feature(
"C wrapper",
Expand Down Expand Up @@ -74,7 +75,8 @@ def read(*rnames):
'Programming Language :: Python :: Implementation :: PyPy',
"Framework :: Zope3",
'Natural Language :: English',
'Operating System :: OS Independent'],
'Operating System :: OS Independent'
],
keywords='proxy generic transparent',
packages=['zope', 'zope.proxy'],
package_dir = {'': 'src'},
Expand All @@ -83,11 +85,13 @@ def read(*rnames):
test_suite = 'zope.proxy',
install_requires=[
'zope.interface',
'setuptools'],
'setuptools',
],
include_package_data = True,
zip_safe = False,
extras_require = {
'testing': ['nose', 'coverage', 'zope.security'],
'docs': ['Sphinx', 'repoze.sphinx.autointerface'],
'test': ['zope.security',],
'testing': ['nose', 'coverage', 'zope.security',],
'docs': ['Sphinx', 'repoze.sphinx.autointerface',],
},
)
4 changes: 2 additions & 2 deletions src/zope/proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ def py_isProxy(obj, klass=None):

def py_sameProxiedObjects(lhs, rhs):
while isinstance(lhs, PyProxyBase):
lhs = lhs._wrapped
lhs = super(PyProxyBase, lhs).__getattribute__('_wrapped')
while isinstance(rhs, PyProxyBase):
rhs = rhs._wrapped
rhs = super(PyProxyBase, rhs).__getattribute__('_wrapped')
return lhs is rhs

def py_queryProxy(obj, klass=None, default=None):
Expand Down
52 changes: 26 additions & 26 deletions src/zope/proxy/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,12 @@ def _makeProxy(self, obj):
from zope.proxy import PyProxyBase
return PyProxyBase(obj)

def _makeSecurityProxy(self, obj):
from zope.security.proxy import ProxyPy
from zope.security.checker import CheckerPy
checker = CheckerPy({})
return ProxyPy(obj, checker)

def test_bare_instance_identical(self):
class C(object):
pass
Expand Down Expand Up @@ -1112,6 +1118,20 @@ class C(object):
self.assertFalse(self._callFUT(_mP(_mP(c1)), c2))
self.assertFalse(self._callFUT(c2, _mP(_mP(c1))))

@unittest.skipUnless(_HAVE_ZOPE_SECURITY, 'zope.security missing')
def test_security_proxy(self):
class C(object):
pass
c1 = C()
proxy1 = self._makeSecurityProxy(c1)
proxy1_2 = self._makeSecurityProxy(c1)

self.assertTrue(self._callFUT(proxy1, proxy1))
self.assertTrue(self._callFUT(proxy1, proxy1_2))

c2 = C()
proxy2 = self._makeSecurityProxy(c2)
self.assertFalse(self._callFUT(proxy1, proxy2))

class Test_sameProxiedObjects(Test_py_sameProxiedObjects):

Expand All @@ -1123,6 +1143,11 @@ def _makeProxy(self, obj):
from zope.proxy import ProxyBase
return ProxyBase(obj)

def _makeSecurityProxy(self, obj):
from zope.security.proxy import Proxy
from zope.security.checker import Checker
checker = Checker({})
return Proxy(obj, checker)

class Test_py_queryProxy(unittest.TestCase):

Expand Down Expand Up @@ -1327,7 +1352,6 @@ def _makeProxy(self, obj):
from zope.proxy import ProxyBase
return ProxyBase(obj)


class Test_ProxyIterator(unittest.TestCase):

def _callFUT(self, *args):
Expand Down Expand Up @@ -1412,28 +1436,4 @@ def __repr__(self):


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ModuleConformanceCase),
unittest.makeSuite(PyProxyBaseTestCase),
unittest.makeSuite(ProxyBaseTestCase),
unittest.makeSuite(Test_py_getProxiedObject),
unittest.makeSuite(Test_getProxiedObject),
unittest.makeSuite(Test_py_setProxiedObject),
unittest.makeSuite(Test_setProxiedObject),
unittest.makeSuite(Test_py_isProxy),
unittest.makeSuite(Test_isProxy),
unittest.makeSuite(Test_py_sameProxiedObjects),
unittest.makeSuite(Test_sameProxiedObjects),
unittest.makeSuite(Test_py_queryProxy),
unittest.makeSuite(Test_queryProxy),
unittest.makeSuite(Test_py_queryInnerProxy),
unittest.makeSuite(Test_queryInnerProxy),
unittest.makeSuite(Test_py_removeAllProxies),
unittest.makeSuite(Test_removeAllProxies),
unittest.makeSuite(Test_ProxyIterator),
unittest.makeSuite(Test_nonOverridable),
unittest.makeSuite(Test_py__module),
unittest.makeSuite(Test__module),
unittest.makeSuite(Test_py_subclass__module),
unittest.makeSuite(Test_subclass__module),
))
return unittest.defaultTestLoader.loadTestsFromName(__name__)
16 changes: 8 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[tox]
envlist =
envlist =
# Jython support pending 2.7 support, due 2012-07-15 or so. See:
# http://fwierzbicki.blogspot.com/2012/03/adconion-to-fund-jython-27.html
# py27,jython,pypy,coverage
py27,py27-pure,py33,py33-pure,py34,py35,pypy,coverage,docs

[testenv]
commands =
commands =
python setup.py -q test -q
deps =
.[test]

[testenv:py27-pure]
basepython =
Expand All @@ -24,28 +26,26 @@ setenv =
PIP_CACHE_DIR = {envdir}/.cache

[testenv:jython]
commands =
commands =
jython setup.py test -q

[testenv:coverage]
basepython =
python2.7
commands =
commands =
# The installed version messes up nose's test discovery / coverage reporting
# So, we uninstall that from the environment, and then install the editable
# version, before running nosetests.
pip uninstall -y zope.proxy
pip install -e .
nosetests --with-xunit --with-xcoverage
deps =
nose
coverage
nosexcover
.[testing]

[testenv:docs]
basepython =
python2.7
commands =
commands =
sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html
sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest
deps =
Expand Down

0 comments on commit c53a19d

Please sign in to comment.