Exemple #1
0
    def __init__(self, tests_queue):
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.queue = tests_queue
        self.finished = False
        from pydev_imports import SimpleXMLRPCServer
        
        
        # This is a hack to patch slow socket.getfqdn calls that
        # BaseHTTPServer (and its subclasses) make.
        # See: http://bugs.python.org/issue6085
        # See: http://www.answermysearches.com/xmlrpc-server-slow-in-python-how-to-fix/2140/
        try:
            import BaseHTTPServer
            def _bare_address_string(self):
                host, port = self.client_address[:2]
                return '%s' % host
            BaseHTTPServer.BaseHTTPRequestHandler.address_string = _bare_address_string
            
        except:
            pass
        # End hack.


        # Create server
        
        import pydev_localhost
        server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), 0), logRequests=False)
        server.register_function(self.GetTestsToRun)
        server.register_function(self.notifyStartTest)
        server.register_function(self.notifyTest)
        server.register_function(self.notifyCommands)
        self.port = server.socket.getsockname()[1]
        self.server = server
    def __init__(self, tests_queue):
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.queue = tests_queue
        self.finished = False
        from pydev_imports import SimpleXMLRPCServer
        
        
        # This is a hack to patch slow socket.getfqdn calls that
        # BaseHTTPServer (and its subclasses) make.
        # See: http://bugs.python.org/issue6085
        # See: http://www.answermysearches.com/xmlrpc-server-slow-in-python-how-to-fix/2140/
        try:
            import BaseHTTPServer
            def _bare_address_string(self):
                host, port = self.client_address[:2]
                return '%s' % host
            BaseHTTPServer.BaseHTTPRequestHandler.address_string = _bare_address_string
            
        except:
            pass
        # End hack.


        # Create server
        
        import pydev_localhost
        server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), 0), logRequests=False)
        server.register_function(self.GetTestsToRun)
        server.register_function(self.notifyStartTest)
        server.register_function(self.notifyTest)
        server.register_function(self.notifyCommands)
        self.port = server.socket.getsockname()[1]
        self.server = server
 def run(self):
     class HandleRequestInput:
         def RequestInput(self):
             return 'input_request'
     
     handle_request_input = HandleRequestInput()
     
     import pydev_localhost
     client_server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), self.client_port), logRequests=False)
     client_server.register_function(handle_request_input.RequestInput)
     client_server.serve_forever()
Exemple #4
0
 def register_function(self, fn, name):
     def proxy_fn(*args, **kwargs):
         def main_loop_cb():
             try:
                 try:
                     sys.exc_clear()
                 except:
                     pass #Not there in Jython 2.1
                 self.resp_queue.put(fn(*args, **kwargs))
             except:
                 import traceback;traceback.print_exc()
                 self.resp_queue.put(None)
         self.main_loop.call_in_main_thread(main_loop_cb)
         return self.resp_queue.get(block=True)
     
     SimpleXMLRPCServer.register_function(self, proxy_fn, name)
Exemple #5
0
    def register_function(self, fn, name):
        def proxy_fn(*args, **kwargs):
            def main_loop_cb():
                try:
                    try:
                        sys.exc_clear()
                    except:
                        pass  # Not there in Jython 2.1
                    self.resp_queue.put(fn(*args, **kwargs))
                except:
                    import traceback
                    traceback.print_exc()
                    self.resp_queue.put(None)

            self.main_loop.call_in_main_thread(main_loop_cb)
            return self.resp_queue.get(block=True)

        SimpleXMLRPCServer.register_function(self, proxy_fn, name)
