summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-07-08 13:26:57 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-07-08 13:26:57 (GMT)
commit2d96f11d07a13b461589169b1db49d310a6edc0b (patch)
treeccd4b966451265ffe4a5e1e31732d1841e125751 /Modules
parent44835d8e7ad180413f85743d53831cb648c4549a (diff)
downloadcpython-2d96f11d07a13b461589169b1db49d310a6edc0b.zip
cpython-2d96f11d07a13b461589169b1db49d310a6edc0b.tar.gz
cpython-2d96f11d07a13b461589169b1db49d310a6edc0b.tar.bz2
map re.sub() to string.replace(), when possible
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sre.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 1e5f618..caf47aa 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1955,6 +1955,28 @@ pattern_deepcopy(PatternObject* self, PyObject* args)
#endif
}
+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},
{"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS},
@@ -1965,6 +1987,7 @@ static PyMethodDef pattern_methods[] = {
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
{"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},
{"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_VARARGS},
+ {"_isliteral", (PyCFunction) pattern_isliteral, METH_VARARGS},
{NULL, NULL}
};