Thread: [Pydev-cvs] org.python.pydev/PySrc test_pyserver.py,1.6,1.7 simpleTipper.py,1.4,1.5 importsTipper.py
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-17 17:36:06
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13035/PySrc Modified Files: test_pyserver.py simpleTipper.py importsTipper.py pycompletionserver.py refactoring.py test_simpleTipper.py Log Message: testing... Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pycompletionserver.py 16 Sep 2004 15:27:25 -0000 1.8 --- pycompletionserver.py 17 Sep 2004 17:35:55 -0000 1.9 *************** *** 7,10 **** --- 7,12 ---- import refactoring import sys + import urllib + import importsTipper HOST = '127.0.0.1' # Symbolic name meaning the local host *************** *** 23,26 **** --- 25,29 ---- MSG_PROCESSING = '@@PROCESSING_END@@' MSG_PROCESSING_PROGRESS = '@@PROCESSING:%sEND@@' + MSG_IMPORTS = '@@IMPORTS:' BUFFER_SIZE = 1024 *************** *** 64,68 **** def removeInvalidChars(self, msg): if msg: ! return msg.replace(',','').replace('(','').replace(')','') return ' ' --- 67,71 ---- def removeInvalidChars(self, msg): if msg: ! return urllib.quote_plus(msg) return ' ' *************** *** 130,174 **** try: ! if MSG_KILL_SERVER in data: ! #break if we received kill message. ! break; ! ! keepAliveThread.start() ! ! if MSG_RELOAD_MODULES in data: ! simpleTipper.ReloadModules() ! returnMsg = MSG_OK ! ! else: ! data = data[:data.rfind(MSG_END)] ! ! if data.startswith(MSG_GLOBALS): ! data = data.replace(MSG_GLOBALS, '') ! comps = simpleTipper.GenerateTip(data, None, False) ! returnMsg = self.getCompletionsMessage(comps) ! ! elif data.startswith(MSG_TOKEN_GLOBALS ): ! data = data.replace(MSG_TOKEN_GLOBALS, '') ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, False) ! returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_CLASS_GLOBALS ): ! data = data.replace(MSG_CLASS_GLOBALS, '') ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, True) ! returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_CHANGE_DIR ): ! data = data.replace(MSG_CHANGE_DIR, '') ! simpleTipper.CompleteFromDir(data) returnMsg = MSG_OK ! elif data.startswith(MSG_REFACTOR): ! data = data.replace(MSG_REFACTOR, '') ! returnMsg = refactoring.HandleRefactorMessage(data, keepAliveThread) ! else: ! returnMsg = MSG_INVALID_REQUEST finally: keepAliveThread.lastMsg = returnMsg --- 133,200 ---- try: ! try: ! if MSG_KILL_SERVER in data: ! #break if we received kill message. ! break; ! keepAliveThread.start() ! if MSG_RELOAD_MODULES in data: ! simpleTipper.ReloadModules() returnMsg = MSG_OK + + else: + data = data[:data.rfind(MSG_END)] + + if data.startswith(MSG_GLOBALS): + data = data.replace(MSG_GLOBALS, '') + data = urllib.unquote_plus(data) + comps = simpleTipper.GenerateTip(data, None, False) + returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_TOKEN_GLOBALS ): ! data = data.replace(MSG_TOKEN_GLOBALS, '') ! data = urllib.unquote_plus(data) ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, False) ! returnMsg = self.getCompletionsMessage(comps) ! ! elif data.startswith(MSG_CLASS_GLOBALS ): ! data = data.replace(MSG_CLASS_GLOBALS, '') ! data = urllib.unquote_plus(data) ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, True) ! returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_IMPORTS ): ! data = data.replace(MSG_IMPORTS, '') ! data = urllib.unquote_plus(data) ! comps = importsTipper.GenerateTip(data) ! returnMsg = self.getCompletionsMessage(comps) ! ! elif data.startswith(MSG_CHANGE_DIR ): ! data = data.replace(MSG_CHANGE_DIR, '') ! data = urllib.unquote_plus(data) ! simpleTipper.CompleteFromDir(data) ! returnMsg = MSG_OK ! ! elif data.startswith(MSG_REFACTOR): ! data = data.replace(MSG_REFACTOR, '') ! data = urllib.unquote_plus(data) ! returnMsg = refactoring.HandleRefactorMessage(data, keepAliveThread) ! ! else: ! returnMsg = MSG_INVALID_REQUEST ! except : ! import sys ! import traceback ! import StringIO ! ! s = StringIO.StringIO() ! exc_info = sys.exc_info() ! ! traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file = s) ! returnMsg = self.getCompletionsMessage([('ERROR:','%s'%(s.getvalue()))]) ! finally: keepAliveThread.lastMsg = returnMsg *************** *** 179,183 **** if __name__ == '__main__': #let's log this!! ! out = open('c:/temp/pydev.log', 'w') sys.stdout = out sys.stderr = out --- 205,216 ---- if __name__ == '__main__': #let's log this!! ! import os ! f = 'c:/temp/pydev.log' ! i=0 ! while os.path.exists(f): ! f = 'c:/temp/pydev%s.log' % i ! i+=1 ! ! out = open(f, 'w') sys.stdout = out sys.stderr = out Index: simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/simpleTipper.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** simpleTipper.py 14 Sep 2004 17:42:07 -0000 1.4 --- simpleTipper.py 17 Sep 2004 17:35:55 -0000 1.5 *************** *** 71,93 **** import simpleinspect __eraseThisMsg = '' ! try: ! __eraseThisMsg += 'Compiling \n%s\n'%theDoc ! __eraseThis = compiler.compile(theDoc, 'temporary_file_completion.py', 'exec') ! __eraseThisMsg += 'Compiled' ! ! simpleinspect.__eraseThisTips = [] ! simpleinspect.GenerateTip (__eraseThis, token) ! toReturn = simpleinspect.__eraseThisTips ! simpleinspect.__eraseThisTips = [] ! ! __eraseThisMsg += 'Getting self variables \n%s\n' % originalDoc ! if checkForSelf: ! toReturn += GetSelfVariables(originalDoc, token) ! ! return toReturn ! except : ! import sys ! s = str(sys.exc_info()[1]) ! return [('ERROR_COMPLETING','%s\nerror tracing:\n%s'%(s,__eraseThisMsg))] class Visitor(compiler.visitor.ASTVisitor): --- 71,89 ---- import simpleinspect __eraseThisMsg = '' ! ! __eraseThisMsg += 'Compiling \n%s\n'%theDoc ! __eraseThis = compiler.compile(theDoc, 'temporary_file_completion.py', 'exec') ! __eraseThisMsg += 'Compiled' ! ! simpleinspect.__eraseThisTips = [] ! simpleinspect.GenerateTip (__eraseThis, token) ! toReturn = simpleinspect.__eraseThisTips ! simpleinspect.__eraseThisTips = [] ! ! __eraseThisMsg += 'Getting self variables \n%s\n' % originalDoc ! if checkForSelf: ! toReturn += GetSelfVariables(originalDoc, token) ! ! return toReturn class Visitor(compiler.visitor.ASTVisitor): Index: test_pyserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_pyserver.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_pyserver.py 16 Sep 2004 15:27:25 -0000 1.6 --- test_pyserver.py 17 Sep 2004 17:35:55 -0000 1.7 *************** *** 7,10 **** --- 7,13 ---- import socket import os + import urllib + + class Test(unittest.TestCase): *************** *** 32,36 **** l.append(('De,f)2','de,s,c,ription2')) msg = t.formatCompletionMessage(l) ! self.assertEquals('@@COMPLETIONS((Def,description),(Def1,description1),(Def2,description2))END@@', msg) def createConnections(self, p1 = 50002,p2 = 50003): --- 35,39 ---- l.append(('De,f)2','de,s,c,ription2')) msg = t.formatCompletionMessage(l) ! self.assertEquals('@@COMPLETIONS((Def,desc%2C%2Cr%2C%2Ci%28%29ption),(Def%281,descriptio%28n1),(De%2Cf%292,de%2Cs%2Cc%2Cription2))END@@', msg) def createConnections(self, p1 = 50002,p2 = 50003): *************** *** 68,82 **** #now that we have the connections all set up, check the code completion messages. ! sToWrite.send('@@GLOBALS:import math\nEND@@') #only 1 global should be returned: math itself. completions = self.readMsg() ! self.assertEquals('@@COMPLETIONS((math,This module is always available. It provides access to the\n'\ ! 'mathematical functions defined by the C standard.))END@@', completions) #check token msg. ! sToWrite.send('@@TOKEN_GLOBALS(math):import math\nEND@@') completions = self.readMsg() self.assert_('@@COMPLETIONS' in completions) --- 71,91 ---- #now that we have the connections all set up, check the code completion messages. ! msg = urllib.quote('import math\n') ! sToWrite.send('@@GLOBALS:%sEND@@'%msg) #only 1 global should be returned: math itself. completions = self.readMsg() ! ! msg = urllib.quote('This module is always available. It provides access to the\n'\ ! 'mathematical functions defined by the C standard.') ! self.assertEquals('@@COMPLETIONS((math,%s))END@@'%msg, completions) + msg1 = urllib.quote('math') + msg2 = urllib.quote('import math\n') #check token msg. ! sToWrite.send('@@TOKEN_GLOBALS(%s):%sEND@@' % (msg1, msg2)) completions = self.readMsg() + self.assert_('@@COMPLETIONS' in completions) *************** *** 100,103 **** --- 109,113 ---- pass ''' + msg = urllib.quote(s) sToWrite.send('@@TOKEN_GLOBALS(C):%s\nEND@@'%s) *************** *** 127,135 **** self.assert_(newDir != None) sToWrite.send('@@CHANGE_DIR:%sEND@@'%newDir) ok = self.readMsg() self.assertEquals('@@MSG_OK_END@@' , ok) ! sToWrite.send('@@TOKEN_GLOBALS(math acos):import math\nEND@@') completions = self.readMsg() self.sendKillMsg(sToWrite) --- 137,157 ---- self.assert_(newDir != None) + newDir = urllib.quote(newDir) sToWrite.send('@@CHANGE_DIR:%sEND@@'%newDir) ok = self.readMsg() self.assertEquals('@@MSG_OK_END@@' , ok) ! ! msg1 = urllib.quote('math.acos') #with point ! msg2 = urllib.quote('import math\n') ! sToWrite.send('@@TOKEN_GLOBALS(%s):%sEND@@' %(msg1, msg2)) completions = self.readMsg() + self.assert_('@@COMPLETIONS' in completions) + self.assert_('END@@' in completions) + + msg1 = urllib.quote('math acos') #with space + msg2 = urllib.quote('import math\n') + sToWrite.send('@@TOKEN_GLOBALS(%s):%sEND@@' %(msg1, msg2)) + completions2 = self.readMsg() + self.assertEquals(completions, completions2) self.sendKillMsg(sToWrite) Index: refactoring.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/refactoring.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** refactoring.py 16 Sep 2004 15:27:25 -0000 1.3 --- refactoring.py 17 Sep 2004 17:35:55 -0000 1.4 *************** *** 5,9 **** import traceback import StringIO ! sys.path.insert(1, os.path.join(os.path.dirname(sys.argv[0]), --- 5,9 ---- import traceback import StringIO ! import urllib sys.path.insert(1, os.path.join(os.path.dirname(sys.argv[0]), *************** *** 30,34 **** msg = '' i -= 1 ! return msg def getLastProgressMsgs(self, v): --- 30,34 ---- msg = '' i -= 1 ! return urllib.quote(msg) def getLastProgressMsgs(self, v): *************** *** 42,46 **** pass i -= 1 ! return msg def init(self): --- 42,46 ---- pass i -= 1 ! return urllib.quote(msg) def init(self): *************** *** 112,118 **** try: ! f = func(*msgSplit)+'END@@' releaseRefactorerBuffers() ! return f except: import sys --- 112,119 ---- try: ! f = func(*msgSplit) releaseRefactorerBuffers() ! s = urllib.quote(f) ! return 'REFACTOR_OK:%s\nEND@@'%(s) except: import sys *************** *** 133,137 **** releaseRefactorerBuffers() restartRefactorer() ! return 'ERROR:%s\nEND@@'%(s.getvalue().replace('END@@','')) --- 134,139 ---- releaseRefactorerBuffers() restartRefactorer() ! s = urllib.quote(s.getvalue()) ! return 'ERROR:%s\nEND@@'%(s) Index: test_simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_simpleTipper.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_simpleTipper.py 14 Sep 2004 17:42:07 -0000 1.3 --- test_simpleTipper.py 17 Sep 2004 17:35:55 -0000 1.4 *************** *** 93,97 **** checkedA = True self.assert_(checkedA) - # self.assert_(('a',' ') in comps) --- 93,96 ---- *************** *** 100,106 **** def testImports(self): ! raise RuntimeError('not implemented') ! importsTipper.GenerateImportsTip(0) ! --- 99,111 ---- def testImports(self): ! importsTipper.GenerateTip('qt.') ! importsTipper.GenerateTip('scbr.') ! importsTipper.GenerateImportsTip(['scbr']) ! importsTipper.GenerateImportsTip([ ] ) ! importsTipper.GenerateImportsTip(['os']) ! importsTipper.GenerateImportsTip(['os','path']) ! importsTipper.GenerateImportsTip(['unittest']) ! importsTipper.GenerateImportsTip(['scbr', 'app', 'actions', 'db']) ! importsTipper.GenerateImportsTip(['scbr', 'app', 'actions', 'db', 'EditCont']) Index: importsTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/importsTipper.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** importsTipper.py 14 Sep 2004 17:42:07 -0000 1.1 --- importsTipper.py 17 Sep 2004 17:35:55 -0000 1.2 *************** *** 1,3 **** ! def GenerateImportsTip(theDoc): ! pass --- 1,116 ---- + import copy + import os + import sys + import os.path + import inspect ! _accessibleModules = {} ! ! def isModuleWithinList(mod, lis, dbg = False): ! for l in lis: ! if l[0] == mod: ! if dbg: ! print 'returning', l ! return l ! return None ! ! def ParseDir(d): ! ret = [] ! if os.path.exists(d) and os.path.isdir(d): ! contents = os.listdir(d) ! ! for f in contents: ! absolute = os.path.join(d, f) ! ! if os.path.isfile(absolute): ! m = None ! ! #if it is a file, just check if it is a valid module. ! if f.endswith('.py'): ! m = stripExtension(f, ret, '.py') ! ! if f.endswith('.pyc'): ! m = stripExtension(f, ret, '.pyc') ! ! if m is not None and isModuleWithinList(m, ret) is None: ! ret.append((m,absolute)) ! ! elif os.path.isdir(absolute): ! contents2 = os.listdir(absolute) ! ! if '__init__.py' in contents2 or '__init__.pyc' in contents2: ! ret.append((f,absolute)) ! ! return ret ! ! def stripExtension(f, ret, ext): ! return f[0:-len(ext)] ! ! def GenerateTip(data): ! data = data.replace('\n','') ! if data.endswith('.'): ! data = data.rstrip('.') ! ! if data.strip() == '': ! return GenerateImportsTip([]) ! ! splitted = data.split('.') ! print splitted ! return GenerateImportsTip(splitted) ! ! ! def GenerateImportsTip(tokenList, pth = sys.path, completeModule = ''): ! pythonPath = pth ! ! #first, just get the root modules ! mods = [] ! for d in pythonPath: ! if _accessibleModules.get(d, None) == None: ! mods += ParseDir(d) ! ! print mods ! if len(tokenList) == 0: ! return mods ! ! else: ! token = tokenList[0] ! if len(completeModule) > 0: ! completeModule += '.' ! completeModule += token ! ! ! newTokenList = tokenList[1:] ! mod = isModuleWithinList(token , mods) ! ! if mod is not None: ! ! if os.path.isfile(mod[1]): ! mod = myImport(completeModule) ! return GenerateImportsTipForModule(newTokenList, mod) ! ! elif os.path.isdir(mod[1]): ! return GenerateImportsTip(newTokenList, [mod[1]], completeModule) ! ! raise RuntimeError('Unable to complete.') ! ! def myImport(name): ! mod = __import__(name) ! components = name.split('.') ! for comp in components[1:]: ! mod = getattr(mod, comp) ! return mod ! ! ! def GenerateImportsTipForModule(tokenList, mod): ! ret = [] ! ! while len(tokenList) > 0: ! mod = getattr(mod, tokenList.pop(0)) ! ! for d in dir(mod): ! ret.append([d,inspect.getdoc(getattr(mod, d))]) ! return ret ! ! ! ! \ No newline at end of file |