Exemple #6
0
 def run(self):
     class HandleRequestInput:
         def RequestInput(self):
             return 'input_request'
     
     handle_request_input = HandleRequestInput()
     
     import pydev_localhost
     client_server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), self.client_port), logRequests=False)
     client_server.register_function(handle_request_input.RequestInput)
     client_server.serve_forever()
            def run(self):
                class HandleRequestInput:
                    def RequestInput(self):
                        client_thread.requested_input = True
                        return 'RequestInput: OK'

                    def NotifyFinished(self, *args, **kwargs):
                        client_thread.notified_finished += 1
                        return 1

                handle_request_input = HandleRequestInput()

                import pydev_localhost
                self.client_server = client_server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), self.client_port), logRequests=False)
                client_server.register_function(handle_request_input.RequestInput)
                client_server.register_function(handle_request_input.NotifyFinished)
                client_server.serve_forever()
                def run(self):
                    class HandleRequestInput:
                        def RequestInput(self):
                            called_RequestInput[0] = True
                            return '\n'
                        def OpenEditor(self, name, line):
                            called_OpenEditor[0] = (name, line)
                            return True

                    handle_request_input = HandleRequestInput()

                    import pydev_localhost
                    client_server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), self.client_port), logRequests=False)
                    client_server.register_function(handle_request_input.RequestInput)
                    client_server.register_function(handle_request_input.OpenEditor)
                    client_server.serve_forever()
 def run(self):
     class HandleRequestInput:
         def RequestInput(self):
             client_thread.requested_input = True
             return 'input_request'
         
         def NotifyFinished(self, *args, **kwargs):
             client_thread.notified_finished += 1
             return 1
     
     handle_request_input = HandleRequestInput()
     
     import pydev_localhost
     client_server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), self.client_port), logRequests=False)
     client_server.register_function(handle_request_input.RequestInput)
     client_server.register_function(handle_request_input.NotifyFinished)
     client_server.serve_forever()
                def run(self):
                    class HandleRequestInput:
                        def RequestInput(self):
                            called_RequestInput[0] = True
                            return '\n'

                        def OpenEditor(self, name, line):
                            called_OpenEditor[0] = (name, line)
                            return True

                    handle_request_input = HandleRequestInput()

                    import pydev_localhost
                    client_server = SimpleXMLRPCServer(
                        (pydev_localhost.get_localhost(), self.client_port),
                        logRequests=False)
                    client_server.register_function(
                        handle_request_input.RequestInput)
                    client_server.register_function(
                        handle_request_input.OpenEditor)
                    client_server.serve_forever()
Exemple #11
0
 def __init__(self, addr, main_loop, **kwargs):
     SimpleXMLRPCServer.__init__(self, addr, **kwargs)
     self.main_loop = main_loop
     self.resp_queue = Queue.Queue()
Exemple #12
0
def start_server(host, port, interpreter):
    if port == 0:
        host = ''

    #I.e.: supporting the internal Jython version in PyDev to create a Jython interactive console inside Eclipse.
    from pydev_imports import SimpleXMLRPCServer as XMLRPCServer  #@Reimport

    try:
        if IS_PY24:
            server = XMLRPCServer((host, port), logRequests=False)
        else:
            server = XMLRPCServer((host, port),
                                  logRequests=False,
                                  allow_none=True)

    except:
        sys.stderr.write(
            'Error starting server with host: %s, port: %s, client_port: %s\n'
            % (host, port, interpreter.client_port))
        raise

    # Tell UMD the proper default namespace
    _set_globals_function(interpreter.getNamespace)

    server.register_function(interpreter.execLine)
    server.register_function(interpreter.execMultipleLines)
    server.register_function(interpreter.getCompletions)
    server.register_function(interpreter.getFrame)
    server.register_function(interpreter.getVariable)
    server.register_function(interpreter.changeVariable)
    server.register_function(interpreter.getDescription)
    server.register_function(interpreter.close)
    server.register_function(interpreter.interrupt)
    server.register_function(handshake)
    server.register_function(interpreter.connectToDebugger)
    server.register_function(interpreter.hello)
    server.register_function(interpreter.getArray)
    server.register_function(interpreter.evaluate)

    # Functions for GUI main loop integration
    server.register_function(interpreter.enableGui)

    if port == 0:
        (h, port) = server.socket.getsockname()

        print(port)
        print(interpreter.client_port)

    sys.stderr.write(interpreter.get_greeting_msg())
    sys.stderr.flush()

    while True:
        try:
            server.serve_forever()
        except:
            # Ugly code to be py2/3 compatible
            # https://sw-brainwy.rhcloud.com/tracker/PyDev/534:
            # Unhandled "interrupted system call" error in the pydevconsol.py
            e = sys.exc_info()[1]
            retry = False
            try:
                retry = e.args[0] == 4  #errno.EINTR
            except:
                pass
            if not retry:
                raise
            # Otherwise, keep on going
    return server
