Thread: [Pydev-cvs] org.python.pydev/PySrc simpleinspect.py,1.1,1.2 test_pyserver.py,1.2,1.3 simpleTipper.py
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-13 19:48:04
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4324/PySrc Modified Files: simpleinspect.py test_pyserver.py simpleTipper.py pycompletionserver.py test_simpleTipper.py Log Message: self. getting instance variables too. Index: test_simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_simpleTipper.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_simpleTipper.py 10 Sep 2004 19:42:23 -0000 1.1 --- test_simpleTipper.py 13 Sep 2004 19:47:54 -0000 1.2 *************** *** 42,46 **** def testEnv1(self): ! comps = simpleTipper.GenerateTip(self.getDoc1(), None) import math, inspect --- 42,46 ---- def testEnv1(self): ! comps = simpleTipper.GenerateTip(self.getDoc1(), None, True) import math, inspect *************** *** 61,65 **** def testEnv1CToken(self): ! comps = simpleTipper.GenerateTip(self.getDoc1(), 'C') checkedA = False for tup in comps: --- 61,65 ---- def testEnv1CToken(self): ! comps = simpleTipper.GenerateTip(self.getDoc1(), 'C', True) checkedA = False for tup in comps: *************** *** 69,72 **** --- 69,98 ---- self.assert_(checkedA) + + + def getDoc2(self): + s = \ + ''' + class C(object): + def __init__(self): + self.a = 1 + self.b = 2 + ''' + return s + + def testEnv2(self): + ''' + Now, check completion for C - should return object methods, 'a' and 'b' + ''' + comps = simpleTipper.GenerateTip(self.getDoc2(), 'C', True) + # print comps + checkedA = False + for tup in comps: + if tup[0] == 'a': + checkedA = True + self.assert_(checkedA) + # self.assert_(('a',' ') in comps) + + if __name__ == '__main__': Index: simpleinspect.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/simpleinspect.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** simpleinspect.py 10 Sep 2004 19:42:23 -0000 1.1 --- simpleinspect.py 13 Sep 2004 19:47:54 -0000 1.2 *************** *** 1,7 **** ''' @author Fabio Zadrozny ''' ! def GenerateTip (__eraseThisV): exec(__eraseThisV) --- 1,9 ---- ''' + Do not pollute this namespace! + @author Fabio Zadrozny ''' ! def GenerateTip (__eraseThisV, __eraseThisToken): exec(__eraseThisV) Index: simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/simpleTipper.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** simpleTipper.py 13 Sep 2004 17:11:51 -0000 1.2 --- simpleTipper.py 13 Sep 2004 19:47:54 -0000 1.3 *************** *** 2,11 **** @author Fabio Zadrozny ''' ! def GenerateTip (theDoc, token): ''' Put in the doc the code so that we get the locals. ''' if token is None: --- 2,13 ---- @author Fabio Zadrozny ''' + import compiler ! def GenerateTip (theDoc, token, checkForSelf): ''' Put in the doc the code so that we get the locals. ''' + originalDoc = theDoc if token is None: *************** *** 40,57 **** import simpleinspect - import compiler try: ! __eraseThis = compiler.compile(theDoc, 'temporary', 'exec') ! simpleinspect.__eraseThisTips = [] ! simpleinspect.GenerateTip (__eraseThis) toReturn = simpleinspect.__eraseThisTips simpleinspect.__eraseThisTips = [] return toReturn except : import sys s = str(sys.exc_info()[1]) return [('ERROR_COMPLETING',s)] \ No newline at end of file --- 42,109 ---- import simpleinspect try: ! __eraseThis = compiler.compile(theDoc, 'temporary_file_completion.py', 'exec') ! simpleinspect.__eraseThisTips = [] ! simpleinspect.GenerateTip (__eraseThis, token) toReturn = simpleinspect.__eraseThisTips simpleinspect.__eraseThisTips = [] + + if checkForSelf: + toReturn += GetSelfVariables(originalDoc, token) + return toReturn except : import sys s = str(sys.exc_info()[1]) + print s return [('ERROR_COMPLETING',s)] + class Visitor(compiler.visitor.ASTVisitor): + + def __init__(self, classToVisit): + self.classToVisit = classToVisit + self.selfAttribs = [] + + def visitClass(self, node): + # print node.name + if node.name == self.classToVisit: + for n in node.getChildNodes(): + self.visit(n) + + def visitAssign(self, node): + + for n in node.getChildNodes(): + if isinstance(n,compiler.ast.AssAttr): + if n.expr.name == 'self': + self.selfAttribs.append((n.attrname,'Instance attribute')) + + + def GetSelfVariables(theDoc, classToVisit): + ast = compiler.parse(theDoc) + + visitor = Visitor(classToVisit) + compiler.walk(ast, visitor) + + return visitor.selfAttribs + + + + + + + + + + + + + + + + + + + \ No newline at end of file Index: test_pyserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_pyserver.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_pyserver.py 13 Sep 2004 17:11:50 -0000 1.2 --- test_pyserver.py 13 Sep 2004 19:47:54 -0000 1.3 *************** *** 76,80 **** def b(self): ! self.a pass --- 76,80 ---- def b(self): ! self.c=1 pass *************** *** 84,87 **** --- 84,91 ---- completions = connToRead.recv(4086) + sToWrite.send('@@CLASS_GLOBALS(C):%s\nEND@@'%s) + completions2 = connToRead.recv(4086) + self.assert_(len(completions) != len(completions2)) + self.sendKillMsg(sToWrite) Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pycompletionserver.py 13 Sep 2004 17:11:50 -0000 1.4 --- pycompletionserver.py 13 Sep 2004 19:47:54 -0000 1.5 *************** *** 14,17 **** --- 14,18 ---- MSG_GLOBALS = '@@GLOBALS:' MSG_TOKEN_GLOBALS = '@@TOKEN_GLOBALS(' + MSG_CLASS_GLOBALS = '@@CLASS_GLOBALS(' MSG_INVALID_REQUEST = '@@INVALID_REQUEST' *************** *** 108,112 **** if MSG_GLOBALS in data: data = data.replace(MSG_GLOBALS, '') ! comps = simpleTipper.GenerateTip(data, None) self.sendCompletionsMessage(comps) --- 109,113 ---- if MSG_GLOBALS in data: data = data.replace(MSG_GLOBALS, '') ! comps = simpleTipper.GenerateTip(data, None, False) self.sendCompletionsMessage(comps) *************** *** 114,118 **** data = data.replace(MSG_TOKEN_GLOBALS, '') token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token) self.sendCompletionsMessage(comps) --- 115,125 ---- data = data.replace(MSG_TOKEN_GLOBALS, '') token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, False) ! self.sendCompletionsMessage(comps) ! ! elif MSG_CLASS_GLOBALS in data: ! data = data.replace(MSG_CLASS_GLOBALS, '') ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, True) self.sendCompletionsMessage(comps) |