[Pydev-cvs] org.python.pydev/PySrc importsTipper.py,1.14,1.15 pycompletionserver.py,1.25,1.26
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2006-01-08 19:33:09
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24770/PySrc Modified Files: importsTipper.py pycompletionserver.py Log Message: Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** pycompletionserver.py 8 Jan 2006 12:04:55 -0000 1.25 --- pycompletionserver.py 8 Jan 2006 19:32:58 -0000 1.26 *************** *** 62,65 **** --- 62,66 ---- MSG_PYTHONPATH = '@@PYTHONPATH_END@@' MSG_CHANGE_PYTHONPATH = '@@CHANGE_PYTHONPATH:' + MSG_SEARCH = '@@SEARCH' BUFFER_SIZE = 1024 *************** *** 142,147 **** def removeInvalidChars( self, msg ): if msg: ! return urllib.quote_plus( msg ) return ' ' --- 143,153 ---- def removeInvalidChars( self, msg ): + msg = str(msg) if msg: ! try: ! return urllib.quote_plus( msg ) ! except: ! print 'error making quote plus in', msg ! raise return ' ' *************** *** 149,153 **** ''' Format the completions suggestions in the following format: ! @@COMPLETIONS((token,description),(token,description),(token,description))END@@ ''' compMsg = [] --- 155,159 ---- ''' Format the completions suggestions in the following format: ! @@COMPLETIONS(modFile(token,description),(token,description),(token,description))END@@ ''' compMsg = [] *************** *** 234,237 **** --- 240,244 ---- dbg( SERVER_NAME+' kill message received', INFO1 ) #break if we received kill message. + self.ended = True sys.exit(0) *************** *** 264,267 **** --- 271,280 ---- returnMsg = MSG_OK + elif data.startswith( MSG_SEARCH ): + data = data.replace( MSG_SEARCH, '' ) + data = urllib.unquote_plus( data ) + (f, line, col), foundAs = importsTipper.Search(data) + returnMsg = self.getCompletionsMessage(f, [(line, col, foundAs)]) + elif data.startswith( MSG_CHANGE_DIR ): data = data.replace( MSG_CHANGE_DIR, '' ) Index: importsTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/importsTipper.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** importsTipper.py 5 Jan 2006 00:53:10 -0000 1.14 --- importsTipper.py 8 Jan 2006 19:32:58 -0000 1.15 *************** *** 1,2 **** --- 1,5 ---- + import os.path + import re + import linecache import inspect import sys *************** *** 25,33 **** raise RuntimeError(s) def Find( name ): f = None mod = _imp(name) ! if inspect.ismodule(mod) and hasattr(mod, '__file__'): ! f = mod.__file__ components = name.split('.') --- 28,55 ---- raise RuntimeError(s) + def GetFile(mod): + f = None + try: + f = inspect.getsourcefile(mod) or inspect.getfile(mod) + except: + if hasattr(mod,'__file__'): + f = mod.__file__ + if string.lower(f[-4:]) in ['.pyc', '.pyo']: + filename = f[:-4] + '.py' + if os.path.exists(filename): + f = filename + + return f + def Find( name ): f = None + parent = None + mod = _imp(name) ! parent = mod ! foundAs = '' ! ! if inspect.ismodule(mod): ! f = GetFile(mod) components = name.split('.') *************** *** 35,43 **** for comp in components[1:]: mod = getattr(mod, comp) ! if inspect.ismodule(mod) and hasattr(mod, '__file__'): ! f = mod.__file__ ! return f, mod def GenerateTip( data ): data = data.replace( '\n', '' ) --- 57,125 ---- for comp in components[1:]: mod = getattr(mod, comp) ! if inspect.ismodule(mod): ! f = GetFile(mod) ! else: ! if len(foundAs) > 0: ! foundAs += '.' ! foundAs += comp ! ! return f, mod, parent, foundAs ! ! def Search( data ): ! '''@return file, line, col ! ''' ! ! data = data.replace( '\n', '' ) ! if data.endswith( '.' ): ! data = data.rstrip( '.' ) ! f, mod, parent, foundAs = Find( data ) ! try: ! return DoFind(f, mod), foundAs ! except: ! return DoFind(f, parent), foundAs ! ! ! def DoFind(f, mod): ! if inspect.ismodule(mod): ! return f, 0, 0 ! ! lines = linecache.getlines(f) ! if inspect.isclass(mod): ! name = mod.__name__ ! pat = re.compile(r'^\s*class\s*' + name + r'\b') ! for i in range(len(lines)): ! if pat.match(lines[i]): ! return f, i, 0 ! ! return f, 0, 0 + if inspect.ismethod(mod): + mod = mod.im_func + if inspect.isfunction(mod): + mod = mod.func_code + if inspect.istraceback(mod): + mod = mod.tb_frame + if inspect.isframe(mod): + mod = mod.f_code + if inspect.iscode(mod): + if not hasattr(mod, 'co_filename'): + return None, 0, 0 + if not hasattr(mod, 'co_firstlineno'): + return mod.co_filename, 0, 0 + + lnum = mod.co_firstlineno - 1 + pat = re.compile(r'^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)') + while lnum > 0: + if pat.match(lines[lnum]): break + lnum = lnum - 1 + return f, lnum, 0 + + raise RuntimeError('Do not know about: '+data+' '+str(mod)) + + + + + def GenerateTip( data ): data = data.replace( '\n', '' ) *************** *** 45,49 **** data = data.rstrip( '.' ) ! f, mod = Find( data ) #print >> open('temp.txt', 'w'), f tips = GenerateImportsTipForModule( mod ) --- 127,131 ---- data = data.rstrip( '.' ) ! f, mod, parent, foundAs = Find( data ) #print >> open('temp.txt', 'w'), f tips = GenerateImportsTipForModule( mod ) |