summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-09-18 20:55:24 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-09-18 20:55:24 (GMT)
commit59b68656f846973840953220c4780f3558b59fb8 (patch)
tree6a91ff46e00681f594aa3c9280d268627d009cc5 /Modules/_sre.c
parentab3b0343b89b4683148dadaf89728ee1198ebee5 (diff)
downloadcpython-59b68656f846973840953220c4780f3558b59fb8.zip
cpython-59b68656f846973840953220c4780f3558b59fb8.tar.gz
cpython-59b68656f846973840953220c4780f3558b59fb8.tar.bz2
fixed #449964: sre.sub raises an exception if the template contains a
\g<x> group reference followed by a character escape (also restructured a few things on the way to fixing #449000)
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index b0ab663..32cd48b 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -31,7 +31,7 @@
* 2001-04-28 fl added __copy__ methods (work in progress)
* 2001-05-14 fl fixes for 1.5.2
* 2001-07-01 fl added BIGCHARSET support (from Martin von Loewis)
- * 2001-09-18 fl
+ * 2001-09-18 fl added _getliteral helper
*
* Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
*
@@ -1959,25 +1959,29 @@ pattern_deepcopy(PatternObject* self, PyObject* args)
}
static PyObject*
-pattern_isliteral(PatternObject* self, PyObject* args)
+pattern_getliteral(PatternObject* self, PyObject* args)
{
- /* internal: return true if pattern consists of literal text only */
+ /* internal: if the pattern is a literal string, return that
+ string. otherwise, return None */
SRE_CODE* code;
- PyObject* isliteral;
+ PyObject* literal;
- if (!PyArg_ParseTuple(args, ":_isliteral"))
+ if (!PyArg_ParseTuple(args, ":_getliteral"))
return NULL;
code = PatternObject_GetCode(self);
- if (code[0] == SRE_OP_INFO && code[2] & SRE_INFO_LITERAL)
- isliteral = Py_True;
- else
- isliteral = Py_False;
+ if (code[0] == SRE_OP_INFO && code[2] & SRE_INFO_LITERAL) {
+ /* FIXME: extract literal string from code buffer. we can't
+ use the pattern member, since it may contain untranslated
+ escape codes (see SF bug 449000) */
+ literal = Py_None;
+ } else
+ literal = Py_None; /* no literal */
- Py_INCREF(isliteral);
- return isliteral;
+ Py_INCREF(literal);
+ return literal;
}
static PyMethodDef pattern_methods[] = {
@@ -1990,7 +1994,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},
+ {"_getliteral", (PyCFunction) pattern_getliteral, METH_VARARGS},
{NULL, NULL}
};