Example #1
0
        def testDotNetLibraries(self):
            if sys.platform == 'cli':
                tip = importsTipper.GenerateTip('System.Drawing')
                self.assertIn('Brushes', tip)

                tip = importsTipper.GenerateTip('System.Drawing.Brushes')
                self.assertIn('Aqua', tip)
Example #2
0
 def testImports4(self):
     try:
         tip = importsTipper.GenerateTip(
             'mx.DateTime.mxDateTime.mxDateTime')
         self.assertIn('now', tip)
     except ImportError:
         pass
Example #3
0
 def testImports2(self):
     try:
         tip = importsTipper.GenerateTip('OpenGL.GLUT')
         self.assertIn('glutDisplayFunc', tip)
         self.assertIn('glutInitDisplayMode', tip)
     except ImportError:
         pass
def GetImports(module_name):
    try:
        processor = pycompletionserver.Processor()
        data = urllib.unquote_plus(module_name)
        def_file, completions = importsTipper.GenerateTip(data)
        return processor.formatCompletionMessage(def_file, completions)
    except:
        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()
        pycompletionserver.dbg('Received error: ' + str(err),
                               pycompletionserver.ERROR)
        raise
Example #5
0
    def run( self ):
        # Echo server program
        try:
            import socket
            
            dbg( SERVER_NAME+' 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( SERVER_NAME+' waiting for connection' , INFO1 )
            conn, addr = s.accept()
            time.sleep( 0.5 ) #wait a little before connecting to JAVA server
    
            dbg( SERVER_NAME+' waiting to java client' , INFO1 )
            #after being connected, create a socket as a client.
            self.connectToServer()
            
            dbg( SERVER_NAME+' Connected by ' + str( addr ), INFO1 )
            
            
            while 1:
                data = ''
                returnMsg = ''
                keepAliveThread = KeepAliveThread( self.socket )
                
                while data.find( MSG_END ) == -1:
                    received = conn.recv( BUFFER_SIZE )
                    if len(received) == 0:
                        sys.exit(0) #ok, connection ended
                    if IS_PYTHON3K:
                        data = data+received.decode('utf-8')
                    else:
                        data = data+received
    
                try:
                    try:
                        if data.find( MSG_KILL_SERVER ) != -1:
                            dbg( SERVER_NAME+' kill message received', INFO1 )
                            #break if we received kill message.
                            self.ended = True
                            sys.exit(0)
            
                        dbg( SERVER_NAME+' 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( None, comps )
    
                        elif data.find( MSG_RELOAD_MODULES ) != -1:
                            ReloadModules()
                            returnMsg = MSG_OK
                        
                        else:
                            data = data[:data.rfind( MSG_END )]
                        
                            if data.startswith( MSG_IMPORTS ):
                                data = data.replace( MSG_IMPORTS, '' )
                                data = unquote_plus( data )
                                defFile, comps = importsTipper.GenerateTip( data )
                                returnMsg = self.getCompletionsMessage( defFile, comps )
        
                            elif data.startswith( MSG_CHANGE_PYTHONPATH ):
                                data = data.replace( MSG_CHANGE_PYTHONPATH, '' )
                                data = unquote_plus( data )
                                ChangePythonPath( data )
                                returnMsg = MSG_OK
        
                            elif data.startswith( MSG_SEARCH ):
                                data = data.replace( MSG_SEARCH, '' )
                                data = 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, '' )
                                data = unquote_plus( data )
                                CompleteFromDir( data )
                                returnMsg = MSG_OK
                                
                            elif data.startswith( MSG_BIKE ): 
                                if IS_JYTHON:
                                    returnMsg = MSG_JYTHON_INVALID_REQUEST
                                else:
                                    data = data.replace( MSG_BIKE, '' )
                                    data = unquote_plus( data )
                                    returnMsg = refactoring.HandleRefactorMessage( data, keepAliveThread )
                                
                            else:
                                returnMsg = MSG_INVALID_REQUEST
                    except SystemExit:
                        returnMsg = self.getCompletionsMessage( None, [( 'Exit:', 'SystemExit', '' )] )
                        keepAliveThread.lastMsg = returnMsg
                        raise
                    except:
                        dbg( SERVER_NAME+' exception ocurred', ERROR )
                        s = StringIO.StringIO()
                        traceback.print_exc(file = s)
    
                        err = s.getvalue()
                        dbg( SERVER_NAME+' received error: '+str(err), ERROR )
                        returnMsg = self.getCompletionsMessage( None, [( 'ERROR:', '%s'%( err ), '' )] )
                            
                    
                finally:
                    keepAliveThread.lastMsg = returnMsg
                
            conn.close()
            self.ended = True
            sys.exit(0) #connection broken
            
            
        except SystemExit:
            raise
            #No need to log SystemExit error
        except:
            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( SERVER_NAME+' received error: '+str( err ), ERROR )
            raise
Example #6
0
        def testImports(self):
            '''
            You can print_ the results to check...
            '''
            if HAS_WX:
                tip = importsTipper.GenerateTip('wxPython.wx')
                self.assertIn('wxApp', tip)

                tip = importsTipper.GenerateTip('wxPython.wx.wxApp')

                try:
                    tip = importsTipper.GenerateTip('qt')
                    self.assertIn('QWidget', tip)
                    self.assertIn('QDialog', tip)

                    tip = importsTipper.GenerateTip('qt.QWidget')
                    self.assertIn('rect', tip)
                    self.assertIn('rect', tip)
                    self.assertIn('AltButton', tip)

                    tip = importsTipper.GenerateTip('qt.QWidget.AltButton')
                    self.assertIn('__xor__', tip)

                    tip = importsTipper.GenerateTip(
                        'qt.QWidget.AltButton.__xor__')
                    self.assertIn('__class__', tip)
                except ImportError:
                    pass

            tip = importsTipper.GenerateTip(BUILTIN_MOD)
            #        for t in tip[1]:
            #            print_ t
            self.assertIn('object', tip)
            self.assertIn('tuple', tip)
            self.assertIn('list', tip)
            self.assertIn('RuntimeError', tip)
            self.assertIn('RuntimeWarning', tip)

            t = self.assertIn('cmp', tip)

            self.CheckArgs(t, '(x, y)', '(object x, object y)')  #args

            t = self.assertIn('isinstance', tip)
            self.CheckArgs(t, '(object, class_or_type_or_tuple)',
                           '(object o, type typeinfo)')  #args

            t = self.assertIn('compile', tip)
            self.CheckArgs(t, '(source, filename, mode)', '()')  #args

            t = self.assertIn('setattr', tip)
            self.CheckArgs(t, '(object, name, value)',
                           '(object o, str name, object val)')  #args

            try:
                import compiler
                compiler_module = 'compiler'
            except ImportError:
                try:
                    import ast
                    compiler_module = 'ast'
                except ImportError:
                    compiler_module = None

            if compiler_module is not None:  #Not available in iron python
                tip = importsTipper.GenerateTip(compiler_module)
                if compiler_module == 'compiler':
                    self.assertArgs('parse', '(buf, mode)', tip)
                    self.assertArgs('walk', '(tree, visitor, walker, verbose)',
                                    tip)
                    self.assertIn('parseFile', tip)
                else:
                    self.assertArgs('parse', '(expr, filename, mode)', tip)
                    self.assertArgs('walk', '(node)', tip)
                self.assertIn('parse', tip)
Example #7
0
 def testImports2c(self):
     tips = importsTipper.GenerateTip('%s.file' % BUILTIN_MOD)
     t = self.assertIn('readlines', tips)
     self.assert_('->' in t[1] or 'sizehint' in t[1])
Example #8
0
 def testImports2b(self):
     tips = importsTipper.GenerateTip('%s' % BUILTIN_MOD)
     t = self.assertIn('file', tips)
     self.assert_('->' in t[1].strip() or 'file' in t[1])
Example #9
0
 def testImports2a(self):
     tips = importsTipper.GenerateTip('%s.RuntimeError' % BUILTIN_MOD)
     self.assertIn('__doc__', tips)
Example #10
0
 def testImports5(self):
     tip = importsTipper.GenerateTip('__builtin__.list')
     s = self.assertIn('sort', tip)
     self.CheckArgs(s, '(cmp=None, key=None, reverse=False)',
                    '(self, object cmp, object key, bool reverse)')
Example #11
0
 def testImports3(self):
     tip = importsTipper.GenerateTip('os')
     ret = self.assertIn('path', tip)
     self.assertEquals('', ret[2])
Example #12
0
    def show_completion(self, text, it, editor, mw):
        complete = ""
        iter2 = self.get_iter_at_mark(self.get_insert())
        s, e = self.get_bounds()
        text_code = self.get_text(s, e)
        lst_ = []

        mod = False
        if text != '.':
            complete = self.get_context(iter2, True)
            if "\n" in complete or complete.isdigit() or complete.isspace():
                return
            else:
                complete = complete + text
            try:
                c = compile(text_code, '<string>', 'exec')
                lst_ = [a for a in c.co_names if a.startswith(complete)]
                con = map(str, c.co_consts)
                con = [
                    a for a in con if a.startswith(complete) and a not in lst_
                ]
                lst_ += con
                lst_ += keyword.kwlist
                lst_ = [a for a in lst_ if a.startswith(complete)]
                lst_.sort()
            except:
                lst_ += keyword.kwlist
                lst_ = [a for a in lst_ if a.startswith(complete)]
                lst_.sort()
        else:
            mod = True
            complete = self.get_context(iter2)
            if complete.isdigit():
                return
            if len(complete.strip()) > 0:
                try:
                    lst_ = [
                        str(a[0]) for a in importsTipper.GenerateTip(
                            complete, os.path.dirname(complete))
                        if a is not None
                    ]
                except:
                    try:
                        c = compile(text_code, '<string>', 'exec')
                        lst_ = [
                            a for a in c.co_names if a.startswith(complete)
                        ]
                        con = map(str, c.co_consts)
                        con = [
                            a for a in con
                            if a.startswith(complete) and a not in lst_
                        ]
                        lst_ += con
                        lst_ += keyword.kwlist
                        lst_ = [a for a in lst_ if a.startswith(complete)]
                        lst_.sort()
                        complete = ""
                    except:
                        lst_ += keyword.kwlist
                        lst_ = [a for a in lst_ if a.startswith(complete)]
                        lst_.sort()
                        complete = ""
        if len(lst_) == 0:
            return
        cw = AutoCompletionWindow(editor, iter2, complete, lst_, mw, mod,
                                  self.context_bounds)
Example #13
0
    def insert_at_cursor_cb(self, buff, iter, text, length):
        complete = ""
        buff, fn = self.get_current()
        iter2 = buff.get_iter_at_mark(buff.get_insert())
        s, e = buff.get_bounds()
        text_code = buff.get_text(s, e)
        lst_ = []
        if self.ac_w is not None:
            self.ac_w.hide()
        mod = False
        if text != '.':
            complete = self.get_context(buff, iter2, True)
            if "\n" in complete or complete.isdigit():
                return
            else:
                complete = complete + text
            try:
                c = compile(text_code, '<string>', 'exec')
                lst_ = [a for a in c.co_names if a.startswith(complete)]
                con = map(str, c.co_consts)
                con = [
                    a for a in con if a.startswith(complete) and a not in lst_
                ]
                lst_ += con
                lst_ += keyword.kwlist
                lst_ = [a for a in lst_ if a.startswith(complete)]
                lst_.sort()
            except:
                lst_ += keyword.kwlist
                lst_ = [a for a in lst_ if a.startswith(complete)]
                lst_.sort()
        else:
            mod = True
            complete = self.get_context(buff, iter2)
            if complete.isdigit():
                return
            if len(complete.strip()) > 0:
                try:
                    lst_ = [
                        str(a[0]) for a in importsTipper.GenerateTip(
                            complete, os.path.dirname(fn)) if a is not None
                    ]
                except:
                    try:
                        c = compile(text_code, '<string>', 'exec')
                        lst_ = [
                            a for a in c.co_names if a.startswith(complete)
                        ]
                        con = map(str, c.co_consts)
                        con = [
                            a for a in con
                            if a.startswith(complete) and a not in lst_
                        ]
                        lst_ += con
                        lst_ += keyword.kwlist
                        lst_ = [a for a in lst_ if a.startswith(complete)]
                        lst_.sort()
                        complete = ""
                    except:
                        lst_ += keyword.kwlist
                        lst_ = [a for a in lst_ if a.startswith(complete)]
                        lst_.sort()
                        complete = ""

        if len(lst_) == 0:
            return
        if self.ac_w is None:
            self.ac_w = AutoCompletionWindow(self.editor, iter2, complete,
                                             lst_, self.plugin.pida.mainwindow,
                                             mod, self.context_bounds)
        else:
            self.ac_w.set_list(self.editor, iter2, complete, lst_,
                               self.plugin.pida.mainwindow, mod,
                               self.context_bounds)
        return