Commit 0d605d8d authored by Christian Zagrodnick's avatar Christian Zagrodnick

- Fixed bug: ``unicode(wrapped)`` was not calling a ``__unicode__``

  method on wrapped objects.   
parent e8e240de
...@@ -6,6 +6,9 @@ Changelog ...@@ -6,6 +6,9 @@ Changelog
- Add ``aq_explicit`` to ``IAcquisitionWrapper``. - Add ``aq_explicit`` to ``IAcquisitionWrapper``.
- Fixed bug: ``unicode(wrapped)`` was not calling a ``__unicode__``
method on wrapped objects.
2.13.5 (2010-09-29) 2.13.5 (2010-09-29)
------------------- -------------------
......
...@@ -51,7 +51,7 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__, ...@@ -51,7 +51,7 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__,
*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__contains__, *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__unicode__, *py__cmp__,
*py__parent__, *py__iter__; *py__parent__, *py__iter__;
static PyObject *Acquired=0; static PyObject *Acquired=0;
...@@ -95,6 +95,7 @@ init_py_names(void) ...@@ -95,6 +95,7 @@ init_py_names(void)
INIT_PY_NAME(__call__); INIT_PY_NAME(__call__);
INIT_PY_NAME(__repr__); INIT_PY_NAME(__repr__);
INIT_PY_NAME(__str__); INIT_PY_NAME(__str__);
INIT_PY_NAME(__unicode__);
INIT_PY_NAME(__cmp__); INIT_PY_NAME(__cmp__);
INIT_PY_NAME(__parent__); INIT_PY_NAME(__parent__);
INIT_PY_NAME(__iter__); INIT_PY_NAME(__iter__);
...@@ -839,6 +840,23 @@ Wrapper_str(Wrapper *self) ...@@ -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 static long
Wrapper_hash(Wrapper *self) Wrapper_hash(Wrapper *self)
{ {
...@@ -1313,6 +1331,8 @@ static struct PyMethodDef Wrapper_methods[] = { ...@@ -1313,6 +1331,8 @@ static struct PyMethodDef Wrapper_methods[] = {
"Wrappers are not picklable"}, "Wrappers are not picklable"},
{"__reduce_ex__", (PyCFunction)Wrappers_are_not_picklable, METH_VARARGS, {"__reduce_ex__", (PyCFunction)Wrappers_are_not_picklable, METH_VARARGS,
"Wrappers are not picklable"}, "Wrappers are not picklable"},
{"__unicode__", (PyCFunction)Wrapper_unicode, METH_NOARGS,
"Unicode"},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
......
...@@ -2435,13 +2435,31 @@ def test___parent__parent__circles(): ...@@ -2435,13 +2435,31 @@ def test___parent__parent__circles():
AttributeError: non_existant_attr AttributeError: non_existant_attr
""" """
import unittest import unittest
from doctest import DocTestSuite, DocFileSuite 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'
self.assertEqual(u'unicode was called', unicode(A().__of__(A())))
def test_explicit_aq_unicode_should_be_called(self):
class A(Acquisition.Explicit):
def __unicode__(self):
return u'unicode was called'
self.assertEqual(u'unicode was called', unicode(A().__of__(A())))
def test_suite(): def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
DocTestSuite(), DocTestSuite(),
DocFileSuite('README.txt', package='Acquisition'), DocFileSuite('README.txt', package='Acquisition'),
unittest.makeSuite(TestUnicode),
)) ))
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment