diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-26 03:45:24 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-26 03:45:24 (GMT) |
commit | bf1253b25ac6fc27beb9819dade9c4465ea493fc (patch) | |
tree | 8384277a6aa3d724947bde18989d2bc4ed17e37b /Objects | |
parent | dff18b0858a3433cc0aa457a43e63aad86900586 (diff) | |
parent | f2b3f780a160347b0759b8d0f8ea9c41a456f724 (diff) | |
download | cpython-bf1253b25ac6fc27beb9819dade9c4465ea493fc.zip cpython-bf1253b25ac6fc27beb9819dade9c4465ea493fc.tar.gz cpython-bf1253b25ac6fc27beb9819dade9c4465ea493fc.tar.bz2 |
#6780: merge with 3.2.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytearrayobject.c | 16 | ||||
-rw-r--r-- | Objects/bytesobject.c | 12 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 13 |
3 files changed, 32 insertions, 9 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 970a6b5..fba5758 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1304,7 +1304,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) @@ -1331,8 +1331,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); } @@ -1343,7 +1347,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) @@ -1370,8 +1374,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); } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 7561ae5..ea14be6 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2224,8 +2224,12 @@ bytes_startswith(PyBytesObject *self, PyObject *args) Py_RETURN_FALSE; } result = _bytes_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); } @@ -2264,8 +2268,12 @@ bytes_endswith(PyBytesObject *self, PyObject *args) Py_RETURN_FALSE; } result = _bytes_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); } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index efe6879..22d2137 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9101,8 +9101,12 @@ unicode_startswith(PyUnicodeObject *self, Py_RETURN_FALSE; } substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj); - if (substring == NULL) + if (substring == NULL) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + PyErr_Format(PyExc_TypeError, "startswith first arg must be str or " + "a tuple of str, not %s", Py_TYPE(subobj)->tp_name); return NULL; + } result = tailmatch(self, substring, start, end, -1); Py_DECREF(substring); return PyBool_FromLong(result); @@ -9145,9 +9149,12 @@ unicode_endswith(PyUnicodeObject *self, Py_RETURN_FALSE; } substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj); - if (substring == NULL) + if (substring == NULL) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + PyErr_Format(PyExc_TypeError, "endswith first arg must be str or " + "a tuple of str, not %s", Py_TYPE(subobj)->tp_name); return NULL; - + } result = tailmatch(self, substring, start, end, +1); Py_DECREF(substring); return PyBool_FromLong(result); |