Log message for revision 68459:
  Acquisition wrappers now correctly proxy __contains__.
  
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/Acquisition/_Acquisition.c
  U   Zope/trunk/lib/python/Acquisition/tests.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt  2006-06-02 14:24:46 UTC (rev 68458)
+++ Zope/trunk/doc/CHANGES.txt  2006-06-02 14:34:52 UTC (rev 68459)
@@ -16,8 +16,9 @@
 
   Zope 2.10.0 beta 2 (unreleased)
 
-    Bugs fixed 
+    Bugs Fixed
 
+      - Acquisition wrappers now correctly proxy __contains__.
 
   Zope 2.10.0 beta 1 (2006/05/30)
 

Modified: Zope/trunk/lib/python/Acquisition/_Acquisition.c
===================================================================
--- Zope/trunk/lib/python/Acquisition/_Acquisition.c    2006-06-02 14:24:46 UTC 
(rev 68458)
+++ Zope/trunk/lib/python/Acquisition/_Acquisition.c    2006-06-02 14:34:52 UTC 
(rev 68459)
@@ -37,7 +37,7 @@
   *py__pos__, *py__abs__, *py__nonzero__, *py__invert__, *py__int__,
   *py__long__, *py__float__, *py__oct__, *py__hex__,
   *py__getitem__, *py__setitem__, *py__delitem__,
-  *py__getslice__, *py__setslice__, *py__delslice__,
+  *py__getslice__, *py__setslice__, *py__delslice__,  *py__contains__,
   *py__len__, *py__of__, *py__call__, *py__repr__, *py__str__, *py__cmp__;
 
 static PyObject *Acquired=0;
@@ -75,6 +75,7 @@
   INIT_PY_NAME(__getslice__);
   INIT_PY_NAME(__setslice__);
   INIT_PY_NAME(__delslice__);
+  INIT_PY_NAME(__contains__);
   INIT_PY_NAME(__len__);
   INIT_PY_NAME(__of__);
   INIT_PY_NAME(__call__);
@@ -804,6 +805,18 @@
   return 0;
 }
 
+static int
+Wrapper_contains(Wrapper *self, PyObject *v)
+{
+  long c;
+
+  UNLESS(v=CallMethodO(OBJECT(self),py__contains__,Build("(O)", v) ,NULL))
+    return -1;
+  c = PyInt_AsLong(v);
+  Py_DECREF(v);
+  return c;
+}
+
 static PySequenceMethods Wrapper_as_sequence = {
        (inquiry)Wrapper_length,                /*sq_length*/
        (binaryfunc)Wrapper_add,                /*sq_concat*/
@@ -812,6 +825,7 @@
        (intintargfunc)Wrapper_slice,           /*sq_slice*/
        (intobjargproc)Wrapper_ass_item,        /*sq_ass_item*/
        (intintobjargproc)Wrapper_ass_slice,    /*sq_ass_slice*/
+       (objobjproc)Wrapper_contains,           /*sq_contains*/
 };
 
 /* -------------------------------------------------------------- */

Modified: Zope/trunk/lib/python/Acquisition/tests.py
===================================================================
--- Zope/trunk/lib/python/Acquisition/tests.py  2006-06-02 14:24:46 UTC (rev 
68458)
+++ Zope/trunk/lib/python/Acquisition/tests.py  2006-06-02 14:34:52 UTC (rev 
68459)
@@ -1620,8 +1620,50 @@
 """
 
 
-    
+def test_proxying():
+    """Make sure that recent python slots are proxied.
 
+    >>> import Acquisition
+    >>> class Impl(Acquisition.Implicit):
+    ...     pass
+
+    >>> class C(Acquisition.Implicit):
+    ...     def __getitem__(self, key):
+    ...         print 'getitem', key
+    ...         if key == 4:
+    ...             raise IndexError
+    ...         return key
+    ...     def __contains__(self, key):
+    ...         print 'contains', repr(key)
+    ...         return key == 5
+
+    The naked class behaves like this:
+
+    >>> c = C()
+    >>> 3 in c
+    contains 3
+    False
+    >>> 5 in c
+    contains 5
+    True
+
+    Let's put c in the context of i:
+
+    >>> i = Impl()
+    >>> i.c = c
+
+    Now check that __contains__ is properly used:
+
+    >>> 3 in i.c # c.__of__(i)
+    contains 3
+    False
+    >>> 5 in i.c
+    contains 5
+    True
+
+    """
+
+
 import unittest
 from zope.testing.doctest import DocTestSuite
 

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to