Skip to content

Commit

Permalink
Make iteration over security-proxied items work under Python3 using t…
Browse files Browse the repository at this point in the history
…he pure-python implementation. Fixes zopefoundation/zope.component#16.
  • Loading branch information
jamadden committed Jun 2, 2015
1 parent 10a9a46 commit 3497236
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/zope/security/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def moduleChecker(module):
'__implemented__'])
_namedChecker = NamesChecker(['__name__'])

_iteratorChecker = NamesChecker(['next', '__iter__', '__len__'])
_iteratorChecker = NamesChecker(['next', '__next__', '__iter__', '__len__'])

_setChecker = NamesChecker(['__iter__', '__len__', '__str__', '__contains__',
'copy', 'difference', 'intersection', 'issubset',
Expand Down Expand Up @@ -651,7 +651,7 @@ def update(self, d):
datetime.time: NoProxy,
datetime.tzinfo: NoProxy,
}
if PYTHON2:
if PYTHON2:
_basic_types[long] = NoProxy
_basic_types[unicode] = NoProxy
else: #pragma NO COVER
Expand Down Expand Up @@ -783,4 +783,3 @@ def _clear():
pass
else:
addCleanUp(_clear)

17 changes: 13 additions & 4 deletions src/zope/security/tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def test_w_spec_as_names_and_iface(self):
class IFoo(Interface):
bar = Attribute('Bar')
other_perm = object()
checker = self._callFUT([(IFoo, other_perm),
checker = self._callFUT([(IFoo, other_perm),
(('foo', 'baz'), CheckerPublic)])
self.assertTrue(checker.permission_id('foo') is CheckerPublic)
self.assertTrue(checker.permission_id('bar') is other_perm)
Expand All @@ -636,7 +636,7 @@ class IFoo(Interface):
bar = Attribute('Bar')
other_perm = object()
self.assertRaises(DuplicationError,
self._callFUT, [(IFoo, other_perm),
self._callFUT, [(IFoo, other_perm),
(('foo', 'bar'), CheckerPublic)])

def test_w_spec_as_mapping(self):
Expand Down Expand Up @@ -784,7 +784,7 @@ def test_hit(self):
from zope.security.checker import _checkers
class Foo(object):
pass
checker = _checkers[Foo] = object()
checker = _checkers[Foo] = object()
self.assertTrue(self._callFUT(Foo) is checker)


Expand Down Expand Up @@ -1362,7 +1362,7 @@ class Foo(object):
BasicTypes.update({Foo: checker})
self.assertTrue(BasicTypes[Foo] is checker)
self.assertTrue(_checkers[Foo] is checker)


# Pre-geddon tests start here

Expand Down Expand Up @@ -1601,6 +1601,15 @@ def test_proxy(self):
# proxy2 = checker.proxy(proxy)
# self.assertTrue(proxy2 is proxy, [proxy, proxy2])

def test_iteration(self):
from zope.security.checker import ProxyFactory
from zope.security.checker import selectChecker

for i in ((1,), [1]):
_iter = iter(i)
proxy = ProxyFactory(_iter, selectChecker(_iter))
self.assertEqual(next(proxy), 1)

def testLayeredProxies(self):
#Test that a Proxy will not be re-proxied.
from zope.security.proxy import Proxy, getObject
Expand Down

0 comments on commit 3497236

Please sign in to comment.