1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from re import match, split
25 from rlcompleter import get_class_members
26
27
29 - def __init__(self, name_space={}, verbosity=0):
30 """Function for tab completion."""
31
32 self.name_space = name_space
33 self.verbosity = verbosity
34
35
37 """Function to create the dictionary of options for tab completion."""
38
39 self.list = sorted(self.name_space.keys())
40
41 self.options = []
42 for name in self.list:
43 if match(self.input, name):
44 self.options.append(name)
45
46
48 """Function to create the dictionary of options for tab completion."""
49
50
51 list = split(r'\.', self.input)
52 if len(list) == 0:
53 return
54
55
56 module = list[0]
57 for i in range(1, len(list)-1):
58 module = module + '.' + list[i]
59 object = eval(module, self.name_space)
60
61
62 self.list = dir(object)
63
64
65 if hasattr(object, '__class__'):
66 self.list.append('__class__')
67 self.list = self.list + get_class_members(object.__class__)
68
69
70 self.options = []
71 for name in self.list:
72 if match(list[-1], name):
73 self.options.append(module + '.' + name)
74
75 if self.verbosity:
76 print("List: " + repr(list))
77 print("Module: " + repr(module))
78 print("self.list: " + repr(self.list))
79 print("self.options: " + repr(self.options))
80
81
82 - def finish(self, input, state):
83 """Return the next possible completion for 'input'"""
84
85 self.input = input
86 self.state = state
87
88
89
90 if self.verbosity:
91 print("\nInput: " + repr(self.input))
92 if not "." in self.input:
93 if self.verbosity:
94 print("Creating list.")
95 self.create_list()
96 if self.verbosity:
97 print("\tOk.")
98 else:
99 if self.verbosity:
100 print("Creating sublist.")
101 self.create_sublist()
102 if self.verbosity:
103 print("\tOk.")
104
105
106
107 if self.verbosity:
108 print("Returning options.")
109 if self.state < len(self.options):
110 return self.options[self.state]
111 else:
112 return None
113