Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
# instance instead of the type, so we monkeypatch to prevent
# side-effects (__getattr__/__getattribute__)
m = self.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 = self.attr_lookup(obj, expr, attr)
return matches
def safe_get_attribute(obj, attr):
"""Gets attributes without triggering descriptors on new-style classes"""
if is_new_style(obj):
with AttrCleaner(obj):
result = safe_get_attribute_new_style(obj, attr)
if isinstance(result, member_descriptor):
# will either be the same slot descriptor or the value
return getattr(obj, attr)
return result
return getattr(obj, attr)
def _callable_postfix(value, word):
"""rlcompleter's _callable_postfix done right."""
with inspection.AttrCleaner(value):
if inspection.is_callable(value):
word += "("
return word
# if f is a method from a xmlrpclib.Server instance, func_name ==
# '__init__' throws xmlrpclib.Fault (see #202)
return None
try:
if py3:
argspec = get_argspec_from_signature(f)
else:
argspec = list(inspect.getargspec(f))
fixlongargs(f, argspec)
if len(argspec) == 4:
argspec = argspec + [list(), dict(), None]
argspec = ArgSpec(*argspec)
fprops = FuncProps(func, argspec, is_bound_method)
except (TypeError, KeyError, ValueError):
with AttrCleaner(f):
argspec = getpydocspec(f, func)
if argspec is None:
return None
if inspect.ismethoddescriptor(f):
argspec.args.insert(0, "obj")
fprops = FuncProps(func, argspec, is_bound_method)
return fprops