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
daf95173
Commit
daf95173
authored
Jan 21, 2009
by
Andreas Zeidler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Acquisition wrappers now correctly proxy `__iter__`.
parent
0687e533
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
3 deletions
+68
-3
_Acquisition.c
_Acquisition.c
+10
-3
tests.py
tests.py
+58
-0
No files found.
_Acquisition.c
View file @
daf95173
...
...
@@ -39,7 +39,7 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__,
*
py__getitem__
,
*
py__setitem__
,
*
py__delitem__
,
*
py__getslice__
,
*
py__setslice__
,
*
py__delslice__
,
*
py__contains__
,
*
py__len__
,
*
py__of__
,
*
py__call__
,
*
py__repr__
,
*
py__str__
,
*
py__cmp__
,
*
py__parent__
;
*
py__parent__
,
*
py__iter__
;
static
PyObject
*
Acquired
=
0
;
...
...
@@ -84,6 +84,7 @@ init_py_names(void)
INIT_PY_NAME
(
__str__
);
INIT_PY_NAME
(
__cmp__
);
INIT_PY_NAME
(
__parent__
);
INIT_PY_NAME
(
__iter__
);
#undef INIT_PY_NAME
}
...
...
@@ -928,6 +929,12 @@ Wrapper_contains(Wrapper *self, PyObject *v)
return
c
;
}
static
PyObject
*
Wrapper_iter
(
Wrapper
*
self
)
{
return
CallMethodO
(
OBJECT
(
self
),
py__iter__
,
NULL
,
NULL
);
}
static
PySequenceMethods
Wrapper_as_sequence
=
{
(
inquiry
)
Wrapper_length
,
/*sq_length*/
(
binaryfunc
)
Wrapper_add
,
/*sq_concat*/
...
...
@@ -1294,7 +1301,7 @@ static PyExtensionClass Wrappertype = {
/* tp_clear */
(
inquiry
)
Wrapper_clear
,
/* tp_richcompare */
(
richcmpfunc
)
Wrapper_richcompare
,
/* tp_weaklistoffset */
(
long
)
0
,
/* tp_iter */
(
getiterfunc
)
0
,
(
getiterfunc
)
Wrapper_iter
,
/*tp_iter*/
/* tp_iternext */
(
iternextfunc
)
0
,
/* tp_methods */
Wrapper_methods
,
/* tp_members */
0
,
...
...
@@ -1338,7 +1345,7 @@ static PyExtensionClass XaqWrappertype = {
/* tp_clear */
(
inquiry
)
Wrapper_clear
,
/* tp_richcompare */
(
richcmpfunc
)
Wrapper_richcompare
,
/* tp_weaklistoffset */
(
long
)
0
,
/* tp_iter */
(
getiterfunc
)
0
,
(
getiterfunc
)
Wrapper_iter
,
/*tp_iter*/
/* tp_iternext */
(
iternextfunc
)
0
,
/* tp_methods */
Wrapper_methods
,
/* tp_members */
0
,
...
...
tests.py
View file @
daf95173
...
...
@@ -1699,6 +1699,9 @@ def test_proxying():
... def __contains__(self, key):
... print 'contains', repr(key)
... return key == 5
... def __iter__(self):
... print 'iterating...'
... return iter((42,))
The naked class behaves like this:
...
...
@@ -1709,6 +1712,9 @@ def test_proxying():
>>> 5 in c
contains 5
True
>>> list(c)
iterating...
[42]
Let's put c in the context of i:
...
...
@@ -1723,6 +1729,58 @@ def test_proxying():
>>> 5 in i.c
contains 5
True
>>> list(i.c)
iterating...
[42]
Let's let's test the same again with an explicit wrapper:
>>> import Acquisition
>>> class Impl(Acquisition.Explicit):
... pass
>>> class C(Acquisition.Explicit):
... 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
... def __iter__(self):
... print 'iterating...'
... return iter((42,))
The naked class behaves like this:
>>> c = C()
>>> 3 in c
contains 3
False
>>> 5 in c
contains 5
True
>>> list(c)
iterating...
[42]
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
>>> list(i.c)
iterating...
[42]
"""
...
...
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