]> granicus.if.org Git - python/commitdiff
Merged revisions 76395 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Thu, 19 Nov 2009 03:11:09 +0000 (03:11 +0000)
committerBenjamin Peterson <benjamin@python.org>
Thu, 19 Nov 2009 03:11:09 +0000 (03:11 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76395 | benjamin.peterson | 2009-11-18 21:00:02 -0600 (Wed, 18 Nov 2009) | 1 line

  #5037 proxy __unicode__ correctly
........

Lib/test/test_weakref.py
Misc/NEWS
Objects/weakrefobject.c

index aeafddab72dbb8f493a2fe8738bbde0d17117b1a..ba109aefd2b75736df34b1d9bd45b2dae40e3fcd 100644 (file)
@@ -188,6 +188,17 @@ class ReferencesTestCase(TestBase):
         self.assertEqual(L3[:5], p3[:5])
         self.assertEqual(L3[2:5], p3[2:5])
 
+    def test_proxy_unicode(self):
+        # See bug 5037
+        class C(object):
+            def __str__(self):
+                return "string"
+            def __unicode__(self):
+                return u"unicode"
+        instance = C()
+        self.assertTrue("__unicode__" in dir(weakref.proxy(instance)))
+        self.assertEqual(unicode(weakref.proxy(instance)), u"unicode")
+
     def test_proxy_index(self):
         class C:
             def __index__(self):
index c75f3699813d909c0d75974a5c97b9fec342e855..4e7d9e3bf12a8624c6655ec863d71287881ea541 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -251,6 +251,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5037: Proxy the __unicode__ special method instead to __unicode__
+  instead of __str__.
+
 - Issue #6894: Fixed the issue urllib2 doesn't respect "no_proxy" environment
 
 - Issue #6790: Make it possible again to pass an `array.array` to
index 9cdd02178d7083cbb6e0a74cca13712c00df97cb..1a998b64bd3d73d51f646239cd37694c5f63fd83 100644 (file)
@@ -433,6 +433,13 @@ proxy_checkref(PyWeakReference *proxy)
         return generic(proxy, v, w); \
     }
 
+#define WRAP_METHOD(method, special) \
+    static PyObject * \
+    method(PyObject *proxy) { \
+           UNWRAP(proxy); \
+               return PyObject_CallMethod(proxy, special, ""); \
+       }
+
 
 /* direct slots */
 
@@ -593,6 +600,15 @@ proxy_iternext(PyWeakReference *proxy)
 }
 
 
+WRAP_METHOD(proxy_unicode, "__unicode__");
+
+
+static PyMethodDef proxy_methods[] = {
+       {"__unicode__", (PyCFunction)proxy_unicode, METH_NOARGS},
+       {NULL, NULL}
+};
+
+
 static PyNumberMethods proxy_as_number = {
     proxy_add,              /*nb_add*/
     proxy_sub,              /*nb_subtract*/
@@ -684,6 +700,7 @@ _PyWeakref_ProxyType = {
     0,                                  /* tp_weaklistoffset */
     (getiterfunc)proxy_iter,            /* tp_iter */
     (iternextfunc)proxy_iternext,       /* tp_iternext */
+       proxy_methods,                      /* tp_methods */
 };