Commit 7b3c975a authored by Sean Reifschneider's avatar Sean Reifschneider

closes #14259 re.finditer() now takes keyword arguments: pos, endpos.

Contrary to the documentation, finditer() did not take pos and endpos
keyword arguments.
parent 45e50de1
...@@ -652,6 +652,26 @@ class ReTests(unittest.TestCase): ...@@ -652,6 +652,26 @@ class ReTests(unittest.TestCase):
self.assertEqual([item.group(0) for item in iter], self.assertEqual([item.group(0) for item in iter],
[":", "::", ":::"]) [":", "::", ":::"])
pat = re.compile(r":+")
iter = pat.finditer("a:b::c:::d", 1, 10)
self.assertEqual([item.group(0) for item in iter],
[":", "::", ":::"])
pat = re.compile(r":+")
iter = pat.finditer("a:b::c:::d", pos=1, endpos=10)
self.assertEqual([item.group(0) for item in iter],
[":", "::", ":::"])
pat = re.compile(r":+")
iter = pat.finditer("a:b::c:::d", endpos=10, pos=1)
self.assertEqual([item.group(0) for item in iter],
[":", "::", ":::"])
pat = re.compile(r":+")
iter = pat.finditer("a:b::c:::d", pos=3, endpos=8)
self.assertEqual([item.group(0) for item in iter],
["::", "::"])
def test_bug_926075(self): def test_bug_926075(self):
self.assertTrue(re.compile('bug_926075') is not self.assertTrue(re.compile('bug_926075') is not
re.compile(b'bug_926075')) re.compile(b'bug_926075'))
......
...@@ -56,6 +56,9 @@ Extension Modules ...@@ -56,6 +56,9 @@ Extension Modules
- Issue #14212: The re module didn't retain a reference to buffers it was - Issue #14212: The re module didn't retain a reference to buffers it was
scanning, resulting in segfaults. scanning, resulting in segfaults.
- Issue #14259: The finditer() method of re objects did not take any
keyword arguments, contrary to the documentation.
What's New in Python 3.3.0 Alpha 1? What's New in Python 3.3.0 Alpha 1?
=================================== ===================================
......
...@@ -1596,7 +1596,7 @@ SRE_SEARCH(SRE_STATE* state, SRE_CODE* pattern) ...@@ -1596,7 +1596,7 @@ SRE_SEARCH(SRE_STATE* state, SRE_CODE* pattern)
/* see sre.h for object declarations */ /* see sre.h for object declarations */
static PyObject*pattern_new_match(PatternObject*, SRE_STATE*, int); static PyObject*pattern_new_match(PatternObject*, SRE_STATE*, int);
static PyObject*pattern_scanner(PatternObject*, PyObject*); static PyObject*pattern_scanner(PatternObject*, PyObject*, PyObject* kw);
static int static int
sre_literal_template(int charsize, char* ptr, Py_ssize_t len) sre_literal_template(int charsize, char* ptr, Py_ssize_t len)
...@@ -2132,13 +2132,13 @@ error: ...@@ -2132,13 +2132,13 @@ error:
#if PY_VERSION_HEX >= 0x02020000 #if PY_VERSION_HEX >= 0x02020000
static PyObject* static PyObject*
pattern_finditer(PatternObject* pattern, PyObject* args) pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw)
{ {
PyObject* scanner; PyObject* scanner;
PyObject* search; PyObject* search;
PyObject* iterator; PyObject* iterator;
scanner = pattern_scanner(pattern, args); scanner = pattern_scanner(pattern, args, kw);
if (!scanner) if (!scanner)
return NULL; return NULL;
...@@ -2576,10 +2576,10 @@ static PyMethodDef pattern_methods[] = { ...@@ -2576,10 +2576,10 @@ static PyMethodDef pattern_methods[] = {
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS, {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
pattern_findall_doc}, pattern_findall_doc},
#if PY_VERSION_HEX >= 0x02020000 #if PY_VERSION_HEX >= 0x02020000
{"finditer", (PyCFunction) pattern_finditer, METH_VARARGS, {"finditer", (PyCFunction) pattern_finditer, METH_VARARGS|METH_KEYWORDS,
pattern_finditer_doc}, pattern_finditer_doc},
#endif #endif
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS}, {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS|METH_KEYWORDS},
{"__copy__", (PyCFunction) pattern_copy, METH_NOARGS}, {"__copy__", (PyCFunction) pattern_copy, METH_NOARGS},
{"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O}, {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O},
{NULL, NULL} {NULL, NULL}
...@@ -3822,7 +3822,7 @@ static PyTypeObject Scanner_Type = { ...@@ -3822,7 +3822,7 @@ static PyTypeObject Scanner_Type = {
}; };
static PyObject* static PyObject*
pattern_scanner(PatternObject* pattern, PyObject* args) pattern_scanner(PatternObject* pattern, PyObject* args, PyObject* kw)
{ {
/* create search state object */ /* create search state object */
...@@ -3831,7 +3831,9 @@ pattern_scanner(PatternObject* pattern, PyObject* args) ...@@ -3831,7 +3831,9 @@ pattern_scanner(PatternObject* pattern, PyObject* args)
PyObject* string; PyObject* string;
Py_ssize_t start = 0; Py_ssize_t start = 0;
Py_ssize_t end = PY_SSIZE_T_MAX; Py_ssize_t end = PY_SSIZE_T_MAX;
if (!PyArg_ParseTuple(args, "O|nn:scanner", &string, &start, &end)) static char* kwlist[] = { "source", "pos", "endpos", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kw, "O|nn:scanner", kwlist,
&string, &start, &end))
return NULL; return NULL;
/* create scanner object */ /* create scanner object */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment