Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9880c8

Browse files
author
Steven M. Gava
committed
py-cvs merge, python 1.5.2 compatability
1 parent 42f6c64 commit e9880c8

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

Lib/idlelib/ReplaceDialog.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def replace_all(self, event=None):
9090
line, m = res
9191
chars = text.get("%d.0" % line, "%d.0" % (line+1))
9292
orig = m.group()
93-
new = re.pcre_expand(m, repl)
93+
new = self._expand(m, repl)
9494
i, j = m.span()
9595
first = "%d.%d" % (line, i)
9696
last = "%d.%d" % (line, j)
@@ -142,7 +142,7 @@ def do_replace(self):
142142
m = prog.match(chars, col)
143143
if not prog:
144144
return 0
145-
new = re.pcre_expand(m, self.replvar.get())
145+
new = self._expand(m, self.replvar.get())
146146
text.mark_set("insert", first)
147147
text.undo_block_start()
148148
if m.group():
@@ -154,6 +154,22 @@ def do_replace(self):
154154
self.ok = 0
155155
return 1
156156

157+
def _expand(self, m, template):
158+
# XXX This code depends on internals of the regular expression
159+
# engine! There's no standard API to do a substitution when you
160+
# have already found the match. One should be added.
161+
# The solution here is designed to be backwards compatible
162+
# with previous Python versions, e.g. 1.5.2.
163+
# XXX This dynamic test should be done only once.
164+
if getattr(re, "engine", "pre") == "pre":
165+
return re.pcre_expand(m, template)
166+
else: # sre
167+
# XXX This import should be avoidable...
168+
import sre_parse
169+
# XXX This parses the template over and over...
170+
ptemplate = sre_parse.parse_template(template, m.re)
171+
return sre_parse.expand_template(ptemplate, m)
172+
157173
def show_hit(self, first, last):
158174
text = self.text
159175
text.mark_set("insert", first)

0 commit comments

Comments
 (0)