summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-09-19 20:51:17 (GMT)
committerGuido van Rossum <guido@python.org>2000-09-19 20:51:17 (GMT)
commitf8d071332a485ede280675a55e3319e136826dd0 (patch)
tree7a7cb427d79d51d62556e5188bc92c91f6d78622 /Tools
parent0eeba5b24b0cf5297421c7bd5dbc38aff774dc5f (diff)
downloadcpython-f8d071332a485ede280675a55e3319e136826dd0.zip
cpython-f8d071332a485ede280675a55e3319e136826dd0.tar.gz
cpython-f8d071332a485ede280675a55e3319e136826dd0.tar.bz2
Temporary fix for Bug #114821.
The cause was that the replace code necessarily used a PCRE internal function to to template expansion. The fix changes the code to use an SRE internal if SRE is used, and a PCRE internal if SRE is used; in a way that should work with 1.5.2. The solution can be sped up tremendously under the assumption that the choice between sre and pre is not changed during the execution of the program; especially replace-all will be slow. But I'll leave that to someone else.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/idle/ReplaceDialog.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/Tools/idle/ReplaceDialog.py b/Tools/idle/ReplaceDialog.py
index e29d4d6..83462f9 100644
--- a/Tools/idle/ReplaceDialog.py
+++ b/Tools/idle/ReplaceDialog.py
@@ -90,7 +90,7 @@ class ReplaceDialog(SearchDialogBase):
line, m = res
chars = text.get("%d.0" % line, "%d.0" % (line+1))
orig = m.group()
- new = re.pcre_expand(m, repl)
+ new = self._expand(m, repl)
i, j = m.span()
first = "%d.%d" % (line, i)
last = "%d.%d" % (line, j)
@@ -142,7 +142,7 @@ class ReplaceDialog(SearchDialogBase):
m = prog.match(chars, col)
if not prog:
return 0
- new = re.pcre_expand(m, self.replvar.get())
+ new = self._expand(m, self.replvar.get())
text.mark_set("insert", first)
text.undo_block_start()
if m.group():
@@ -154,6 +154,22 @@ class ReplaceDialog(SearchDialogBase):
self.ok = 0
return 1
+ def _expand(self, m, template):
+ # XXX This code depends on internals of the regular expression
+ # engine! There's no standard API to do a substitution when you
+ # have already found the match. One should be added.
+ # The solution here is designed to be backwards compatible
+ # with previous Python versions, e.g. 1.5.2.
+ # XXX This dynamic test should be done only once.
+ if getattr(re, "engine", "pre") == "pre":
+ return re.pcre_expand(m, template)
+ else: # sre
+ # XXX This import should be avoidable...
+ import sre_parse
+ # XXX This parses the template over and over...
+ ptemplate = sre_parse.parse_template(template, m.re)
+ return sre_parse.expand_template(ptemplate, m)
+
def show_hit(self, first, last):
text = self.text
text.mark_set("insert", first)