Index: Objects/bytearrayobject.c =================================================================== --- Objects/bytearrayobject.c (Revision 67926) +++ Objects/bytearrayobject.c (Arbeitskopie) @@ -1380,14 +1380,19 @@ &tableobj, &delobj)) return NULL; - if (_getbuffer(tableobj, &vtable) < 0) + if (tableobj == Py_None) { + table = NULL; + tableobj = NULL; + } else if (_getbuffer(tableobj, &vtable) < 0) { return NULL; - - if (vtable.len != 256) { - PyErr_SetString(PyExc_ValueError, - "translation table must be 256 characters long"); - result = NULL; - goto done; + } else { + if (vtable.len != 256) { + PyErr_SetString(PyExc_ValueError, + "translation table must be 256 characters long"); + result = NULL; + goto done; + } + table = (const char*)vtable.buf; } if (delobj != NULL) { @@ -1401,7 +1406,6 @@ vdel.len = 0; } - table = (const char *)vtable.buf; inlen = PyByteArray_GET_SIZE(input_obj); result = PyByteArray_FromStringAndSize((char *)NULL, inlen); if (result == NULL) @@ -1409,7 +1413,7 @@ output_start = output = PyByteArray_AsString(result); input = PyByteArray_AS_STRING(input_obj); - if (vdel.len == 0) { + if (vdel.len == 0 && table != NULL) { /* If no deletions are required, use faster code */ for (i = inlen; --i >= 0; ) { c = Py_CHARMASK(*input++); @@ -1417,10 +1421,15 @@ } goto done; } - - for (i = 0; i < 256; i++) - trans_table[i] = Py_CHARMASK(table[i]); + if (table == NULL) { + for (i = 0; i < 256; i++) + trans_table[i] = Py_CHARMASK(i); + } else { + for (i = 0; i < 256; i++) + trans_table[i] = Py_CHARMASK(table[i]); + } + for (i = 0; i < vdel.len; i++) trans_table[(int) Py_CHARMASK( ((unsigned char*)vdel.buf)[i] )] = -1; @@ -1435,7 +1444,8 @@ PyByteArray_Resize(result, output - output_start); done: - PyBuffer_Release(&vtable); + if (tableobj != NULL) + PyBuffer_Release(&vtable); if (delobj != NULL) PyBuffer_Release(&vdel); return result; Index: Lib/test/test_bytes.py =================================================================== --- Lib/test/test_bytes.py (Revision 67926) +++ Lib/test/test_bytes.py (Arbeitskopie) @@ -893,6 +893,8 @@ c = b.translate(rosetta, b'l') self.assertEqual(b, b'hello') self.assertEqual(c, b'hee') + c = b.translate(None, b'e') + self.assertEqual(c, b'hllo') def test_split_bytearray(self): self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])