summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
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}
};