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 __bytes__(self):
+ return b"bytes"
+ instance = C()
+ self.assertTrue("__bytes__" in dir(weakref.proxy(instance)))
+ self.assertEqual(bytes(weakref.proxy(instance)), b"bytes")
+
def test_proxy_index(self):
class C:
def __index__(self):
return generic(proxy, v, w); \
}
+#define WRAP_METHOD(method, special) \
+ static PyObject * \
+ method(PyObject *proxy) { \
+ UNWRAP(proxy); \
+ return PyObject_CallMethod(proxy, special, ""); \
+ }
+
/* direct slots */
}
+WRAP_METHOD(proxy_bytes, "__bytes__");
+
+
+static PyMethodDef proxy_methods[] = {
+ {"__bytes__", (PyCFunction)proxy_bytes, METH_NOARGS},
+ {NULL, NULL}
+};
+
+
static PyNumberMethods proxy_as_number = {
proxy_add, /*nb_add*/
proxy_sub, /*nb_subtract*/
0, /* tp_weaklistoffset */
(getiterfunc)proxy_iter, /* tp_iter */
(iternextfunc)proxy_iternext, /* tp_iternext */
+ proxy_methods, /* tp_methods */
};