def start_server(host, port, interpreter):
    if port == 0:
        host = ''

    from pydev_imports import SimpleXMLRPCServer

    try:
        server = SimpleXMLRPCServer((host, port), logRequests=False, allow_none=True)

    except:
        sys.stderr.write('Error starting server with host: %s, port: %s, client_port: %s\n' % (host, port, client_port))
        raise

    server.register_function(interpreter.execLine)
    server.register_function(interpreter.getCompletions)
    server.register_function(interpreter.getFrame)
    server.register_function(interpreter.getVariable)
    server.register_function(interpreter.changeVariable)
    server.register_function(interpreter.getDescription)
    server.register_function(interpreter.close)
    server.register_function(interpreter.interrupt)
    server.register_function(handshake)

    if IPYTHON:
        try:
            interpreter.interpreter.ipython.hooks.editor = ipython_editor(interpreter)
        except:
            pass

    if port == 0:
        (h, port) = server.socket.getsockname()

        print(port)
        print(client_port)


    sys.stderr.write(interpreter.get_greeting_msg())

    server.serve_forever()

    return server
Exemple #14
0
def StartServer(host, port, client_port):
    #replace exit (see comments on method)
    #note that this does not work in jython!!! (sys method can't be replaced).
    sys.exit = _DoExit
    
    from pydev_imports import SimpleXMLRPCServer
    try:
        interpreter = InterpreterInterface(host, client_port)
        server = SimpleXMLRPCServer((host, port), logRequests=False)
    except:
        sys.stderr.write('Error starting server with host: %s, port: %s, client_port: %s\n' % (host, port, client_port))
        raise

    
    if True:
        server.register_function(interpreter.addExec)
        server.register_function(interpreter.getCompletions)
        server.register_function(interpreter.getDescription)
        server.register_function(interpreter.close)
        server.serve_forever()
        
    else:
        #This is still not finished -- that's why the if True is there :)
        from pydev_imports import Queue
        queue_requests_received = Queue.Queue() #@UndefinedVariable
        queue_return_computed = Queue.Queue() #@UndefinedVariable
        
        def addExec(line):
            queue_requests_received.put(('addExec', line))
            return queue_return_computed.get(block=True)
        
        def getCompletions(text):
            queue_requests_received.put(('getCompletions', text))
            return queue_return_computed.get(block=True)
        
        def getDescription(text):
            queue_requests_received.put(('getDescription', text))
            return queue_return_computed.get(block=True)
        
        def close():
            queue_requests_received.put(('close', None))
            return queue_return_computed.get(block=True)
            
        server.register_function(addExec)
        server.register_function(getCompletions)
        server.register_function(getDescription)
        server.register_function(close)
        try:
            import PyQt4.QtGui #We can only start the PyQt4 loop if we actually have access to it.
        except ImportError:
            print('Unable to process gui events (PyQt4.QtGui not imported)')
            server.serve_forever()
        else:
            import threading
            class PydevHandleRequestsThread(threading.Thread):
                
                def run(self):
                    while 1:
                        #This is done on a thread (so, it may be blocking or not blocking, it doesn't matter)
                        #anyways, the request will be put on a queue and the return will be gotten from another
                        #one -- and those queues are shared with the main thread.
                        server.handle_request()
                    
            app = PyQt4.QtGui.QApplication([])
            def serve_forever():
                """Handle one request at a time until doomsday."""
                while 1:
                    try:
                        try:
                            func, param = queue_requests_received.get(block=True,timeout=1.0/20.0) #20 loops/second
                            attr = getattr(interpreter, func)
                            if param is not None:
                                queue_return_computed.put(attr(param))
                            else:
                                queue_return_computed.put(attr())
                        except Queue.Empty: #@UndefinedVariable
                            pass
                        
                        PyQt4.QtGui.qApp.processEvents()
                    except:
                        import traceback;traceback.print_exc()
                    
            PydevHandleRequestsThread().start()
            serve_forever()
