Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
1171b89c
Commit
1171b89c
authored
Jun 02, 2006
by
Florent Guillaume
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Acquisition wrappers now correctly proxy __contains__.
parent
8bdd6dcc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
2 deletions
+64
-2
doc/CHANGES.txt
doc/CHANGES.txt
+6
-0
lib/python/Acquisition/_Acquisition.c
lib/python/Acquisition/_Acquisition.c
+15
-1
lib/python/Acquisition/tests.py
lib/python/Acquisition/tests.py
+43
-1
No files found.
doc/CHANGES.txt
View file @
1171b89c
...
...
@@ -14,6 +14,12 @@ Zope Changes
to the rules for such a type laid out in the Python docs:
http://docs.python.org/api/supporting-cycle-detection.html
After Zope 2.10 beta 1
Bugs Fixed
- Acquisition wrappers now correctly proxy __contains__.
Zope 2.10 beta 1 (2006/05/30)
Restructuring
...
...
lib/python/Acquisition/_Acquisition.c
View file @
1171b89c
...
...
@@ -37,7 +37,7 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__,
*
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_names(void)
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 @@ Wrapper_ass_slice(Wrapper *self, int ilow, int ihigh, PyObject *v)
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 @@ static PySequenceMethods Wrapper_as_sequence = {
(
intintargfunc
)
Wrapper_slice
,
/*sq_slice*/
(
intobjargproc
)
Wrapper_ass_item
,
/*sq_ass_item*/
(
intintobjargproc
)
Wrapper_ass_slice
,
/*sq_ass_slice*/
(
objobjproc
)
Wrapper_contains
,
/*sq_contains*/
};
/* -------------------------------------------------------------- */
...
...
lib/python/Acquisition/tests.py
View file @
1171b89c
...
...
@@ -1620,7 +1620,49 @@ def test_Wrapper_gc():
"""
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment