def get_object(self, name): attributes = name.split('.') obj = eval(attributes.pop(0), self.interp.locals) while attributes: with inspection.AttrCleaner(obj): obj = getattr(obj, attributes.pop(0)) return obj
def attr_matches(self, text): """Taken from rlcompleter.py and bent to my will.""" m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) if not m: return [] expr, attr = m.group(1, 3) if expr.isdigit(): # Special case: float literal, using attrs here will result in # a SyntaxError return [] obj = eval(expr, self.interp.locals) with inspection.AttrCleaner(obj): matches = self.attr_lookup(obj, expr, attr) return matches
def attr_matches(text, namespace, autocomplete_mode): """Taken from rlcompleter.py and bent to my will. """ # Gna, Py 2.6's rlcompleter searches for __call__ inside the # instance instead of the type, so we monkeypatch to prevent # side-effects (__getattr__/__getattribute__) m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) if not m: return [] expr, attr = m.group(1, 3) obj = safe_eval(expr, namespace) if obj is SafeEvalFailed: return [] with inspection.AttrCleaner(obj): matches = attr_lookup(obj, expr, attr, autocomplete_mode) return matches
def matches(self, cursor_offset, line, **kwargs): if 'locals_' not in kwargs: return None locals_ = kwargs['locals_'] if locals_ is None: locals_ = __main__.__dict__ attr = self.locate(cursor_offset, line) try: obj = evaluate_current_expression(cursor_offset, line, locals_) except EvaluationError: return set() with inspection.AttrCleaner(obj): # strips leading dot matches = [m[1:] for m in self.attr_lookup(obj, '', attr.word)] return set(m for m in matches if few_enough_underscores(attr.word, m))
def attr_matches(self, text): """Taken from rlcompleter.py and bent to my will.""" # Gna, Py 2.6's rlcompleter searches for __call__ inside the # instance instead of the type, so we monkeypatch to prevent # side-effects (__getattr__/__getattribute__) m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) if not m: return [] expr, attr = m.group(1, 3) if expr.isdigit(): # Special case: float literal, using attrs here will result in # a SyntaxError return [] obj = eval(expr, self.locals) with inspection.AttrCleaner(obj): matches = self.attr_lookup(obj, expr, attr) return matches
def attr_matches(text, namespace): """Taken from rlcompleter.py and bent to my will. """ # Gna, Py 2.6's rlcompleter searches for __call__ inside the # instance instead of the type, so we monkeypatch to prevent # side-effects (__getattr__/__getattribute__) m = attr_matches_re.match(text) if not m: return [] expr, attr = m.group(1, 3) if expr.isdigit(): # Special case: float literal, using attrs here will result in # a SyntaxError return [] try: obj = safe_eval(expr, namespace) except EvaluationError: return [] with inspection.AttrCleaner(obj): matches = attr_lookup(obj, expr, attr) return matches
def _callable_postfix(self, value, word): """rlcompleter's _callable_postfix done right.""" with inspection.AttrCleaner(value): if inspection.is_callable(value): word += '(' return word