Exemple #15
0
def start_server(host, port, interpreter):
    if port == 0:
        host = ''

    from pydev_imports import SimpleXMLRPCServer

    try:
        server = SimpleXMLRPCServer((host, port), logRequests=False, allow_none=True)

    except:
        sys.stderr.write('Error starting server with host: %s, port: %s, client_port: %s\n' % (host, port, client_port))
        raise

    server.register_function(interpreter.execLine)
    server.register_function(interpreter.execMultipleLines)
    server.register_function(interpreter.getCompletions)
    server.register_function(interpreter.getFrame)
    server.register_function(interpreter.getVariable)
    server.register_function(interpreter.changeVariable)
    server.register_function(interpreter.getDescription)
    server.register_function(interpreter.close)
    server.register_function(interpreter.interrupt)
    server.register_function(handshake)

    if IPYTHON:
        try:
            interpreter.interpreter.ipython.hooks.editor = ipython_editor(interpreter)
        except:
            pass

    if port == 0:
        (h, port) = server.socket.getsockname()

        print(port)
        print(client_port)


    sys.stderr.write(interpreter.get_greeting_msg())

    server.serve_forever()

    return server
def start_server(host, port, interpreter):
    if port == 0:
        host = ''

    #I.e.: supporting the internal Jython version in PyDev to create a Jython interactive console inside Eclipse.
    from pydev_imports import SimpleXMLRPCServer as XMLRPCServer  #@Reimport

    try:
        if IS_PY24:
            server = XMLRPCServer((host, port), logRequests=False)
        else:
            server = XMLRPCServer((host, port),
                                  logRequests=False,
                                  allow_none=True)

    except:
        sys.stderr.write(
            'Error starting server with host: %s, port: %s, client_port: %s\n'
            % (host, port, interpreter.client_port))
        raise

    # Tell UMD the proper default namespace
    _set_globals_function(interpreter.getNamespace)

    server.register_function(interpreter.execLine)
    server.register_function(interpreter.execMultipleLines)
    server.register_function(interpreter.getCompletions)
    server.register_function(interpreter.getFrame)
    server.register_function(interpreter.getVariable)
    server.register_function(interpreter.changeVariable)
    server.register_function(interpreter.getDescription)
    server.register_function(interpreter.close)
    server.register_function(interpreter.interrupt)
    server.register_function(handshake)
    server.register_function(interpreter.connectToDebugger)
    server.register_function(interpreter.hello)
    server.register_function(interpreter.getArray)
    server.register_function(interpreter.evaluate)

    # Functions for GUI main loop integration
    server.register_function(interpreter.enableGui)

    if port == 0:
        (h, port) = server.socket.getsockname()

        print(port)
        print(interpreter.client_port)

    sys.stderr.write(interpreter.get_greeting_msg())
    sys.stderr.flush()

    server.serve_forever()

    return server
