mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
py-cvs merge, python 1.5.2 compatability
This commit is contained in:
parent
42f6c64816
commit
e9880c81b9
1 changed files with 18 additions and 2 deletions
|
@ -90,7 +90,7 @@ class ReplaceDialog(SearchDialogBase):
|
||||||
line, m = res
|
line, m = res
|
||||||
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
chars = text.get("%d.0" % line, "%d.0" % (line+1))
|
||||||
orig = m.group()
|
orig = m.group()
|
||||||
new = re.pcre_expand(m, repl)
|
new = self._expand(m, repl)
|
||||||
i, j = m.span()
|
i, j = m.span()
|
||||||
first = "%d.%d" % (line, i)
|
first = "%d.%d" % (line, i)
|
||||||
last = "%d.%d" % (line, j)
|
last = "%d.%d" % (line, j)
|
||||||
|
@ -142,7 +142,7 @@ class ReplaceDialog(SearchDialogBase):
|
||||||
m = prog.match(chars, col)
|
m = prog.match(chars, col)
|
||||||
if not prog:
|
if not prog:
|
||||||
return 0
|
return 0
|
||||||
new = re.pcre_expand(m, self.replvar.get())
|
new = self._expand(m, self.replvar.get())
|
||||||
text.mark_set("insert", first)
|
text.mark_set("insert", first)
|
||||||
text.undo_block_start()
|
text.undo_block_start()
|
||||||
if m.group():
|
if m.group():
|
||||||
|
@ -154,6 +154,22 @@ class ReplaceDialog(SearchDialogBase):
|
||||||
self.ok = 0
|
self.ok = 0
|
||||||
return 1
|
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):
|
def show_hit(self, first, last):
|
||||||
text = self.text
|
text = self.text
|
||||||
text.mark_set("insert", first)
|
text.mark_set("insert", first)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue