Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Acquisition
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
Acquisition
Commits
aa855980
Commit
aa855980
authored
Jun 02, 2006
by
Florent Guillaume
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Acquisition wrappers now correctly proxy __contains__.
parent
82e1679a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
2 deletions
+58
-2
_Acquisition.c
_Acquisition.c
+15
-1
tests.py
tests.py
+43
-1
No files found.
_Acquisition.c
View file @
aa855980
...
@@ -37,7 +37,7 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__,
...
@@ -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__pos__
,
*
py__abs__
,
*
py__nonzero__
,
*
py__invert__
,
*
py__int__
,
*
py__long__
,
*
py__float__
,
*
py__oct__
,
*
py__hex__
,
*
py__long__
,
*
py__float__
,
*
py__oct__
,
*
py__hex__
,
*
py__getitem__
,
*
py__setitem__
,
*
py__delitem__
,
*
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__
;
*
py__len__
,
*
py__of__
,
*
py__call__
,
*
py__repr__
,
*
py__str__
,
*
py__cmp__
;
static
PyObject
*
Acquired
=
0
;
static
PyObject
*
Acquired
=
0
;
...
@@ -75,6 +75,7 @@ init_py_names(void)
...
@@ -75,6 +75,7 @@ init_py_names(void)
INIT_PY_NAME
(
__getslice__
);
INIT_PY_NAME
(
__getslice__
);
INIT_PY_NAME
(
__setslice__
);
INIT_PY_NAME
(
__setslice__
);
INIT_PY_NAME
(
__delslice__
);
INIT_PY_NAME
(
__delslice__
);
INIT_PY_NAME
(
__contains__
);
INIT_PY_NAME
(
__len__
);
INIT_PY_NAME
(
__len__
);
INIT_PY_NAME
(
__of__
);
INIT_PY_NAME
(
__of__
);
INIT_PY_NAME
(
__call__
);
INIT_PY_NAME
(
__call__
);
...
@@ -804,6 +805,18 @@ Wrapper_ass_slice(Wrapper *self, int ilow, int ihigh, PyObject *v)
...
@@ -804,6 +805,18 @@ Wrapper_ass_slice(Wrapper *self, int ilow, int ihigh, PyObject *v)
return
0
;
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
=
{
static
PySequenceMethods
Wrapper_as_sequence
=
{
(
inquiry
)
Wrapper_length
,
/*sq_length*/
(
inquiry
)
Wrapper_length
,
/*sq_length*/
(
binaryfunc
)
Wrapper_add
,
/*sq_concat*/
(
binaryfunc
)
Wrapper_add
,
/*sq_concat*/
...
@@ -812,6 +825,7 @@ static PySequenceMethods Wrapper_as_sequence = {
...
@@ -812,6 +825,7 @@ static PySequenceMethods Wrapper_as_sequence = {
(
intintargfunc
)
Wrapper_slice
,
/*sq_slice*/
(
intintargfunc
)
Wrapper_slice
,
/*sq_slice*/
(
intobjargproc
)
Wrapper_ass_item
,
/*sq_ass_item*/
(
intobjargproc
)
Wrapper_ass_item
,
/*sq_ass_item*/
(
intintobjargproc
)
Wrapper_ass_slice
,
/*sq_ass_slice*/
(
intintobjargproc
)
Wrapper_ass_slice
,
/*sq_ass_slice*/
(
objobjproc
)
Wrapper_contains
,
/*sq_contains*/
};
};
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */
...
...
tests.py
View file @
aa855980
...
@@ -1620,7 +1620,49 @@ def test_Wrapper_gc():
...
@@ -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
import
unittest
from
zope.testing.doctest
import
DocTestSuite
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