Exemple #17
0
def StartServer(host, port, client_port):
    #replace exit (see comments on method)
    #note that this does not work in jython!!! (sys method can't be replaced).
    sys.exit = _DoExit

    from pydev_imports import SimpleXMLRPCServer
    try:
        interpreter = InterpreterInterface(host, client_port)
        server = SimpleXMLRPCServer((host, port), logRequests=False)
    except:
        sys.stderr.write(
            'Error starting server with host: %s, port: %s, client_port: %s\n'
            % (host, port, client_port))
        raise

    if True:
        #Functions for basic protocol
        server.register_function(interpreter.addExec)
        server.register_function(interpreter.getCompletions)
        server.register_function(interpreter.getDescription)
        server.register_function(interpreter.close)

        #Functions so that the console can work as a debugger (i.e.: variables view, expressions...)
        server.register_function(interpreter.connectToDebugger)
        server.register_function(interpreter.postCommand)
        server.register_function(interpreter.hello)

        server.serve_forever()

    else:
        #This is still not finished -- that's why the if True is there :)
        from pydev_imports import Queue
        queue_requests_received = Queue.Queue()  #@UndefinedVariable
        queue_return_computed = Queue.Queue()  #@UndefinedVariable

        def addExec(line):
            queue_requests_received.put(('addExec', line))
            return queue_return_computed.get(block=True)

        def getCompletions(text):
            queue_requests_received.put(('getCompletions', text))
            return queue_return_computed.get(block=True)

        def getDescription(text):
            queue_requests_received.put(('getDescription', text))
            return queue_return_computed.get(block=True)

        def close():
            queue_requests_received.put(('close', None))
            return queue_return_computed.get(block=True)

        server.register_function(addExec)
        server.register_function(getCompletions)
        server.register_function(getDescription)
        server.register_function(close)
        try:
            import PyQt4.QtGui  #We can only start the PyQt4 loop if we actually have access to it.
        except ImportError:
            print('Unable to process gui events (PyQt4.QtGui not imported)')
            server.serve_forever()
        else:
            import threading

            class PydevHandleRequestsThread(threading.Thread):
                def run(self):
                    while 1:
                        #This is done on a thread (so, it may be blocking or not blocking, it doesn't matter)
                        #anyways, the request will be put on a queue and the return will be gotten from another
                        #one -- and those queues are shared with the main thread.
                        server.handle_request()

            app = PyQt4.QtGui.QApplication([])

            def serve_forever():
                """Handle one request at a time until doomsday."""
                while 1:
                    try:
                        try:
                            func, param = queue_requests_received.get(
                                block=True,
                                timeout=1.0 / 20.0)  #20 loops/second
                            attr = getattr(interpreter, func)
                            if param is not None:
                                queue_return_computed.put(attr(param))
                            else:
                                queue_return_computed.put(attr())
                        except Queue.Empty:  #@UndefinedVariable
                            pass

                        PyQt4.QtGui.qApp.processEvents()
                    except:
                        import traceback
                        traceback.print_exc()

            PydevHandleRequestsThread().start()
            serve_forever()
 def __init__(self, *args, **kwargs):
     SimpleXMLRPCServer.__init__(self, *args, **kwargs)
     # Tell the inputhook mechanisms when control should be returned
     set_return_control_callback(self.return_control)
     self.debug_hook = None
     self.return_control_osc = False
Exemple #19
0
 def handle_error(self, request, client_address):
     type_, value = sys.exc_info()[:2]
     if issubclass(type_, KeyboardInterrupt):
         sys.stderr.write('\n'.join(traceback.format_exception_only(type_, value)))
     else:
         SimpleXMLRPCServer.handle_error(self, request, client_address)
def start_server(host, port, interpreter):
    if port == 0:
        host = ''

    #I.e.: supporting the internal Jython version in PyDev to create a Jython interactive console inside Eclipse.
    from pydev_imports import SimpleXMLRPCServer as XMLRPCServer  #@Reimport

    try:
        server = XMLRPCServer((host, port), logRequests=False, allow_none=True)

    except:
        sys.stderr.write('Error starting server with host: %s, port: %s, client_port: %s\n' % (host, port, client_port))
        raise

    # Tell UMD the proper default namespace
    _set_globals_function(interpreter.getNamespace)

    server.register_function(interpreter.execLine)
    server.register_function(interpreter.execMultipleLines)
    server.register_function(interpreter.getCompletions)
    server.register_function(interpreter.getFrame)
    server.register_function(interpreter.getVariable)
    server.register_function(interpreter.changeVariable)
    server.register_function(interpreter.getDescription)
    server.register_function(interpreter.close)
    server.register_function(interpreter.interrupt)
    server.register_function(handshake)
    server.register_function(interpreter.connectToDebugger)
    server.register_function(interpreter.hello)
    server.register_function(interpreter.getArray)
    server.register_function(interpreter.evaluate)

    # Functions for GUI main loop integration
    server.register_function(interpreter.enableGui)

    if port == 0:
        (h, port) = server.socket.getsockname()

        print(port)
        print(client_port)


    sys.stderr.write(interpreter.get_greeting_msg())
    sys.stderr.flush()

    server.serve_forever()

    return server
Exemple #21
0
def start_server(host, port, interpreter):
    if port == 0:
        host = ''

    #I.e.: supporting the internal Jython version in PyDev to create a Jython interactive console inside Eclipse.
    from pydev_imports import SimpleXMLRPCServer as XMLRPCServer  #@Reimport

    try:
        if IS_PY24:
            server = XMLRPCServer((host, port), logRequests=False)
        else:
            server = XMLRPCServer((host, port), logRequests=False, allow_none=True)

    except:
        sys.stderr.write('Error starting server with host: %s, port: %s, client_port: %s\n' % (host, port, interpreter.client_port))
        raise

    # Tell UMD the proper default namespace
    _set_globals_function(interpreter.getNamespace)

    server.register_function(interpreter.execLine)
    server.register_function(interpreter.execMultipleLines)
    server.register_function(interpreter.getCompletions)
    server.register_function(interpreter.getFrame)
    server.register_function(interpreter.getVariable)
    server.register_function(interpreter.changeVariable)
    server.register_function(interpreter.getDescription)
    server.register_function(interpreter.close)
    server.register_function(interpreter.interrupt)
    server.register_function(handshake)
    server.register_function(interpreter.connectToDebugger)
    server.register_function(interpreter.hello)
    server.register_function(interpreter.getArray)
    server.register_function(interpreter.evaluate)

    # Functions for GUI main loop integration
    server.register_function(interpreter.enableGui)

    if port == 0:
        (h, port) = server.socket.getsockname()

        print(port)
        print(interpreter.client_port)


    sys.stderr.write(interpreter.get_greeting_msg())
    sys.stderr.flush()

    while True:
        try:
            server.serve_forever()
        except:
            # Ugly code to be py2/3 compatible
            # https://sw-brainwy.rhcloud.com/tracker/PyDev/534:
            # Unhandled "interrupted system call" error in the pydevconsol.py
            e = sys.exc_info()[1]
            retry = False
            try:
                retry = e.args[0] == 4 #errno.EINTR
            except:
                pass
            if not retry:
                raise
            # Otherwise, keep on going
    return server
Exemple #22
0
 def __init__(self, *args, **kwargs):
     SimpleXMLRPCServer.__init__(self, *args, **kwargs)
     self.debug_hook = None
Exemple #23
0
 def __init__(self, addr, main_loop, **kwargs):
     SimpleXMLRPCServer.__init__(self, addr, **kwargs)
     self.main_loop = main_loop
     self.resp_queue = Queue.Queue()
 def __init__(self, *args, **kwargs):
     SimpleXMLRPCServer.__init__(self, *args, **kwargs)
     # Tell the inputhook mechanisms when control should be returned
     set_return_control_callback(self.return_control)
     self.debug_hook = None
     self.return_control_osc = False