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

Skip to content

Commit f8c8cf8

Browse files
committed
Get rid of _expand() altogether - the match object supports m.expand().
1 parent 403e351 commit f8c8cf8

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

Tools/idle/ReplaceDialog.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import tkMessageBox
77
import SearchEngine
88
from SearchDialogBase import SearchDialogBase
9-
import sre_parse
109

1110
def replace(text):
1211
root = text._root()
@@ -91,7 +90,7 @@ def replace_all(self, event=None):
9190
line, m = res
9291
chars = text.get("%d.0" % line, "%d.0" % (line+1))
9392
orig = m.group()
94-
new = self._expand(m, repl)
93+
new = m.expand(repl)
9594
i, j = m.span()
9695
first = "%d.%d" % (line, i)
9796
last = "%d.%d" % (line, j)
@@ -143,7 +142,7 @@ def do_replace(self):
143142
m = prog.match(chars, col)
144143
if not prog:
145144
return False
146-
new = self._expand(m, self.replvar.get())
145+
new = m.expand(self.replvar.get())
147146
text.mark_set("insert", first)
148147
text.undo_block_start()
149148
if m.group():
@@ -155,14 +154,6 @@ def do_replace(self):
155154
self.ok = 0
156155
return True
157156

158-
def _expand(self, m, template):
159-
# XXX This code depends on internals of the regular expression
160-
# engine! There's no standard API to do a substitution when you
161-
# have already found the match. One should be added.
162-
# XXX This parses the template over and over...
163-
ptemplate = sre_parse.parse_template(template, m.re)
164-
return sre_parse.expand_template(ptemplate, m)
165-
166157
def show_hit(self, first, last):
167158
text = self.text
168159
text.mark_set("insert", first)

0 commit comments

Comments
 (0)