c = b.translate(None, delete=b'e')
self.assertEqual(c, b'hllo')
+ def test_sq_item(self):
+ _testcapi = test.support.import_module('_testcapi')
+ obj = self.type2test((42,))
+ with self.assertRaises(IndexError):
+ _testcapi.sequence_getitem(obj, -2)
+ with self.assertRaises(IndexError):
+ _testcapi.sequence_getitem(obj, 1)
+ self.assertEqual(_testcapi.sequence_getitem(obj, 0), 42)
+
class BytesTest(BaseBytesTest, unittest.TestCase):
type2test = bytes
}
+static PyObject *
+sequence_getitem(PyObject *self, PyObject *args)
+{
+ PyObject *seq;
+ Py_ssize_t i;
+ if (!PyArg_ParseTuple(args, "On", &seq, &i)) {
+ return NULL;
+ }
+ return PySequence_GetItem(seq, i);
+}
+
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", raise_memoryerror, METH_NOARGS},
{"negative_refcount", negative_refcount, METH_NOARGS},
#endif
{"write_unraisable_exc", test_write_unraisable_exc, METH_VARARGS},
+ {"sequence_getitem", sequence_getitem, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
static PyObject *
bytearray_getitem(PyByteArrayObject *self, Py_ssize_t i)
{
- if (i < 0)
- i += Py_SIZE(self);
if (i < 0 || i >= Py_SIZE(self)) {
PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
return NULL;