mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merge with 3.4
This commit is contained in:
commit
eb5ba067c9
1 changed files with 29 additions and 20 deletions
|
@ -1,9 +1,14 @@
|
||||||
import os
|
import os
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import re # for htest
|
||||||
import sys
|
import sys
|
||||||
from tkinter import *
|
from tkinter import StringVar, BooleanVar, Checkbutton # for GrepDialog
|
||||||
|
from tkinter import Tk, Text, Button, SEL, END # for htest
|
||||||
from idlelib import SearchEngine
|
from idlelib import SearchEngine
|
||||||
|
import itertools
|
||||||
from idlelib.SearchDialogBase import SearchDialogBase
|
from idlelib.SearchDialogBase import SearchDialogBase
|
||||||
|
# Importing OutputWindow fails due to import loop
|
||||||
|
# EditorWindow -> GrepDialop -> OutputWindow -> EditorWindow
|
||||||
|
|
||||||
def grep(text, io=None, flist=None):
|
def grep(text, io=None, flist=None):
|
||||||
root = text._root()
|
root = text._root()
|
||||||
|
@ -63,7 +68,7 @@ class GrepDialog(SearchDialogBase):
|
||||||
if not path:
|
if not path:
|
||||||
self.top.bell()
|
self.top.bell()
|
||||||
return
|
return
|
||||||
from idlelib.OutputWindow import OutputWindow
|
from idlelib.OutputWindow import OutputWindow # leave here!
|
||||||
save = sys.stdout
|
save = sys.stdout
|
||||||
try:
|
try:
|
||||||
sys.stdout = OutputWindow(self.flist)
|
sys.stdout = OutputWindow(self.flist)
|
||||||
|
@ -79,21 +84,26 @@ class GrepDialog(SearchDialogBase):
|
||||||
pat = self.engine.getpat()
|
pat = self.engine.getpat()
|
||||||
print("Searching %r in %s ..." % (pat, path))
|
print("Searching %r in %s ..." % (pat, path))
|
||||||
hits = 0
|
hits = 0
|
||||||
for fn in list:
|
try:
|
||||||
try:
|
for fn in list:
|
||||||
with open(fn, errors='replace') as f:
|
try:
|
||||||
for lineno, line in enumerate(f, 1):
|
with open(fn, errors='replace') as f:
|
||||||
if line[-1:] == '\n':
|
for lineno, line in enumerate(f, 1):
|
||||||
line = line[:-1]
|
if line[-1:] == '\n':
|
||||||
if prog.search(line):
|
line = line[:-1]
|
||||||
sys.stdout.write("%s: %s: %s\n" %
|
if prog.search(line):
|
||||||
(fn, lineno, line))
|
sys.stdout.write("%s: %s: %s\n" %
|
||||||
hits += 1
|
(fn, lineno, line))
|
||||||
except OSError as msg:
|
hits += 1
|
||||||
print(msg)
|
except OSError as msg:
|
||||||
print(("Hits found: %s\n"
|
print(msg)
|
||||||
"(Hint: right-click to open locations.)"
|
print(("Hits found: %s\n"
|
||||||
% hits) if hits else "No hits.")
|
"(Hint: right-click to open locations.)"
|
||||||
|
% hits) if hits else "No hits.")
|
||||||
|
except AttributeError:
|
||||||
|
# Tk window has been closed, OutputWindow.text = None,
|
||||||
|
# so in OW.write, OW.text.insert fails.
|
||||||
|
pass
|
||||||
|
|
||||||
def findfiles(self, dir, base, rec):
|
def findfiles(self, dir, base, rec):
|
||||||
try:
|
try:
|
||||||
|
@ -120,7 +130,8 @@ class GrepDialog(SearchDialogBase):
|
||||||
self.top.grab_release()
|
self.top.grab_release()
|
||||||
self.top.withdraw()
|
self.top.withdraw()
|
||||||
|
|
||||||
def _grep_dialog(parent):
|
|
||||||
|
def _grep_dialog(parent): # for htest
|
||||||
from idlelib.PyShell import PyShellFileList
|
from idlelib.PyShell import PyShellFileList
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.title("Test GrepDialog")
|
root.title("Test GrepDialog")
|
||||||
|
@ -141,8 +152,6 @@ def _grep_dialog(parent):
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# A human test is a bit tricky since EditorWindow() imports this module.
|
|
||||||
# Hence Idle must be restarted after editing this file for a live test.
|
|
||||||
import unittest
|
import unittest
|
||||||
unittest.main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
|
unittest.main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue