示例#1
0
    def getDescription(self, text):
        try:
            obj = None
            if '.' not in text:
                try:
                    obj = self.getNamespace()[text]
                except KeyError:
                    return ''

            else:
                try:
                    splitted = text.split('.')
                    obj = self.getNamespace()[splitted[0]]
                    for t in splitted[1:]:
                        obj = getattr(obj, t)
                except:
                    return ''

            if obj is not None:
                try:
                    if sys.platform.startswith("java"):
                        #Jython
                        doc = obj.__doc__
                        if doc is not None:
                            return doc

                        import jyimportsTipper

                        is_method, infos = jyimportsTipper.ismethod(obj)
                        ret = ''
                        if is_method:
                            for info in infos:
                                ret += info.getAsDoc()
                            return ret

                    else:
                        #Python and Iron Python
                        import inspect #@UnresolvedImport

                        doc = inspect.getdoc(obj)
                        if doc is not None:
                            return doc
                except:
                    pass

            try:
                #if no attempt succeeded, try to return repr()... 
                return repr(obj)
            except:
                try:
                    #otherwise the class 
                    return str(obj.__class__)
                except:
                    #if all fails, go to an empty string 
                    return ''
        except:
            traceback.print_exc()
            return ''
示例#2
0
 def testGettingInfoOnJython(self):
     
     dbg('\n\n--------------------------- java')
     assert not ismethod(java)[0]
     assert not isclass(java)
     assert jyimportsTipper.ismodule(java)
         
     dbg('\n\n--------------------------- java.lang')
     assert not ismethod(java.lang)[0]
     assert not isclass(java.lang)
     assert jyimportsTipper.ismodule(java.lang)
         
     dbg('\n\n--------------------------- Method')
     assert not ismethod(Method)[0]
     assert isclass(Method)
         
     dbg('\n\n--------------------------- System')
     assert not ismethod(System)[0]
     assert isclass(System)
         
     dbg('\n\n--------------------------- String')
     assert not ismethod(System)[0]
     assert isclass(String)
     assert len(dirObj(String)) > 10
         
     dbg('\n\n--------------------------- arraycopy')
     isMet = ismethod(arraycopy)
     assert isMet[0]
     assert isMet[1][0].basicAsStr() == "function:arraycopy args=['java.lang.Object', 'int', 'java.lang.Object', 'int', 'int'], varargs=None, kwargs=None, docs:None"
     assert not isclass(arraycopy)
         
     dbg('\n\n--------------------------- out')
     isMet = ismethod(out)
     assert not isMet[0]
     assert not isclass(out)
         
     dbg('\n\n--------------------------- out.println')
     isMet = ismethod(out.println) #@UndefinedVariable
     assert isMet[0]
     assert len(isMet[1]) == 10
     self.assertEquals(isMet[1][0].basicAsStr(), "function:println args=[], varargs=None, kwargs=None, docs:None")
     assert isMet[1][1].basicAsStr() == "function:println args=['long'], varargs=None, kwargs=None, docs:None"
     assert not isclass(out.println) #@UndefinedVariable
     
     dbg('\n\n--------------------------- str')
     isMet = ismethod(str)
     #the code below should work, but is failing on jython 22a1
     #assert isMet[0]
     #assert isMet[1][0].basicAsStr() == "function:str args=['org.python.core.PyObject'], varargs=None, kwargs=None, docs:None"
     assert not isclass(str)
     
     
     def met1():
         a = 3
         return a
     
     dbg('\n\n--------------------------- met1')
     isMet = ismethod(met1)
     assert isMet[0]
     assert isMet[1][0].basicAsStr() == "function:met1 args=[], varargs=None, kwargs=None, docs:None"
     assert not isclass(met1)
     
     def met2(arg1, arg2, *vararg, **kwarg):
         '''docmet2'''
         
         a = 1
         return a
     
     dbg('\n\n--------------------------- met2')
     isMet = ismethod(met2)
     assert isMet[0]
     assert isMet[1][0].basicAsStr() == "function:met2 args=['arg1', 'arg2'], varargs=vararg, kwargs=kwarg, docs:docmet2"
     assert not isclass(met2)