Exemplo n.º 1
0
 def attr_complete(self, prefix, ctx):
     """Complete attributes of an object."""
     attrs = set()
     m = RE_ATTR.match(prefix)
     if m is None:
         return attrs
     expr, attr = m.group(1, 3)
     expr = subexpr_from_unbalanced(expr, '(', ')')
     expr = subexpr_from_unbalanced(expr, '[', ']')
     expr = subexpr_from_unbalanced(expr, '{', '}')
     try:
         val = builtins.evalx(expr, glbs=ctx)
     except:  # pylint:disable=bare-except
         try:
             val = builtins.evalx(expr, glbs=builtins.__dict__)
         except:  # pylint:disable=bare-except
             return attrs  # anything could have gone wrong!
     opts = dir(val)
     if len(attr) == 0:
         opts = [o for o in opts if not o.startswith('_')]
     else:
         opts = [o for o in opts if o.startswith(attr)]
     prelen = len(prefix)
     for opt in opts:
         a = getattr(val, opt)
         rpl = opt + '(' if callable(a) else opt
         # note that prefix[:prelen-len(attr)] != prefix[:-len(attr)]
         # when len(attr) == 0.
         comp = prefix[:prelen-len(attr)] + rpl
         attrs.add(comp)
     return attrs
Exemplo n.º 2
0
 def attr_complete(self, prefix, ctx):
     """Complete attributes of an object."""
     attrs = set()
     m = RE_ATTR.match(prefix)
     if m is None:
         return attrs
     expr, attr = m.group(1, 3)
     expr = subexpr_from_unbalanced(expr, '(', ')')
     expr = subexpr_from_unbalanced(expr, '[', ']')
     expr = subexpr_from_unbalanced(expr, '{', '}')
     try:
         val = builtins.evalx(expr, glbs=ctx)
     except:  # pylint:disable=bare-except
         try:
             val = builtins.evalx(expr, glbs=builtins.__dict__)
         except:  # pylint:disable=bare-except
             return attrs  # anything could have gone wrong!
     opts = dir(val)
     if len(attr) == 0:
         opts = [o for o in opts if not o.startswith('_')]
     else:
         csc = builtins.__xonsh_env__.get('CASE_SENSITIVE_COMPLETIONS')
         startswither = startswithnorm if csc else startswithlow
         attrlow = attr.lower()
         opts = [o for o in opts if startswither(o, attr, attrlow)]
     prelen = len(prefix)
     for opt in opts:
         a = getattr(val, opt)
         rpl = opt + '(' if callable(a) else opt
         # note that prefix[:prelen-len(attr)] != prefix[:-len(attr)]
         # when len(attr) == 0.
         comp = prefix[:prelen - len(attr)] + rpl
         attrs.add(comp)
     return attrs