mirror of https://github.com/python/cpython
-- changed findall to return empty strings instead of None
for undefined groups
This commit is contained in:
parent
8e6d571a7c
commit
5810064476
|
@ -177,6 +177,7 @@ try:
|
||||||
assert sre.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
|
assert sre.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
|
||||||
(":", ":"),
|
(":", ":"),
|
||||||
(":", "::")]
|
(":", "::")]
|
||||||
|
assert sre.findall("(a)|(b)", "abc") == [("a", ""), ("", "b")]
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise TestFailed, "sre.findall"
|
raise TestFailed, "sre.findall"
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
* 00-08-01 fl fixes for 1.6b1 (0.9.8)
|
* 00-08-01 fl fixes for 1.6b1 (0.9.8)
|
||||||
* 00-08-03 fl added recursion limit
|
* 00-08-03 fl added recursion limit
|
||||||
* 00-08-07 fl use PyOS_CheckStack() if available
|
* 00-08-07 fl use PyOS_CheckStack() if available
|
||||||
|
* 00-08-08 fl changed findall to return empty strings instead of None
|
||||||
*
|
*
|
||||||
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
|
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -568,9 +569,8 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
|
||||||
TRACE(("|%p|%p|ENTER %d\n", pattern, ptr, level));
|
TRACE(("|%p|%p|ENTER %d\n", pattern, ptr, level));
|
||||||
|
|
||||||
#if defined(USE_STACKCHECK)
|
#if defined(USE_STACKCHECK)
|
||||||
if (level % 10 == 0 && PyOS_CheckStack()) {
|
if (level % 10 == 0 && PyOS_CheckStack())
|
||||||
return SRE_ERROR_RECURSION_LIMIT;
|
return SRE_ERROR_RECURSION_LIMIT;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_RECURSION_LIMIT)
|
#if defined(USE_RECURSION_LIMIT)
|
||||||
|
@ -1352,20 +1352,20 @@ state_fini(SRE_STATE* state)
|
||||||
LOCAL(PyObject*)
|
LOCAL(PyObject*)
|
||||||
state_getslice(SRE_STATE* state, int index, PyObject* string)
|
state_getslice(SRE_STATE* state, int index, PyObject* string)
|
||||||
{
|
{
|
||||||
|
int i, j;
|
||||||
|
|
||||||
index = (index - 1) * 2;
|
index = (index - 1) * 2;
|
||||||
|
|
||||||
if (string == Py_None || !state->mark[index] || !state->mark[index+1]) {
|
if (string == Py_None || !state->mark[index] || !state->mark[index+1]) {
|
||||||
Py_INCREF(Py_None);
|
i = j = 0;
|
||||||
return Py_None;
|
} else {
|
||||||
|
i = ((char*)state->mark[index] - (char*)state->beginning) /
|
||||||
|
state->charsize;
|
||||||
|
j = ((char*)state->mark[index+1] - (char*)state->beginning) /
|
||||||
|
state->charsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PySequence_GetSlice(
|
return PySequence_GetSlice(string, i, j);
|
||||||
string,
|
|
||||||
((char*)state->mark[index] - (char*)state->beginning) /
|
|
||||||
state->charsize,
|
|
||||||
((char*)state->mark[index+1] - (char*)state->beginning) /
|
|
||||||
state->charsize
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue