[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.21,2.22 sre.h,2.11,2.12
Fredrik Lundh
python-dev@python.org
Sun, 2 Jul 2000 15:25:42 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv13488/Modules
Modified Files:
_sre.c sre.h
Log Message:
- experimental: added two new attributes to the match object:
"lastgroup" is the name of the last matched capturing group,
"lastindex" is the index of the same group. if no group was
matched, both attributes are set to None.
the (?P#) feature will be removed in the next relase.
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.21
retrieving revision 2.22
diff -C2 -r2.21 -r2.22
*** _sre.c 2000/07/02 17:33:27 2.21
--- _sre.c 2000/07/02 22:25:39 2.22
***************
*** 1105,1111 ****
int groups = 0;
PyObject* groupindex = NULL;
! if (!PyArg_ParseTuple(args, "OiO!|iO", &pattern, &flags,
&PyString_Type, &code,
! &groups, &groupindex))
return NULL;
--- 1105,1112 ----
int groups = 0;
PyObject* groupindex = NULL;
! PyObject* indexgroup = NULL;
! if (!PyArg_ParseTuple(args, "OiO!|iOO", &pattern, &flags,
&PyString_Type, &code,
! &groups, &groupindex, &indexgroup))
return NULL;
***************
*** 1128,1131 ****
--- 1129,1135 ----
self->groupindex = groupindex;
+ Py_XINCREF(indexgroup);
+ self->indexgroup = indexgroup;
+
return (PyObject*) self;
}
***************
*** 1884,1888 ****
PyErr_Clear();
! /* attributes */
if (!strcmp(name, "string")) {
Py_INCREF(self->string);
--- 1888,1913 ----
PyErr_Clear();
! if (!strcmp(name, "lastindex")) {
! /* experimental */
! if (self->index >= 0)
! return Py_BuildValue("i", self->index);
! Py_INCREF(Py_None);
! return Py_None;
! }
!
! if (!strcmp(name, "lastgroup")) {
! /* experimental */
! if (self->pattern->indexgroup) {
! PyObject* result = PySequence_GetItem(
! self->pattern->indexgroup, self->index
! );
! if (result)
! return result;
! PyErr_Clear();
! }
! Py_INCREF(Py_None);
! return Py_None;
! }
!
if (!strcmp(name, "string")) {
Py_INCREF(self->string);
***************
*** 1900,1912 ****
if (!strcmp(name, "endpos"))
return Py_BuildValue("i", 0); /* FIXME */
-
- if (!strcmp(name, "index")) {
- /* experimental */
- if (self->index < 0) {
- Py_INCREF(Py_None);
- return Py_None;
- } else
- return Py_BuildValue("i", self->index);
- }
PyErr_SetString(PyExc_AttributeError, name);
--- 1925,1928 ----
Index: sre.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/sre.h,v
retrieving revision 2.11
retrieving revision 2.12
diff -C2 -r2.11 -r2.12
*** sre.h 2000/07/02 17:33:27 2.11
--- sre.h 2000/07/02 22:25:39 2.12
***************
*** 22,25 ****
--- 22,26 ----
int groups;
PyObject* groupindex;
+ PyObject* indexgroup;
/* compatibility */
PyObject* pattern; /* pattern source (or None) */