reverse use of tokenize, to get the command under the cursor

This commit is contained in:
David Halter
2012-04-06 04:02:34 +02:00
parent 1724a64e8d
commit 09fcff0f91
2 changed files with 54 additions and 109 deletions

View File

@@ -35,22 +35,13 @@ class File(object):
if not self.module_name and not self.source:
raise AttributeError("Submit a module name or the source code")
elif self.module_name:
return self.load_module()
return self._load_module()
def load_module(self):
def _load_module(self):
self._parser = parsing.PyFuzzyParser(self.source)
del self.source # efficiency
return self._parser
def get_line(self, line):
if not self._line_cache:
self._line_cache = self.source.split('\n')
if 1 <= line <= len(self._line_cache):
return self._line_cache[line - 1]
else:
return None
def find_module(point_path):
"""
Find a module with a path (of the module, like usb.backend.libusb10).