[pypy-commit] pyrepl codecheck-clean: clean some more files
RonnyPfannschmidt
noreply at buildbot.pypy.org
Tue Jan 15 11:55:14 CET 2013
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: codecheck-clean
Changeset: r214:e07229306d89
Date: 2013-01-15 11:26 +0100
http://bitbucket.org/pypy/pyrepl/changeset/e07229306d89/
Log: clean some more files
diff --git a/pyrepl/_minimal_curses.py b/pyrepl/_minimal_curses.py
--- a/pyrepl/_minimal_curses.py
+++ b/pyrepl/_minimal_curses.py
@@ -9,7 +9,8 @@
hide this one if compiled in.
"""
-import ctypes, ctypes.util
+import ctypes.util
+
class error(Exception):
pass
@@ -42,8 +43,12 @@
# ____________________________________________________________
-try: from __pypy__ import builtinify
-except ImportError: builtinify = lambda f: f
+try:
+ from __pypy__ import builtinify
+ builtinify # silence broken pyflakes
+except ImportError:
+ builtinify = lambda f: f
+
@builtinify
def setupterm(termstr, fd):
@@ -52,6 +57,7 @@
if result == ERR:
raise error("setupterm() failed (err=%d)" % err.value)
+
@builtinify
def tigetstr(cap):
if not isinstance(cap, bytes):
@@ -61,6 +67,7 @@
return None
return ctypes.cast(result, ctypes.c_char_p).value
+
@builtinify
def tparm(str, i1=0, i2=0, i3=0, i4=0, i5=0, i6=0, i7=0, i8=0, i9=0):
result = clib.tparm(str, i1, i2, i3, i4, i5, i6, i7, i8, i9)
diff --git a/pyrepl/completer.py b/pyrepl/completer.py
--- a/pyrepl/completer.py
+++ b/pyrepl/completer.py
@@ -19,10 +19,12 @@
try:
import __builtin__ as builtins
+ builtins # silence broken pyflakes
except ImportError:
import builtins
-class Completer:
+
+class Completer(object):
def __init__(self, ns):
self.ns = ns
@@ -79,11 +81,10 @@
matches.append("%s.%s" % (expr, word))
return matches
+
def get_class_members(klass):
ret = dir(klass)
if hasattr(klass, '__bases__'):
for base in klass.__bases__:
ret = ret + get_class_members(base)
return ret
-
-
diff --git a/pyrepl/completing_reader.py b/pyrepl/completing_reader.py
--- a/pyrepl/completing_reader.py
+++ b/pyrepl/completing_reader.py
@@ -18,11 +18,12 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+import re
from pyrepl import commands, reader
from pyrepl.reader import Reader
-def prefix(wordlist, j = 0):
+def prefix(wordlist, j=0):
d = {}
i = j
try:
@@ -36,14 +37,18 @@
except IndexError:
return wordlist[0][j:i]
-import re
+
+STRIPCOLOR_REGEX = re.compile(r"\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[m|K]")
+
+
def stripcolor(s):
- return stripcolor.regexp.sub('', s)
-stripcolor.regexp = re.compile(r"\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[m|K]")
+ return STRIPCOLOR_REGEX.regexp.sub('', s)
+
def real_len(s):
return len(stripcolor(s))
+
def left_align(s, maxlen):
stripped = stripcolor(s)
if len(stripped) > maxlen:
@@ -52,6 +57,7 @@
padding = maxlen - len(stripped)
return s + ' '*padding
+
def build_menu(cons, wordlist, start, use_brackets, sort_in_column):
if use_brackets:
item = "[ %s ]"
@@ -66,14 +72,14 @@
if sort_in_column:
# sort_in_column=False (default) sort_in_column=True
# A B C A D G
- # D E F B E
+ # D E F B E
# G C F
#
# "fill" the table with empty words, so we always have the same amout
# of rows for each column
missing = cols*rows - len(wordlist)
wordlist = wordlist + ['']*missing
- indexes = [(i%cols)*rows + i//cols for i in range(len(wordlist))]
+ indexes = [(i % cols) * rows + i // cols for i in range(len(wordlist))]
wordlist = [wordlist[i] for i in indexes]
menu = []
i = start
@@ -84,14 +90,14 @@
i += 1
if i >= len(wordlist):
break
- menu.append( ''.join(row) )
+ menu.append(''.join(row))
if i >= len(wordlist):
i = 0
break
if r + 5 > cons.height:
- menu.append(" %d more... "%(len(wordlist) - i))
+ menu.append(" %d more... " % (len(wordlist) - i))
break
- return menu, i
+ return menu, i
# this gets somewhat user interface-y, and as a result the logic gets
# very convoluted.
@@ -118,7 +124,7 @@
# only if the ``assume_immutable_completions`` is True.
#
# now it gets complicated.
-#
+#
# for the first press of a completion key:
# if there's a common prefix, stick it in.
@@ -140,22 +146,22 @@
# for subsequent bangs, rotate the menu around (if there are sufficient
# choices).
+
class complete(commands.Command):
def do(self):
r = self.reader
+ last_is_completer = r.last_command_is(self.__class__)
+ immutable_completions = r.assume_immutable_completions
+ completions_unchangable = last_is_completer and immutable_completions
stem = r.get_stem()
- if r.assume_immutable_completions and \
- r.last_command_is(self.__class__):
- completions = r.cmpltn_menu_choices
- else:
- r.cmpltn_menu_choices = completions = \
- r.get_completions(stem)
- if len(completions) == 0:
+ if not completions_unchangable:
+ r.cmpltn_menu_choices = r.get_completions(stem)
+
+ completions = r.cmpltn_menu_choices
+ if not completions:
r.error("no matches")
elif len(completions) == 1:
- if r.assume_immutable_completions and \
- len(completions[0]) == len(stem) and \
- r.last_command_is(self.__class__):
+ if completions_unchangable and len(completions[0]) == len(stem):
r.msg = "[ sole completion ]"
r.dirty = 1
r.insert(completions[0][len(stem):])
@@ -163,7 +169,7 @@
p = prefix(completions, len(stem))
if p:
r.insert(p)
- if r.last_command_is(self.__class__):
+ if last_is_completer:
if not r.cmpltn_menu_vis:
r.cmpltn_menu_vis = 1
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
@@ -177,6 +183,7 @@
r.msg = "[ not unique ]"
r.dirty = 1
+
class self_insert(commands.self_insert):
def do(self):
commands.self_insert.do(self)
@@ -195,6 +202,7 @@
else:
r.cmpltn_reset()
+
class CompletingReader(Reader):
"""Adds completion support
@@ -204,26 +212,25 @@
"""
# see the comment for the complete command
assume_immutable_completions = True
- use_brackets = True # display completions inside []
+ use_brackets = True # display completions inside []
sort_in_column = False
-
+
def collect_keymap(self):
return super(CompletingReader, self).collect_keymap() + (
(r'\t', 'complete'),)
-
+
def __init__(self, console):
super(CompletingReader, self).__init__(console)
self.cmpltn_menu = ["[ menu 1 ]", "[ menu 2 ]"]
self.cmpltn_menu_vis = 0
self.cmpltn_menu_end = 0
- for c in [complete, self_insert]:
+ for c in (complete, self_insert):
self.commands[c.__name__] = c
- self.commands[c.__name__.replace('_', '-')] = c
+ self.commands[c.__name__.replace('_', '-')] = c
def after_command(self, cmd):
super(CompletingReader, self).after_command(cmd)
- if not isinstance(cmd, self.commands['complete']) \
- and not isinstance(cmd, self.commands['self_insert']):
+ if not isinstance(cmd, (complete, self_insert)):
self.cmpltn_reset()
def calc_screen(self):
@@ -243,7 +250,7 @@
self.cmpltn_menu = []
self.cmpltn_menu_vis = 0
self.cmpltn_menu_end = 0
- self.cmpltn_menu_choices = []
+ self.cmpltn_menu_choices = []
def get_stem(self):
st = self.syntax_table
@@ -257,11 +264,14 @@
def get_completions(self, stem):
return []
+
def test():
class TestReader(CompletingReader):
def get_completions(self, stem):
- return [s for l in map(lambda x:x.split(),self.history)
- for s in l if s and s.startswith(stem)]
+ return [s for l in self.history
+ for s in l.split()
+ if s and s.startswith(stem)]
+
reader = TestReader()
reader.ps1 = "c**> "
reader.ps2 = "c/*> "
@@ -270,5 +280,6 @@
while reader.readline():
pass
-if __name__=='__main__':
+
+if __name__ == '__main__':
test()
diff --git a/pyrepl/console.py b/pyrepl/console.py
--- a/pyrepl/console.py
+++ b/pyrepl/console.py
@@ -17,6 +17,7 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
class Event(object):
"""An Event. `evt' is 'key' or somesuch."""
__slots__ = 'evt', 'data', 'raw'
@@ -27,7 +28,8 @@
self.raw = raw
def __repr__(self):
- return 'Event(%r, %r)'%(self.evt, self.data)
+ return 'Event(%r, %r)' % (self.evt, self.data)
+
class Console(object):
"""Attributes:
@@ -36,7 +38,7 @@
height,
width,
"""
-
+
def refresh(self, screen, xy):
pass
More information about the pypy-commit
mailing list