def testGetRoot(self):
        "figure out how getRoot behaves"
        import string
        root = introspect.getRoot("string.", ".")
        self.assertEquals("string", root)

        root = introspect.getRoot("string.join", "(")
        self.assertEquals("string.join", root)
Exemple #2
0
 def autoCompleteFunction(self, linePart):
     element = introspect.getRoot(linePart)
     funcName, funcParam, funcHelp = introspect.getCallTip(
         element, locals=self.interp.locals)
     self.fullCallTip = funcName, funcHelp
     callTip = self.maxCallTip(funcHelp)
     return len(funcName) - 1, funcParam, callTip
Exemple #3
0
def getAutoCompleteList(command = '', locals = None, includeMagic = 1,
                        includeSingle = 1, includeDouble = 1):
    """
Return list of auto-completion options for command.
The list of options will be based on the locals namespace.
    """
    attributes = []
    # Get the proper chunk of code from the command.
    root = introspect.getRoot(command, terminator = '.')
    try:
        if locals is not None:
            object = eval(root, locals)
        else:
            object = eval(root)
    except:
        pass
    else:
        attributes = introspect.getAttributeNames(object, includeMagic,
                                                  includeSingle, includeDouble)
        def createlist(obj):
            return [s.name() for s in obj if s.name() not in attributes]

        if hasattr(object, "children"):
            attributes.extend(createlist(object.children()))

        if hasattr(object, "parms"):
            attributes.extend(createlist(object.parms()))

        if hasattr(object, "parmTuples"):
            attributes.extend(createlist(object.parmTuples()))

    return attributes
Exemple #4
0
 def autoCompleteObject(self, linePart):
     element = introspect.getRoot(linePart)
     try:
         autoCompleteList = dir(eval(element, self.interp.locals))
         if len(autoCompleteList) > 0:
             #autoCompleteList = '\t'.join(sorted(autoCompleteList))
             autoCompleteList = '\t'.join(sorted([i for i in autoCompleteList if not i.startswith('_')],\
                     key=lambda s: s.lower()) + sorted([i for i in autoCompleteList if i.startswith('_')]))
     except:
         autoCompleteList = None
     return autoCompleteList
 def autoCompleteDict(self, linePart):
     element = introspect.getRoot(linePart)
     autoCompleteList = None
     try:
         object = eval(element, self.interp.locals)
         t = type(object)
         if t is dict or 'h5py.' in str(t):
             autoCompleteList = '\t'.join(sorted([repr(i) for i in object.keys()])) if len(object) < 1000 else None
     except:
         pass
     return autoCompleteList
Exemple #6
0
    def getCallTip(self, line, var, truncate=True):
        if not line:
            element = var
        else:
            element = introspect.getRoot(line)
        if len(element) < len(var): return
        try:
            object = eval(element, self.interp.locals)
        except:
            return
        if var in element:
            if line:
                try:
                    funcName, funcParam, funcHelp = introspect.getCallTip(
                        element, locals=self.interp.locals)
                except:
                    funcHelp = ''
            else:
                funcHelp = ''
            typ = str(type(object))
            if typ.startswith("<type '") and typ.endswith("'>"):
                typ = typ[7:-2]
            if funcHelp:
                textFull = funcHelp
                if truncate: funcHelp = self.maxCallTip(textFull)
                calltip = 'type: ', typ, '\ndoc: ', funcHelp
            else:
                textFull = str(object)
                if isinstance(object, ModuleType):
                    try:
                        textFull = textFull + '\nhelp:\n' + object.__doc__
                    except:
                        pass
                    value = textFull
                    if truncate: value = self.maxCallTip(textFull)
                    calltip = 'type: ', typ, '\nstr: ', ('\n' if '\n' in value
                                                         else '') + value
                else:
                    value = textFull
                    if truncate: value = self.maxCallTip(textFull)
                    if hasattr(object, '__len__'):
                        calltip = 'type: ', typ + ', len: %i' % len(
                            object), '\nstr: ', ('\n' if '\n' in value else
                                                 '') + value
                    else:
                        calltip = 'type: ', typ, '\nstr: ', (
                            '\n' if '\n' in value else '') + value
            self.fullCallTip = var, calltip[:-1] + (textFull, )
        nHighlight = 0
        for ct in calltip[:3]:
            nHighlight += len(ct)

        return element, str(nHighlight), calltip
 def _checkRoot(self, input, terminator, output):
     root = introspect.getRoot(command=input, terminator=terminator)
     self.assertEqual(root, output,
                      ':in: %r :t: %r :out: %r :root: %r' %
                      (input, terminator, output, root))
 def _checkRoot(self, input, terminator, output):
     root = introspect.getRoot(command=input, terminator=terminator)
     self.assertEqual(
         root, output, ':in: %r :t: %r :out: %r :root: %r' %
         (input, terminator, output, root))