def matches(self, cursor_offset, line, **kwargs): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ if 'locals_' not in kwargs: return None locals_ = kwargs['locals_'] r = self.locate(cursor_offset, line) if r is None: return None matches = set() n = len(r.word) for word in KEYWORDS: if self.method_match(word, n, r.word): matches.add(word) for nspace in (builtins.__dict__, locals_): for word, val in iteritems(nspace): word = try_decode(word, 'ascii') # if identifier isn't ascii, don't complete (syntax error) if word is None: continue if (self.method_match(word, n, r.word) and word != "__builtins__"): matches.add(_callable_postfix(val, word)) return matches
def matches(self, cursor_offset, line, **kwargs): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ if 'locals_' not in kwargs: return None locals_ = kwargs['locals_'] r = self.locate(cursor_offset, line) if r is None: return None start, end, text = r matches = set() n = len(text) for word in KEYWORDS: if method_match(word, n, text): matches.add(word) for nspace in (builtins.__dict__, locals_): for word, val in iteritems(nspace): if method_match(word, n, text) and word != "__builtins__": word = try_decode(word, 'ascii') # if identifier isn't ascii, don't complete (syntax error) if word is None: continue matches.add(_callable_postfix(val, word)) return matches
def find_all_modules(path=None): """Return a list with all modules in `path`, which should be a list of directory names. If path is not given, sys.path will be used.""" if path is None: modules.update(try_decode(m, 'ascii') for m in sys.builtin_module_names) path = sys.path for p in path: if not p: p = os.curdir for module in find_modules(p): module = try_decode(module, 'ascii') if module is None: continue modules.add(module) yield
def find_all_modules(path=None): """Return a list with all modules in `path`, which should be a list of directory names. If path is not given, sys.path will be used.""" if path is None: modules.update( try_decode(m, 'ascii') for m in sys.builtin_module_names) path = sys.path for p in path: if not p: p = os.curdir for module in find_modules(p): module = try_decode(module, 'ascii') if module is None: continue modules.add(module) yield
def attr_matches(cw, prefix='', only_modules=False): """Attributes to replace name with""" full = '%s.%s' % (prefix, cw) if prefix else cw module_name, _, name_after_dot = full.rpartition('.') if module_name not in sys.modules: return set() module = sys.modules[module_name] if only_modules: matches = (name for name in dir(module) if (name.startswith(name_after_dot) and '%s.%s' % (module_name, name)) in sys.modules) else: matches = (name for name in dir(module) if name.startswith(name_after_dot)) module_part, _, _ = cw.rpartition('.') if module_part: matches = ('%s.%s' % (module_part, m) for m in matches) generator = (try_decode(match, 'ascii') for match in matches) return set(filter(lambda x: x is not None, generator))