summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-04-26 03:40:59 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-04-26 03:40:59 (GMT)
commitf2b3f780a160347b0759b8d0f8ea9c41a456f724 (patch)
tree459bb689054d19a6cc78d46ddaa9c0ce6cc19222 /Objects/bytearrayobject.c
parent0fb5b398cddbf75a121b93680c8f9771f2e8499c (diff)
parentba42fd5801af664060dd90fccc4054b73967944c (diff)
downloadcpython-f2b3f780a160347b0759b8d0f8ea9c41a456f724.zip
cpython-f2b3f780a160347b0759b8d0f8ea9c41a456f724.tar.gz
cpython-f2b3f780a160347b0759b8d0f8ea9c41a456f724.tar.bz2
#6780: merge with 3.1.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 827fded..7a74104 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1280,7 +1280,7 @@ PyDoc_STRVAR(startswith__doc__,
Return True if B starts with the specified prefix, False otherwise.\n\
With optional start, test B beginning at that position.\n\
With optional end, stop comparing B at that position.\n\
-prefix can also be a tuple of strings to try.");
+prefix can also be a tuple of bytes to try.");
static PyObject *
bytearray_startswith(PyByteArrayObject *self, PyObject *args)
@@ -1307,8 +1307,12 @@ bytearray_startswith(PyByteArrayObject *self, PyObject *args)
Py_RETURN_FALSE;
}
result = _bytearray_tailmatch(self, subobj, start, end, -1);
- if (result == -1)
+ if (result == -1) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ PyErr_Format(PyExc_TypeError, "startswith first arg must be bytes "
+ "or a tuple of bytes, not %s", Py_TYPE(subobj)->tp_name);
return NULL;
+ }
else
return PyBool_FromLong(result);
}
@@ -1319,7 +1323,7 @@ PyDoc_STRVAR(endswith__doc__,
Return True if B ends with the specified suffix, False otherwise.\n\
With optional start, test B beginning at that position.\n\
With optional end, stop comparing B at that position.\n\
-suffix can also be a tuple of strings to try.");
+suffix can also be a tuple of bytes to try.");
static PyObject *
bytearray_endswith(PyByteArrayObject *self, PyObject *args)
@@ -1346,8 +1350,12 @@ bytearray_endswith(PyByteArrayObject *self, PyObject *args)
Py_RETURN_FALSE;
}
result = _bytearray_tailmatch(self, subobj, start, end, +1);
- if (result == -1)
+ if (result == -1) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ PyErr_Format(PyExc_TypeError, "endswith first arg must be bytes or "
+ "a tuple of bytes, not %s", Py_TYPE(subobj)->tp_name);
return NULL;
+ }
else
return PyBool_FromLong(result);
}