34
34
pyrepl."""
35
35
36
36
37
+ import cmd
37
38
38
39
from pyrepl import completer
39
40
from pyrepl .completing_reader import CompletingReader as CR
40
- import cmd
41
41
42
42
43
43
class CmdReader (CR ):
44
44
def collect_keymap (self ):
45
45
return super (CmdReader , self ).collect_keymap () + (
46
46
("\\ M-\\ n" , "invalid-key" ),
47
- ("\\ n" , "accept" ))
47
+ ("\\ n" , "accept" ),
48
+ )
48
49
49
50
def __init__ (self , completions ):
50
51
super (CmdReader , self ).__init__ ()
@@ -53,13 +54,10 @@ def __init__(self, completions):
53
54
def get_completions (self , stem ):
54
55
if len (stem ) != self .pos :
55
56
return []
56
- return sorted (set (s
57
- for s in self .completions
58
- if s .startswith (stem )))
57
+ return sorted (set (s for s in self .completions if s .startswith (stem )))
59
58
60
59
61
60
def replize (klass , history_across_invocations = 1 ):
62
-
63
61
"""Return a subclass of the cmd.Cmd-derived klass that uses
64
62
pyrepl instead of readline.
65
63
@@ -69,13 +67,13 @@ def replize(klass, history_across_invocations=1):
69
67
controls whether instances of the returned class share
70
68
histories."""
71
69
72
- completions = [s [ 3 :]
73
- for s in completer .get_class_members (klass )
74
- if s . startswith ( "do_" ) ]
70
+ completions = [
71
+ s [ 3 :] for s in completer .get_class_members (klass ) if s . startswith ( "do_" )
72
+ ]
75
73
76
74
assert issubclass (klass , cmd .Cmd )
77
- # if klass.cmdloop.im_class is not cmd.Cmd:
78
- # print "this may not work"
75
+ # if klass.cmdloop.im_class is not cmd.Cmd:
76
+ # print "this may not work"
79
77
80
78
class MultiHist (object ):
81
79
__history = []
@@ -118,4 +116,5 @@ def cmdloop(self, intro=None):
118
116
119
117
class CmdRepl (hist , CmdLoopMixin , klass ):
120
118
__name__ = "replize(%s.%s)" % (klass .__module__ , klass .__name__ )
119
+
121
120
return CmdRepl
0 commit comments