[Checkins] SVN: Acquisition/branches/zagy-unicode-should-be-called/ - Fixed bug: ``unicode(wrapped)`` was not calling a ``__unicode__``
Christian Zagrodnick
cz at gocept.com
Wed Feb 16 16:16:22 EST 2011
Log message for revision 120393:
- Fixed bug: ``unicode(wrapped)`` was not calling a ``__unicode__``
method on wrapped objects.
Changed:
U Acquisition/branches/zagy-unicode-should-be-called/CHANGES.txt
U Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/_Acquisition.c
U Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/tests.py
-=-
Modified: Acquisition/branches/zagy-unicode-should-be-called/CHANGES.txt
===================================================================
--- Acquisition/branches/zagy-unicode-should-be-called/CHANGES.txt 2011-02-16 21:13:57 UTC (rev 120392)
+++ Acquisition/branches/zagy-unicode-should-be-called/CHANGES.txt 2011-02-16 21:16:22 UTC (rev 120393)
@@ -6,6 +6,9 @@
- Add ``aq_explicit`` to ``IAcquisitionWrapper``.
+- Fixed bug: ``unicode(wrapped)`` was not calling a ``__unicode__``
+ method on wrapped objects.
+
2.13.5 (2010-09-29)
-------------------
Modified: Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/_Acquisition.c
===================================================================
--- Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/_Acquisition.c 2011-02-16 21:13:57 UTC (rev 120392)
+++ Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/_Acquisition.c 2011-02-16 21:16:22 UTC (rev 120393)
@@ -51,7 +51,7 @@
*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__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_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 @@
}
}
+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 @@
"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 */
};
Modified: Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/tests.py
===================================================================
--- Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/tests.py 2011-02-16 21:13:57 UTC (rev 120392)
+++ Acquisition/branches/zagy-unicode-should-be-called/src/Acquisition/tests.py 2011-02-16 21:16:22 UTC (rev 120393)
@@ -2435,13 +2435,31 @@
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'
+ 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():
return unittest.TestSuite((
DocTestSuite(),
DocFileSuite('README.txt', package='Acquisition'),
+ unittest.makeSuite(TestUnicode),
))
if __name__ == '__main__':
More information about the checkins
mailing list