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
0de682e1
Commit
0de682e1
authored
Feb 19, 2011
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged zagy-unicode-should-be-called branch incl. some more tests
parent
3cb2b752
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
2 deletions
+63
-2
CHANGES.txt
CHANGES.txt
+3
-0
src/Acquisition/_Acquisition.c
src/Acquisition/_Acquisition.c
+22
-2
src/Acquisition/tests.py
src/Acquisition/tests.py
+38
-0
No files found.
CHANGES.txt
View file @
0de682e1
...
...
@@ -6,6 +6,9 @@ Changelog
- Add ``aq_explicit`` to ``IAcquisitionWrapper``.
- Fixed bug: ``unicode(wrapped)`` was not calling a ``__unicode__``
method on wrapped objects.
2.13.5 (2010-09-29)
-------------------
...
...
src/Acquisition/_Acquisition.c
View file @
0de682e1
...
...
@@ -51,8 +51,8 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__,
*
py__long__
,
*
py__float__
,
*
py__oct__
,
*
py__hex__
,
*
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__iter__
;
*
py__len__
,
*
py__of__
,
*
py__call__
,
*
py__repr__
,
*
py__str__
,
*
py__
unicode
__
,
*
py__
cmp__
,
*
py__
parent__
,
*
py__iter__
;
static
PyObject
*
Acquired
=
0
;
...
...
@@ -95,6 +95,7 @@ init_py_names(void)
INIT_PY_NAME
(
__call__
);
INIT_PY_NAME
(
__repr__
);
INIT_PY_NAME
(
__str__
);
INIT_PY_NAME
(
__unicode__
);
INIT_PY_NAME
(
__cmp__
);
INIT_PY_NAME
(
__parent__
);
INIT_PY_NAME
(
__iter__
);
...
...
@@ -839,6 +840,23 @@ Wrapper_str(Wrapper *self)
}
}
static
PyObject
*
Wrapper_unicode
(
Wrapper
*
self
)
{
PyObject
*
r
;
if
((
r
=
PyObject_GetAttr
(
OBJECT
(
self
),
py__unicode__
)))
{
ASSIGN
(
r
,
PyObject_CallFunction
(
r
,
NULL
,
NULL
));
return
r
;
}
else
{
PyErr_Clear
();
return
PyObject_Unicode
(
self
->
obj
);
}
}
static
long
Wrapper_hash
(
Wrapper
*
self
)
{
...
...
@@ -1313,6 +1331,8 @@ static struct PyMethodDef Wrapper_methods[] = {
"Wrappers are not picklable"
},
{
"__reduce_ex__"
,
(
PyCFunction
)
Wrappers_are_not_picklable
,
METH_VARARGS
,
"Wrappers are not picklable"
},
{
"__unicode__"
,
(
PyCFunction
)
Wrapper_unicode
,
METH_NOARGS
,
"Unicode"
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
src/Acquisition/tests.py
View file @
0de682e1
...
...
@@ -2435,13 +2435,51 @@ def test___parent__parent__circles():
AttributeError: non_existant_attr
"""
import
unittest
from
doctest
import
DocTestSuite
,
DocFileSuite
class
TestUnicode
(
unittest
.
TestCase
):
def
test_implicit_aq_unicode_should_be_called
(
self
):
class
A
(
Acquisition
.
Implicit
):
def
__unicode__
(
self
):
return
u'unicode was called'
wrapped
=
A
().
__of__
(
A
())
self
.
assertEqual
(
u'unicode was called'
,
unicode
(
wrapped
))
self
.
assertEqual
(
str
(
wrapped
),
repr
(
wrapped
))
def
test_explicit_aq_unicode_should_be_called
(
self
):
class
A
(
Acquisition
.
Explicit
):
def
__unicode__
(
self
):
return
u'unicode was called'
wrapped
=
A
().
__of__
(
A
())
self
.
assertEqual
(
u'unicode was called'
,
unicode
(
wrapped
))
self
.
assertEqual
(
str
(
wrapped
),
repr
(
wrapped
))
def
test_implicit_should_fall_back_to_str
(
self
):
class
A
(
Acquisition
.
Implicit
):
def
__str__
(
self
):
return
'str was called'
wrapped
=
A
().
__of__
(
A
())
self
.
assertEqual
(
u'str was called'
,
unicode
(
wrapped
))
self
.
assertEqual
(
'str was called'
,
str
(
wrapped
))
def
test_explicit_should_fall_back_to_str
(
self
):
class
A
(
Acquisition
.
Explicit
):
def
__str__
(
self
):
return
'str was called'
wrapped
=
A
().
__of__
(
A
())
self
.
assertEqual
(
u'str was called'
,
unicode
(
wrapped
))
self
.
assertEqual
(
'str was called'
,
str
(
wrapped
))
def
test_suite
():
return
unittest
.
TestSuite
((
DocTestSuite
(),
DocFileSuite
(
'README.txt'
,
package
=
'Acquisition'
),
unittest
.
makeSuite
(
TestUnicode
),
))
if
__name__
==
'__main__'
:
...
...
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