Author: Brian Kearns <[email protected]>
Branch:
Changeset: r61063:02a691b8f00d
Date: 2013-02-11 02:58 -0500
http://bitbucket.org/pypy/pypy/changeset/02a691b8f00d/
Log: 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
diff --git a/lib_pypy/pyrepl/cmdrepl.py b/lib_pypy/pyrepl/cmdrepl.py
--- a/lib_pypy/pyrepl/cmdrepl.py
+++ b/lib_pypy/pyrepl/cmdrepl.py
@@ -53,8 +53,8 @@
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):
diff --git a/lib_pypy/pyrepl/completing_reader.py
b/lib_pypy/pyrepl/completing_reader.py
--- a/lib_pypy/pyrepl/completing_reader.py
+++ b/lib_pypy/pyrepl/completing_reader.py
@@ -21,13 +21,6 @@
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 = {}
diff --git a/lib_pypy/pyrepl/module_lister.py b/lib_pypy/pyrepl/module_lister.py
--- a/lib_pypy/pyrepl/module_lister.py
+++ b/lib_pypy/pyrepl/module_lister.py
@@ -17,7 +17,6 @@
# 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.
@@ -38,20 +37,12 @@
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 == '':
diff --git a/lib_pypy/pyrepl/python_reader.py b/lib_pypy/pyrepl/python_reader.py
--- a/lib_pypy/pyrepl/python_reader.py
+++ b/lib_pypy/pyrepl/python_reader.py
@@ -140,7 +140,7 @@
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 []
@@ -178,7 +178,8 @@
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:
@@ -368,7 +369,7 @@
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" '\
diff --git a/lib_pypy/pyrepl/unix_console.py b/lib_pypy/pyrepl/unix_console.py
--- a/lib_pypy/pyrepl/unix_console.py
+++ b/lib_pypy/pyrepl/unix_console.py
@@ -185,16 +185,6 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit