Пример #1
0
    def __init__(self, notifications_queue, port, daemon=False):
        threading.Thread.__init__(self)
        self.setDaemon(
            daemon
        )  # If False, wait for all the notifications to be passed before exiting!
        self.finished = False
        self.notifications_queue = notifications_queue

        from _pydev_bundle import pydev_localhost

        # It is necessary to specify an encoding, that matches
        # the encoding of all bytes-strings passed into an
        # XMLRPC call: "All 8-bit strings in the data structure are assumed to use the
        # packet encoding.  Unicode strings are automatically converted,
        # where necessary."
        # Byte strings most likely come from file names.
        encoding = file_system_encoding
        if encoding == "mbcs":
            # Windos symbolic name for the system encoding CP_ACP.
            # We need to convert it into a encoding that is recognized by Java.
            # Unfortunately this is not always possible. You could use
            # GetCPInfoEx and get a name similar to "windows-1251". Then
            # you need a table to translate on a best effort basis. Much to complicated.
            # ISO-8859-1 is good enough.
            encoding = "ISO-8859-1"

        self.server = xmlrpclib.Server('http://%s:%s' %
                                       (pydev_localhost.get_localhost(), port),
                                       encoding=encoding)
Пример #2
0
    def test_server(self):
        # Just making sure that the singleton is created in this thread.
        try:
            from _pydev_bundle.pydev_ipython_console_011 import get_pydev_frontend
        except:
            sys.stderr.write(
                'Skipped test because IPython could not be imported.')
            return
        get_pydev_frontend(get_localhost(), 0)

        client_port, server_port = self.get_free_addresses()

        class ServerThread(threading.Thread):
            def __init__(self, client_port, server_port):
                threading.Thread.__init__(self)
                self.client_port = client_port
                self.server_port = server_port

            def run(self):
                from _pydev_bundle import pydev_localhost
                print('Starting server with:', pydev_localhost.get_localhost(),
                      self.server_port, self.client_port)
                pydevconsole.start_server(pydev_localhost.get_localhost(),
                                          self.server_port, self.client_port)

        server_thread = ServerThread(client_port, server_port)
        server_thread.setDaemon(True)
        server_thread.start()

        client_thread = self.start_client_thread(client_port)  #@UnusedVariable

        try:
            import time
            time.sleep(.3)  #let's give it some time to start the threads

            from _pydev_bundle import pydev_localhost
            server = xmlrpclib.Server(
                'http://%s:%s' %
                (pydev_localhost.get_localhost(), server_port))
            server.execLine(
                "import sys; print('Running with: %s %s' % (sys.executable or sys.platform, sys.version))"
            )
            server.execLine('class Foo:')
            server.execLine('    pass')
            server.execLine('')
            server.execLine('foo = Foo()')
            server.execLine('a = %s()' % raw_input_name)
            initial = time.time()
            while not client_thread.requested_input:
                if time.time() - initial > 2:
                    raise AssertionError(
                        'Did not get the return asked before the timeout.')
                time.sleep(.1)
            frame_xml = server.getFrame()
            self.assert_('RequestInput' in frame_xml,
                         'Did not fid RequestInput in:\n%s' % (frame_xml, ))
        finally:
            client_thread.shutdown()
 def readline(self, *args, **kwargs):
     #Ok, callback into the client to get the new input
     try:
         server = xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port))
         requested_input = server.RequestInput()
         if not requested_input:
             return '\n' #Yes, a readline must return something (otherwise we can get an EOFError on the input() call).
         return requested_input
     except:
         return '\n'
Пример #4
0
    def test_server(self):
        self.original_stdout = sys.stdout
        sys.stdout = pydevd_io.IOBuf()
        try:
            client_port, server_port = self.get_free_addresses()

            class ServerThread(threading.Thread):
                def __init__(self, client_port, server_port):
                    threading.Thread.__init__(self)
                    self.client_port = client_port
                    self.server_port = server_port

                def run(self):
                    from _pydev_bundle import pydev_localhost
                    pydevconsole.start_server(pydev_localhost.get_localhost(),
                                              self.server_port,
                                              self.client_port)

            server_thread = ServerThread(client_port, server_port)
            server_thread.setDaemon(True)
            server_thread.start()

            client_thread = self.start_client_thread(
                client_port)  #@UnusedVariable

            import time
            time.sleep(.3)  #let's give it some time to start the threads
            sys.stdout = pydevd_io.IOBuf()

            from _pydev_bundle import pydev_localhost
            server = xmlrpclib.Server(
                'http://%s:%s' %
                (pydev_localhost.get_localhost(), server_port))
            server.execLine('class Foo:')
            server.execLine('    pass')
            server.execLine('')
            server.execLine('foo = Foo()')
            server.execLine('a = %s()' % (raw_input_name, ))
            server.execLine('print (a)')
            initial = time.time()
            while not client_thread.requested_input:
                if time.time() - initial > 2:
                    raise AssertionError(
                        'Did not get the return asked before the timeout.')
                time.sleep(.1)

            found = sys.stdout.getvalue()
            while ['input_request'] != found.split():
                found += sys.stdout.getvalue()
                if time.time() - initial > 2:
                    break
                time.sleep(.1)
            self.assertEqual(['input_request'], found.split())
        finally:
            sys.stdout = self.original_stdout
Пример #5
0
 def readline(self, *args, **kwargs):
     # Ok, callback into the client to get the new input
     try:
         server = xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port))
         requested_input = server.RequestInput()
         if not requested_input:
             return '\n'  # Yes, a readline must return something (otherwise we can get an EOFError on the input() call).
         return requested_input
     except KeyboardInterrupt:
         raise  # Let KeyboardInterrupt go through -- #PyDev-816: Interrupting infinite loop in the Interactive Console
     except:
         return '\n'
Пример #6
0
 def readline(self, *args, **kwargs):
     #Ok, callback into the client to get the new input
     try:
         server = xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port))
         requested_input = server.RequestInput()
         if not requested_input:
             return '\n' #Yes, a readline must return something (otherwise we can get an EOFError on the input() call).
         else:
             # readline should end with '\n' (not doing so makes IPython 5 remove the last *valid* character).
             requested_input += '\n'
         return requested_input
     except:
         return '\n'
Пример #7
0
    def call_editor(filename, line=0, wait=True):
        """ Open an editor in PyDev """
        if line is None:
            line = 0

        # Make sure to send an absolution path because unlike most editor hooks
        # we don't launch a process. This is more like what happens in the zmqshell
        filename = os.path.abspath(filename)

        # import sys
        # sys.__stderr__.write('Calling editor at: %s:%s\n' % (pydev_host, pydev_client_port))

        # Tell PyDev to open the editor
        server = xmlrpclib.Server('http://%s:%s' %
                                  (pydev_host, pydev_client_port))
        server.IPythonEditor(filename, str(line))

        if wait:
            input("Press Enter when done editing:")
Пример #8
0
 def get_server(self):
     if getattr(self, 'host', None) is not None:
         return xmlrpclib.Server('http://%s:%s' %
                                 (self.host, self.client_port))
     else:
         return None
def run_client(job_id, port, verbosity, coverage_output_file,
               coverage_include):
    job_id = int(job_id)

    from _pydev_bundle import pydev_localhost
    server = xmlrpclib.Server('http://%s:%s' %
                              (pydev_localhost.get_localhost(), port))
    server.lock = threading.Lock()

    server_comm = ServerComm(job_id, server)
    server_comm.start()

    try:
        server_facade = ServerFacade(server_comm.notifications_queue)
        from _pydev_runfiles import pydev_runfiles
        from _pydev_runfiles import pydev_runfiles_xml_rpc
        pydev_runfiles_xml_rpc.set_server(server_facade)

        #Starts None and when the 1st test is gotten, it's started (because a server may be initiated and terminated
        #before receiving any test -- which would mean a different process got all the tests to run).
        coverage = None

        try:
            tests_to_run = [1]
            while tests_to_run:
                #Investigate: is it dangerous to use the same xmlrpclib server from different threads?
                #It seems it should be, as it creates a new connection for each request...
                server.lock.acquire()
                try:
                    tests_to_run = server.GetTestsToRun(job_id)
                finally:
                    server.lock.release()

                if not tests_to_run:
                    break

                if coverage is None:
                    _coverage_files, coverage = start_coverage_support_from_params(
                        None, coverage_output_file, 1, coverage_include)

                files_to_tests = {}
                for test in tests_to_run:
                    filename_and_test = test.split('|')
                    if len(filename_and_test) == 2:
                        files_to_tests.setdefault(filename_and_test[0],
                                                  []).append(
                                                      filename_and_test[1])

                configuration = pydev_runfiles.Configuration(
                    '',
                    verbosity,
                    None,
                    None,
                    None,
                    files_to_tests,
                    1,  #Always single job here
                    None,

                    #The coverage is handled in this loop.
                    coverage_output_file=None,
                    coverage_include=None,
                )
                test_runner = pydev_runfiles.PydevTestRunner(configuration)
                sys.stdout.flush()
                test_runner.run_tests(handle_coverage=False)
        finally:
            if coverage is not None:
                coverage.stop()
                coverage.save()

    except:
        traceback.print_exc()
    server_comm.notifications_queue.put_nowait(KillServer())