mirror of
https://github.com/python/cpython.git
synced 2025-07-15 07:15:18 +00:00
startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
This commit is contained in:
parent
d07eaf177c
commit
ac4515063c
8 changed files with 197 additions and 64 deletions
|
@ -7150,13 +7150,8 @@ unicode_count(PyUnicodeObject *self, PyObject *args)
|
|||
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||
PyObject *result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring,
|
||||
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
|
||||
return NULL;
|
||||
|
||||
substring = (PyUnicodeObject *)PyUnicode_FromObject(
|
||||
(PyObject *)substring);
|
||||
if (substring == NULL)
|
||||
if (!stringlib_parse_args_finds_unicode("count", args, &substring,
|
||||
&start, &end))
|
||||
return NULL;
|
||||
|
||||
FIX_START_END(self);
|
||||
|
@ -7306,12 +7301,13 @@ Return -1 on failure.");
|
|||
static PyObject *
|
||||
unicode_find(PyUnicodeObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *substring;
|
||||
PyUnicodeObject *substring;
|
||||
Py_ssize_t start;
|
||||
Py_ssize_t end;
|
||||
Py_ssize_t result;
|
||||
|
||||
if (!_ParseTupleFinds(args, &substring, &start, &end))
|
||||
if (!stringlib_parse_args_finds_unicode("find", args, &substring,
|
||||
&start, &end))
|
||||
return NULL;
|
||||
|
||||
result = stringlib_find_slice(
|
||||
|
@ -7368,11 +7364,12 @@ static PyObject *
|
|||
unicode_index(PyUnicodeObject *self, PyObject *args)
|
||||
{
|
||||
Py_ssize_t result;
|
||||
PyObject *substring;
|
||||
PyUnicodeObject *substring;
|
||||
Py_ssize_t start;
|
||||
Py_ssize_t end;
|
||||
|
||||
if (!_ParseTupleFinds(args, &substring, &start, &end))
|
||||
if (!stringlib_parse_args_finds_unicode("index", args, &substring,
|
||||
&start, &end))
|
||||
return NULL;
|
||||
|
||||
result = stringlib_find_slice(
|
||||
|
@ -8230,12 +8227,13 @@ Return -1 on failure.");
|
|||
static PyObject *
|
||||
unicode_rfind(PyUnicodeObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *substring;
|
||||
PyUnicodeObject *substring;
|
||||
Py_ssize_t start;
|
||||
Py_ssize_t end;
|
||||
Py_ssize_t result;
|
||||
|
||||
if (!_ParseTupleFinds(args, &substring, &start, &end))
|
||||
if (!stringlib_parse_args_finds_unicode("rfind", args, &substring,
|
||||
&start, &end))
|
||||
return NULL;
|
||||
|
||||
result = stringlib_rfind_slice(
|
||||
|
@ -8257,12 +8255,13 @@ Like S.rfind() but raise ValueError when the substring is not found.");
|
|||
static PyObject *
|
||||
unicode_rindex(PyUnicodeObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *substring;
|
||||
PyUnicodeObject *substring;
|
||||
Py_ssize_t start;
|
||||
Py_ssize_t end;
|
||||
Py_ssize_t result;
|
||||
|
||||
if (!_ParseTupleFinds(args, &substring, &start, &end))
|
||||
if (!stringlib_parse_args_finds_unicode("rindex", args, &substring,
|
||||
&start, &end))
|
||||
return NULL;
|
||||
|
||||
result = stringlib_rfind_slice(
|
||||
|
@ -8725,8 +8724,7 @@ unicode_startswith(PyUnicodeObject *self,
|
|||
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||
int result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj,
|
||||
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
|
||||
if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end))
|
||||
return NULL;
|
||||
if (PyTuple_Check(subobj)) {
|
||||
Py_ssize_t i;
|
||||
|
@ -8771,8 +8769,7 @@ unicode_endswith(PyUnicodeObject *self,
|
|||
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||
int result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj,
|
||||
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
|
||||
if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end))
|
||||
return NULL;
|
||||
if (PyTuple_Check(subobj)) {
|
||||
Py_ssize_t i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue