[Zope3-checkins] CVS: Zope3/src/zope/security/tests - test_standard_checkers.py:1.5

Jim Fulton jim@zope.com
Sun, 22 Jun 2003 20:03:58 -0400


Update of /cvs-repository/Zope3/src/zope/security/tests
In directory cvs.zope.org:/tmp/cvs-serv13692/zope/security/tests

Modified Files:
	test_standard_checkers.py 
Log Message:
When iterating over security-proxied sequences, Python failed to
recognize a ForbiddenAttributeError as an AttributeError. To work
around this, we now don't raise a ForbiddenAttribute for __iter__ if
the object doesn't have an __iter__ attribute.


=== Zope3/src/zope/security/tests/test_standard_checkers.py 1.4 => 1.5 ===
--- Zope3/src/zope/security/tests/test_standard_checkers.py:1.4	Sun Jun 22 19:21:42 2003
+++ Zope3/src/zope/security/tests/test_standard_checkers.py	Sun Jun 22 20:03:58 2003
@@ -420,6 +420,41 @@
     1
     """
 
+def test_iter_of_sequences():
+    """
+    >>> class X:
+    ...   d = 1, 2, 3
+    ...   def __getitem__(self, i):
+    ...      return self.d[i]
+    ... 
+    >>> x = X()
+
+    We can iterate over sequences
+    
+    >>> list(x)
+    [1, 2, 3]
+    >>> c = NamesChecker(['__getitem__'])
+    >>> p = ProxyFactory(x, c)
+
+    Even if they are proxied
+    
+    >>> list(p)
+    [1, 2, 3]
+
+    But if the class has an iter:
+
+    >>> X.__iter__ = lambda self: iter(self.d)
+    >>> list(x)
+    [1, 2, 3]
+
+    We shouldn't be able to iterate if we don't have an assertion:
+    
+    >>> list(p)
+    Traceback (most recent call last):
+    ...
+    ForbiddenAttribute: __iter__
+    """
+    
 
     
 from zope.testing.doctestunit import DocTestSuite