summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-04-26 03:09:45 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-04-26 03:09:45 (GMT)
commitba42fd5801af664060dd90fccc4054b73967944c (patch)
tree4dc15aa0aac6a604f28de7a316701c0c4c64425f /Objects
parent2043f9c582943ec7624f8aec5dc58e59a0b9a5b0 (diff)
downloadcpython-ba42fd5801af664060dd90fccc4054b73967944c.zip
cpython-ba42fd5801af664060dd90fccc4054b73967944c.tar.gz
cpython-ba42fd5801af664060dd90fccc4054b73967944c.tar.bz2
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytearrayobject.c16
-rw-r--r--Objects/bytesobject.c12
-rw-r--r--Objects/unicodeobject.c21
3 files changed, 36 insertions, 13 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 6fc229d..27affb5 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1281,7 +1281,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)
@@ -1308,8 +1308,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);
}
@@ -1320,7 +1324,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)
@@ -1347,8 +1351,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 616f390..f2ee131 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2654,8 +2654,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);
}
@@ -2694,8 +2698,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 877640d..2cdbc0e 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1554,7 +1554,7 @@ PyUnicode_FSConverter(PyObject* arg, void* addr)
arg = PyUnicode_FromObject(arg);
if (!arg)
return 0;
- output = PyUnicode_AsEncodedObject(arg,
+ output = PyUnicode_AsEncodedObject(arg,
Py_FileSystemDefaultEncoding,
"surrogateescape");
Py_DECREF(arg);
@@ -1569,7 +1569,7 @@ PyUnicode_FSConverter(PyObject* arg, void* addr)
if (PyBytes_Check(output)) {
size = PyBytes_GET_SIZE(output);
data = PyBytes_AS_STRING(output);
- }
+ }
else {
size = PyByteArray_GET_SIZE(output);
data = PyByteArray_AS_STRING(output);
@@ -2148,7 +2148,7 @@ char utf8_code_length[256] = {
illegal prefix. See RFC 3629 for details */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00-0F */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -2631,7 +2631,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
#endif
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
-
+
q = (unsigned char *)s;
e = q + size;
@@ -8743,8 +8743,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);
@@ -8787,9 +8791,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);