Commits

Brian Kearns committed 02a691b

backport some obvious fixes/cleanups from pyrepl including a fix for issue1098

dup fds for UnixConsole and and check for closed stdout before flushing
use reverse=True instead of negative comparator
kill uniqify for sorted(set(...))
kill disabled setaf writeout code

Comments (0)

Files changed (5)

lib_pypy/pyrepl/cmdrepl.py

     def get_completions(self, stem):
         if len(stem) != self.pos:
             return []
-        return cr.uniqify([s for s in self.completions
-                           if s.startswith(stem)])
+        return sorted(set(s for s in self.completions
+                           if s.startswith(stem)))
 
 def replize(klass, history_across_invocations=1):
 

lib_pypy/pyrepl/completing_reader.py

 from pyrepl import commands, reader
 from pyrepl.reader import Reader
 
-def uniqify(l):
-    d = {}
-    for i in l:
-        d[i] = 1
-    r = d.keys()
-    r.sort()
-    return r
 
 def prefix(wordlist, j = 0):
     d = {}

lib_pypy/pyrepl/module_lister.py

 # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-from pyrepl.completing_reader import uniqify
 import os, sys
 
 # for the completion support.
             l.append( prefix + fname )
             _packages[prefix + fname] = _make_module_list_dir(
                 file, suffs, prefix + fname + '.' )
-    l = uniqify(l)
-    l.sort()
-    return l
+    return sorted(set(l))
 
 def _make_module_list():
     import imp
     suffs = [x[0] for x in imp.get_suffixes() if x[0] != '.pyc']
-    def compare(x, y):
-        c = -cmp(len(x), len(y))
-        if c:
-            return c
-        else:
-            return -cmp(x, y)
-    suffs.sort(compare)
+    suffs.sort(reverse=True)
     _packages[''] = list(sys.builtin_module_names)
     for dir in sys.path:
         if dir == '':

lib_pypy/pyrepl/python_reader.py

                 return [x[len(mod) + 1:]
                         for x in l if x.startswith(mod + '.' + name)]
         try:
-            l = completing_reader.uniqify(self.completer.complete(stem))
+            l = sorted(set(self.completer.complete(stem)))
             return l
         except (NameError, AttributeError):
             return []
             self.showsyntaxerror("<input>")
         else:
             self.runcode(code)
-            sys.stdout.flush()
+            if sys.stdout and not sys.stdout.closed:
+                sys.stdout.flush()
 
     def interact(self):
         while 1:
                         encoding = None
                 else:
                     encoding = None # so you get ASCII...
-            con = UnixConsole(0, 1, None, encoding)
+            con = UnixConsole(os.dup(0), os.dup(1), None, encoding)
         if print_banner:
             print "Python", sys.version, "on", sys.platform
             print 'Type "help", "copyright", "credits" or "license" '\

lib_pypy/pyrepl/unix_console.py

         old_offset = offset = self.__offset
         height = self.height
 
-        if 0:
-            global counter
-            try:
-                counter
-            except NameError:
-                counter = 0
-            self.__write_code(curses.tigetstr("setaf"), counter)
-            counter += 1
-            if counter > 8:
-                counter = 0
 
         # we make sure the cursor is on the screen, and that we're
         # using all of the screen if we can