[Pydev-cvs] org.python.pydev/PySrc pycompletionserver.py,1.20,1.21 jycompletionserver.py,1.5,1.6
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-08-25 13:32:42
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10634/PySrc Modified Files: pycompletionserver.py jycompletionserver.py Log Message: Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** pycompletionserver.py 13 Aug 2005 21:04:39 -0000 1.20 --- pycompletionserver.py 25 Aug 2005 13:32:31 -0000 1.21 *************** *** 8,12 **** _sys_modules = {} ! for name,mod in sys.modules.items(): _sys_modules[name] = mod --- 8,12 ---- _sys_modules = {} ! for name, mod in sys.modules.items(): _sys_modules[name] = mod *************** *** 17,25 **** import importsTipper ! DEBUG = False ! def dbg(s): ! if DEBUG == True: print s --- 17,29 ---- import importsTipper + INFO1 = 1 + INFO2 = 2 + WARN = 4 + ERROR = 8 ! DEBUG = INFO1 | ERROR ! def dbg( s, prior ): ! if prior & DEBUG != 0: print s *************** *** 46,50 **** currDirModule = None ! def CompleteFromDir(dir): ''' This is necessary so that we get the imports from the same dir where the file --- 50,54 ---- currDirModule = None ! def CompleteFromDir( dir ): ''' This is necessary so that we get the imports from the same dir where the file *************** *** 55,59 **** del sys.path[currDirModule] ! sys.path.insert(0, dir) --- 59,63 ---- del sys.path[currDirModule] ! sys.path.insert( 0, dir ) *************** *** 63,70 **** ''' sys.modules.clear() ! for name,mod in _sys_modules.items(): sys.modules[name] = mod ! def ChangePythonPath(pythonpath): '''Changes the pythonpath (clears all the previous pythonpath) --- 67,74 ---- ''' sys.modules.clear() ! for name, mod in _sys_modules.items(): sys.modules[name] = mod ! def ChangePythonPath( pythonpath ): '''Changes the pythonpath (clears all the previous pythonpath) *************** *** 72,81 **** ''' ! split = pythonpath.split('|') sys.path = [] for path in split: path = path.strip() ! if len(path) > 0: ! sys.path.append(path) class KeepAliveThread( threading.Thread ): --- 76,85 ---- ''' ! split = pythonpath.split( '|' ) sys.path = [] for path in split: path = path.strip() ! if len( path ) > 0: ! sys.path.append( path ) class KeepAliveThread( threading.Thread ): *************** *** 91,95 **** if self.processMsgFunc != None: ! s = MSG_PROCESSING_PROGRESS % urllib.quote_plus( self.processMsgFunc( ) ) self.socket.send( s ) else: --- 95,99 ---- if self.processMsgFunc != None: ! s = MSG_PROCESSING_PROGRESS % urllib.quote_plus( self.processMsgFunc() ) self.socket.send( s ) else: *************** *** 97,101 **** time.sleep( 0.1 ) ! dbg( 'sending '+ self.lastMsg) self.socket.send( self.lastMsg ) --- 101,105 ---- time.sleep( 0.1 ) ! dbg( 'sending '+ self.lastMsg, INFO2 ) self.socket.send( self.lastMsg ) *************** *** 135,143 **** compMsg.append( self.removeInvalidChars( tup[1] ) ) #description ! if(len(tup) > 2): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[2] ) ) #args - only if function. ! if(len(tup) > 3): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[3] ) ) #TYPE --- 139,147 ---- compMsg.append( self.removeInvalidChars( tup[1] ) ) #description ! if( len( tup ) > 2 ): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[2] ) ) #args - only if function. ! if( len( tup ) > 3 ): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[3] ) ) #TYPE *************** *** 168,260 **** def run( self ): ! # Echo server program ! import socket ! ! s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) ! s.bind( ( HOST, self.thisPort ) ) ! s.listen( 1 ) #socket to receive messages. ! ! ! #we stay here until we are connected. ! #we only accept 1 client. ! #the exit message for the server is @@KILL_SERVER_END@@ ! conn, addr = s.accept( ) ! time.sleep( 0.5 ) #wait a little before connecting to JAVA server ! ! #after being connected, create a socket as a client. ! self.connectToServer( ) ! ! dbg('pycompletionserver Connected by ' + str(addr)) ! ! ! while 1: ! data = '' ! returnMsg = '' ! keepAliveThread = KeepAliveThread( self.socket ) ! while not data.endswith( MSG_END ): ! data += conn.recv( BUFFER_SIZE ) ! ! try: try: ! if MSG_KILL_SERVER in data: ! #break if we received kill message. ! break; ! ! keepAliveThread.start( ) ! ! if MSG_PYTHONPATH in data: ! comps = [] ! for p in _sys_path: ! comps.append( ( p, ' ' ) ) ! returnMsg = self.getCompletionsMessage( comps ) ! ! elif MSG_RELOAD_MODULES in data: ! ReloadModules( ) ! returnMsg = MSG_OK ! ! else: ! data = data[:data.rfind( MSG_END )] ! ! if 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_PYTHONPATH ): ! data = data.replace( MSG_CHANGE_PYTHONPATH, '' ) ! data = urllib.unquote_plus( data ) ! ChangePythonPath( data ) ! returnMsg = MSG_OK ! ! elif data.startswith( MSG_CHANGE_DIR ): ! data = data.replace( MSG_CHANGE_DIR, '' ) ! data = urllib.unquote_plus( data ) ! CompleteFromDir( data ) returnMsg = MSG_OK ! ! elif data.startswith( MSG_BIKE ): ! data = data.replace( MSG_BIKE, '' ) ! data = urllib.unquote_plus( data ) ! returnMsg = refactoring.HandleRefactorMessage( data, keepAliveThread ) ! else: ! returnMsg = MSG_INVALID_REQUEST ! except : ! 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 ! ! conn.close( ) ! self.ended = True if __name__ == '__main__': --- 172,283 ---- def run( self ): ! try: ! # Echo server program ! import socket ! dbg( 'pycompletionserver creating socket' , INFO1 ) ! s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) ! s.bind( ( HOST, self.thisPort ) ) ! s.listen( 1 ) #socket to receive messages. ! ! ! #we stay here until we are connected. ! #we only accept 1 client. ! #the exit message for the server is @@KILL_SERVER_END@@ ! dbg( 'pycompletionserver waiting for connection' , INFO1 ) ! conn, addr = s.accept() ! time.sleep( 0.5 ) #wait a little before connecting to JAVA server ! ! dbg( 'pycompletionserver waiting to java client' , INFO1 ) ! #after being connected, create a socket as a client. ! self.connectToServer() ! ! dbg( 'pycompletionserver Connected by ' + str( addr ), INFO1 ) ! ! ! while 1: ! data = '' ! returnMsg = '' ! keepAliveThread = KeepAliveThread( self.socket ) ! ! while not data.endswith( MSG_END ): ! data += conn.recv( BUFFER_SIZE ) ! try: ! try: ! if MSG_KILL_SERVER in data: ! dbg( 'pycompletionserver kill message received', INFO1 ) ! #break if we received kill message. ! break; ! ! keepAliveThread.start() ! ! if MSG_PYTHONPATH in data: ! comps = [] ! for p in _sys_path: ! comps.append( ( p, ' ' ) ) returnMsg = self.getCompletionsMessage( comps ) ! elif MSG_RELOAD_MODULES in data: ! ReloadModules() returnMsg = MSG_OK ! else: ! data = data[:data.rfind( MSG_END )] ! ! if 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_PYTHONPATH ): ! data = data.replace( MSG_CHANGE_PYTHONPATH, '' ) ! data = urllib.unquote_plus( data ) ! ChangePythonPath( data ) ! returnMsg = MSG_OK ! ! elif data.startswith( MSG_CHANGE_DIR ): ! data = data.replace( MSG_CHANGE_DIR, '' ) ! data = urllib.unquote_plus( data ) ! CompleteFromDir( data ) ! returnMsg = MSG_OK ! ! elif data.startswith( MSG_BIKE ): ! data = data.replace( MSG_BIKE, '' ) ! data = urllib.unquote_plus( data ) ! returnMsg = refactoring.HandleRefactorMessage( data, keepAliveThread ) ! ! else: ! returnMsg = MSG_INVALID_REQUEST ! except : ! dbg( 'pycompletionserver exception ocurred', ERROR ) ! 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 ) ! ! err = s.getvalue() ! dbg( 'pycompletionserver received error: '+err, ERROR ) ! returnMsg = self.getCompletionsMessage( [( 'ERROR:', '%s'%( err ), '' )] ) ! ! finally: ! keepAliveThread.lastMsg = returnMsg ! ! conn.close() ! self.ended = True ! except: ! 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 ) ! err = s.getvalue() ! dbg( 'jycompletionserver received error: '+str( err ), ERROR ) ! raise if __name__ == '__main__': *************** *** 264,268 **** t = T( thisPort, serverPort ) ! dbg( 'will start' ) ! t.start( ) --- 287,291 ---- t = T( thisPort, serverPort ) ! dbg( 'pycompletionserver will start', INFO1 ) ! t.start() Index: jycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/jycompletionserver.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** jycompletionserver.py 19 Aug 2005 16:48:07 -0000 1.5 --- jycompletionserver.py 25 Aug 2005 13:32:31 -0000 1.6 *************** *** 1,2 **** --- 1,3 ---- + #@PydevCodeAnalysisIgnore ''' @author Fabio Zadrozny *************** *** 13,17 **** _sys_modules = {} ! for name,mod in sys.modules.items(): _sys_modules[name] = mod --- 14,18 ---- _sys_modules = {} ! for name, mod in sys.modules.items(): _sys_modules[name] = mod *************** *** 24,30 **** DEBUG = False ! def dbg(s): ! if DEBUG == True: ! print 'JY_SERVER', s HOST = '127.0.0.1' # Symbolic name meaning the local host --- 25,39 ---- DEBUG = False ! INFO1 = 1 ! INFO2 = 2 ! WARN = 4 ! ERROR = 8 ! ! DEBUG = INFO1 | ERROR ! ! def dbg( s, prior ): ! if prior & DEBUG != 0: ! print s ! HOST = '127.0.0.1' # Symbolic name meaning the local host *************** *** 48,52 **** currDirModule = None ! def CompleteFromDir(dir): ''' This is necessary so that we get the imports from the same dir where the file --- 57,61 ---- currDirModule = None ! def CompleteFromDir( dir ): ''' This is necessary so that we get the imports from the same dir where the file *************** *** 57,61 **** del sys.path[currDirModule] ! sys.path.insert(0, dir) --- 66,70 ---- del sys.path[currDirModule] ! sys.path.insert( 0, dir ) *************** *** 65,72 **** ''' sys.modules.clear() ! for name,mod in _sys_modules.items(): sys.modules[name] = mod ! def ChangePythonPath(pythonpath): '''Changes the pythonpath (clears all the previous pythonpath) --- 74,81 ---- ''' sys.modules.clear() ! for name, mod in _sys_modules.items(): sys.modules[name] = mod ! def ChangePythonPath( pythonpath ): '''Changes the pythonpath (clears all the previous pythonpath) *************** *** 74,83 **** ''' ! split = pythonpath.split('|') sys.path = [] for path in split: path = path.strip() ! if len(path) > 0: ! sys.path.append(path) class KeepAliveThread( Thread ): --- 83,92 ---- ''' ! split = pythonpath.split( '|' ) sys.path = [] for path in split: path = path.strip() ! if len( path ) > 0: ! sys.path.append( path ) class KeepAliveThread( Thread ): *************** *** 93,97 **** if self.processMsgFunc != None: ! s = MSG_PROCESSING_PROGRESS % urllib.quote_plus( self.processMsgFunc( ) ) self.socket.send( s ) else: --- 102,106 ---- if self.processMsgFunc != None: ! s = MSG_PROCESSING_PROGRESS % urllib.quote_plus( self.processMsgFunc() ) self.socket.send( s ) else: *************** *** 99,103 **** time.sleep( 0.1 ) - dbg( 'sending '+ self.lastMsg) self.socket.send( self.lastMsg ) --- 108,111 ---- *************** *** 137,145 **** compMsg.append( self.removeInvalidChars( tup[1] ) ) #description ! if(len(tup) > 2): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[2] ) ) #args - only if function. ! if(len(tup) > 3): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[3] ) ) #TYPE --- 145,153 ---- compMsg.append( self.removeInvalidChars( tup[1] ) ) #description ! if( len( tup ) > 2 ): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[2] ) ) #args - only if function. ! if( len( tup ) > 3 ): compMsg.append( ',' ) compMsg.append( self.removeInvalidChars( tup[3] ) ) #TYPE *************** *** 171,261 **** def run( self ): # Echo server program ! import socket ! ! s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) ! s.bind( ( HOST, self.thisPort ) ) ! s.listen( 1 ) #socket to receive messages. ! ! ! #we stay here until we are connected. ! #we only accept 1 client. ! #the exit message for the server is @@KILL_SERVER_END@@ ! conn, addr = s.accept( ) ! time.sleep( 0.5 ) #wait a little before connecting to JAVA server ! ! #after being connected, create a socket as a client. ! self.connectToServer( ) ! ! dbg('jycompletionserver Connected by ' + str(addr)) ! ! ! while 1: ! data = '' ! returnMsg = '' ! keepAliveThread = KeepAliveThread( self.socket ) ! while not data.endswith( MSG_END ): ! data += conn.recv( BUFFER_SIZE ) ! dbg('received data '+str(data)) ! ! dbg('ok, out of the while... treating received msg') ! try: try: ! dbg('making test') ! if data.find(MSG_KILL_SERVER) != -1: ! #break if we received kill message. ! break; ! ! dbg('starting keep alive thread') ! keepAliveThread.start( ) ! ! if data.find(MSG_PYTHONPATH) != -1: ! comps = [] ! for p in _sys_path: ! comps.append( ( p, ' ' ) ) ! returnMsg = self.getCompletionsMessage( comps ) ! ! else: ! data = data[:data.rfind( MSG_END )] ! ! if data.startswith( MSG_IMPORTS ): ! dbg('ok, generating tips for import msg: '+str(data)) ! data = data.replace( MSG_IMPORTS, '' ) ! data = urllib.unquote_plus( data ) ! comps = jyimportsTipper.GenerateTip( data ) returnMsg = self.getCompletionsMessage( comps ) - elif data.startswith( MSG_CHANGE_PYTHONPATH ): - data = data.replace( MSG_CHANGE_PYTHONPATH, '' ) - data = urllib.unquote_plus( data ) - ChangePythonPath( data ) - returnMsg = MSG_OK - - elif data.startswith( MSG_CHANGE_DIR ): - data = data.replace( MSG_CHANGE_DIR, '' ) - data = urllib.unquote_plus( data ) - CompleteFromDir( data ) - returnMsg = MSG_OK - else: ! returnMsg = MSG_INVALID_REQUEST ! except : ! dbg('exception ocurred') ! 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( ) ), '' )] ) ! dbg('exception ocurred and returned (%s)' % s.getvalue()) ! finally: ! keepAliveThread.lastMsg = returnMsg ! conn.close( ) ! self.ended = True if __name__ == '__main__': --- 179,284 ---- def run( self ): # Echo server program ! try: ! import socket ! dbg( 'jycompletionserver creating socket' , INFO1 ) ! s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) ! s.bind( ( HOST, self.thisPort ) ) ! s.listen( 1 ) #socket to receive messages. ! ! #we stay here until we are connected. ! #we only accept 1 client. ! #the exit message for the server is @@KILL_SERVER_END@@ ! dbg( 'jycompletionserver waiting for connection' , INFO1 ) ! conn, addr = s.accept() ! time.sleep( 0.5 ) #wait a little before connecting to JAVA server ! ! dbg( 'jycompletionserver waiting to java client' , INFO1 ) ! #after being connected, create a socket as a client. ! self.connectToServer() ! ! dbg( 'jycompletionserver Connected by ' + str( addr ), INFO1 ) ! ! ! while 1: ! data = '' ! returnMsg = '' ! keepAliveThread = KeepAliveThread( self.socket ) ! ! while not data.endswith( MSG_END ): ! data += conn.recv( BUFFER_SIZE ) ! ! dbg( 'jycompletionserver ok, out of the while... treating received msg', INFO1 ) ! try: ! try: ! if data.find( MSG_KILL_SERVER ) != -1: ! dbg( 'jycompletionserver kill message received', INFO1 ) ! #break if we received kill message. ! break; ! ! dbg( 'jycompletionserver starting keep alive thread', INFO2 ) ! keepAliveThread.start() ! ! if data.find( MSG_PYTHONPATH ) != -1: ! comps = [] ! for p in _sys_path: ! comps.append( ( p, ' ' ) ) returnMsg = self.getCompletionsMessage( comps ) else: ! data = data[:data.rfind( MSG_END )] ! ! if data.startswith( MSG_IMPORTS ): ! data = data.replace( MSG_IMPORTS, '' ) ! data = urllib.unquote_plus( data ) ! comps = jyimportsTipper.GenerateTip( data ) ! returnMsg = self.getCompletionsMessage( comps ) ! ! elif data.startswith( MSG_CHANGE_PYTHONPATH ): ! data = data.replace( MSG_CHANGE_PYTHONPATH, '' ) ! data = urllib.unquote_plus( data ) ! ChangePythonPath( data ) ! returnMsg = MSG_OK ! ! elif data.startswith( MSG_CHANGE_DIR ): ! data = data.replace( MSG_CHANGE_DIR, '' ) ! data = urllib.unquote_plus( data ) ! CompleteFromDir( data ) ! returnMsg = MSG_OK ! ! else: ! returnMsg = MSG_INVALID_REQUEST ! except : ! dbg( 'jycompletionserver exception ocurred', ERROR ) ! 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 ) ! err = s.getvalue() ! dbg( 'jycompletionserver received error: '+str( err ), ERROR ) ! returnMsg = self.getCompletionsMessage( [( 'ERROR:', '%s'%( err ), '' )] ) ! ! finally: ! keepAliveThread.lastMsg = returnMsg ! conn.close() ! self.ended = True ! except: ! 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 ) ! err = s.getvalue() ! dbg( 'jycompletionserver received error: '+str( err ), ERROR ) ! raise if __name__ == '__main__': *************** *** 265,269 **** t = T( thisPort, serverPort ) ! dbg( 'will start' ) ! t.start( ) --- 288,292 ---- t = T( thisPort, serverPort ) ! dbg( 'jycompletionserver will start', INFO1 ) ! t.start() |