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