[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.60,2.61

Fredrik Lundh effbot@users.sourceforge.net
Sun, 08 Jul 2001 06:26:59 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv27901/Modules

Modified Files:
	_sre.c 
Log Message:


map re.sub() to string.replace(), when possible


Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.60
retrieving revision 2.61
diff -C2 -r2.60 -r2.61
*** _sre.c	2001/07/03 20:32:36	2.60
--- _sre.c	2001/07/08 13:26:57	2.61
***************
*** 1956,1959 ****
--- 1956,1981 ----
  }
  
+ static PyObject*
+ pattern_isliteral(PatternObject* self, PyObject* args)
+ {
+     /* internal: return true if pattern consists of literal text only */
+ 
+     SRE_CODE* code;
+     PyObject* isliteral;
+ 
+     if (!PyArg_ParseTuple(args, ":_isliteral"))
+         return NULL;
+ 
+     code = PatternObject_GetCode(self);
+ 
+     if (code[0] == SRE_OP_INFO && code[2] & SRE_INFO_LITERAL)
+         isliteral = Py_True;
+     else
+         isliteral = Py_False;
+ 
+     Py_INCREF(isliteral);
+     return isliteral;
+ }
+ 
  static PyMethodDef pattern_methods[] = {
      {"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS},
***************
*** 1966,1969 ****
--- 1988,1992 ----
      {"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},
      {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_VARARGS},
+     {"_isliteral", (PyCFunction) pattern_isliteral, METH_VARARGS},
      {NULL, NULL}
  };