table = string.maketrans('a', 'A')
test('translate', 'abc', 'Abc', table)
test('translate', 'xyz', 'xyz', table)
+ test('translate', 'xyz', ValueError, 'too short', 'strip')
+ test('translate', 'xyz', ValueError, 'too short')
test('replace', 'one!two!three!', 'one@two!three!', '!', '@', 1)
test('replace', 'one!two!three!', 'onetwothree', '!', '')
else if (PyObject_AsCharBuffer(tableobj, &table1, &tablen))
return NULL;
+ if (tablen != 256) {
+ PyErr_SetString(PyExc_ValueError,
+ "translation table must be 256 characters long");
+ return NULL;
+ }
+
if (delobj != NULL) {
if (PyString_Check(delobj)) {
del_table = PyString_AS_STRING(delobj);
#endif
else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen))
return NULL;
-
- if (tablen != 256) {
- PyErr_SetString(PyExc_ValueError,
- "translation table must be 256 characters long");
- return NULL;
- }
}
else {
del_table = NULL;