Changeset 391 for python/trunk/Lib/idlelib/GrepDialog.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/idlelib/GrepDialog.py
r2 r391 3 3 import sys 4 4 from Tkinter import * 5 import SearchEngine6 from SearchDialogBase import SearchDialogBase5 from idlelib import SearchEngine 6 from idlelib.SearchDialogBase import SearchDialogBase 7 7 8 8 def grep(text, io=None, flist=None): … … 64 64 self.top.bell() 65 65 return 66 from OutputWindow import OutputWindow66 from idlelib.OutputWindow import OutputWindow 67 67 save = sys.stdout 68 68 try: … … 82 82 for fn in list: 83 83 try: 84 f = open(fn) 85 except IOError, msg: 84 with open(fn) as f: 85 for lineno, line in enumerate(f, 1): 86 if line[-1:] == '\n': 87 line = line[:-1] 88 if prog.search(line): 89 sys.stdout.write("%s: %s: %s\n" % 90 (fn, lineno, line)) 91 hits += 1 92 except IOError as msg: 86 93 print msg 87 continue 88 lineno = 0 89 while 1: 90 block = f.readlines(100000) 91 if not block: 92 break 93 for line in block: 94 lineno = lineno + 1 95 if line[-1:] == '\n': 96 line = line[:-1] 97 if prog.search(line): 98 sys.stdout.write("%s: %s: %s\n" % (fn, lineno, line)) 99 hits = hits + 1 100 if hits: 101 if hits == 1: 102 s = "" 103 else: 104 s = "s" 105 print "Found", hits, "hit%s." % s 106 print "(Hint: right-click to open locations.)" 107 else: 108 print "No hits." 94 print(("Hits found: %s\n" 95 "(Hint: right-click to open locations.)" 96 % hits) if hits else "No hits.") 109 97 110 98 def findfiles(self, dir, base, rec): 111 99 try: 112 100 names = os.listdir(dir or os.curdir) 113 except os.error ,msg:101 except os.error as msg: 114 102 print msg 115 103 return [] … … 132 120 self.top.grab_release() 133 121 self.top.withdraw() 122 123 if __name__ == "__main__": 124 # A human test is a bit tricky since EditorWindow() imports this module. 125 # Hence Idle must be restarted after editing this file for a live test. 126 import unittest 127 unittest.main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
Note:
See TracChangeset
for help on using the changeset viewer.