cpython: 0f38948cc6df (original) (raw)
Mercurial > cpython
changeset 78415:0f38948cc6df 3.2
Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. [#13052]
Andrew Svetlov andrew.svetlov@gmail.com | |
---|---|
date | Sat, 04 Aug 2012 21:38:22 +0300 |
parents | 66b53f555704 |
children | 9dcfba4d0357 4efad7fba42a |
files | Lib/idlelib/ReplaceDialog.py Misc/NEWS |
diffstat | 2 files changed, 29 insertions(+), 5 deletions(-)[+] [-] Lib/idlelib/ReplaceDialog.py 31 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/idlelib/ReplaceDialog.py +++ b/Lib/idlelib/ReplaceDialog.py @@ -2,6 +2,8 @@ from tkinter import * from idlelib import SearchEngine from idlelib.SearchDialogBase import SearchDialogBase +import re + def replace(text): root = text._root() @@ -11,6 +13,7 @@ def replace(text): dialog = engine._replacedialog dialog.open(text) + class ReplaceDialog(SearchDialogBase): title = "Replace Dialog" @@ -55,8 +58,23 @@ class ReplaceDialog(SearchDialogBase): def default_command(self, event=None): if self.do_find(self.ok):
self.do_replace()[](#l1.24)
self.do_find(0)[](#l1.25)
if self.do_replace(): # Only find next match if replace succeeded.[](#l1.26)
# A bad re can cause a it to fail.[](#l1.27)
self.do_find(0)[](#l1.28)
- def _replace_expand(self, m, repl):
""" Helper function for expanding a regular expression[](#l1.31)
in the replace field, if needed. """[](#l1.32)
if self.engine.isre():[](#l1.33)
try:[](#l1.34)
new = m.expand(repl)[](#l1.35)
except re.error:[](#l1.36)
self.engine.report_error(repl, 'Invalid Replace Expression')[](#l1.37)
new = None[](#l1.38)
else:[](#l1.39)
new = repl[](#l1.40)
return new[](#l1.42)
def replace_all(self, event=None): prog = self.engine.getprog() @@ -86,7 +104,9 @@ class ReplaceDialog(SearchDialogBase): line, m = res chars = text.get("%d.0" % line, "%d.0" % (line+1)) orig = m.group()
new = m.expand(repl)[](#l1.50)
new = self._replace_expand(m, repl)[](#l1.51)
if new is None:[](#l1.52)
break[](#l1.53) i, j = m.span()[](#l1.54) first = "%d.%d" % (line, i)[](#l1.55) last = "%d.%d" % (line, j)[](#l1.56)
@@ -103,7 +123,6 @@ class ReplaceDialog(SearchDialogBase): text.undo_block_stop() if first and last: self.show_hit(first, last)
self.close()[](#l1.61)
def do_find(self, ok=0): if not self.engine.getprog(): @@ -138,7 +157,9 @@ class ReplaceDialog(SearchDialogBase): m = prog.match(chars, col) if not prog: return False
new = m.expand(self.replvar.get())[](#l1.69)
new = self._replace_expand(m, self.replvar.get())[](#l1.70)
if new is None:[](#l1.71)
return False[](#l1.72) text.mark_set("insert", first)[](#l1.73) text.undo_block_start()[](#l1.74) if m.group():[](#l1.75)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,9 @@ Core and Builtins Library ------- +- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog