Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/idlelib/GrepDialog.py

    r2 r391  
    33import sys
    44from Tkinter import *
    5 import SearchEngine
    6 from SearchDialogBase import SearchDialogBase
     5from idlelib import SearchEngine
     6from idlelib.SearchDialogBase import SearchDialogBase
    77
    88def grep(text, io=None, flist=None):
     
    6464            self.top.bell()
    6565            return
    66         from OutputWindow import OutputWindow
     66        from idlelib.OutputWindow import OutputWindow
    6767        save = sys.stdout
    6868        try:
     
    8282        for fn in list:
    8383            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:
    8693                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.")
    10997
    11098    def findfiles(self, dir, base, rec):
    11199        try:
    112100            names = os.listdir(dir or os.curdir)
    113         except os.error, msg:
     101        except os.error as msg:
    114102            print msg
    115103            return []
     
    132120            self.top.grab_release()
    133121            self.top.withdraw()
     122
     123if __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.