def run(self) -> None:
        from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import (
            STOP_WRITER_THREAD,
        )

        socket, _addr = self._server_socket.accept()
        self._server_socket.close()

        from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import (
            writer_thread,
        )
        from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import (
            reader_thread,
        )
        import queue
        from robotframework_debug_adapter_tests.fixtures import _DebuggerAPI

        read_from = socket.makefile("rb")
        write_to = socket.makefile("wb")

        write_queue: queue.Queue = queue.Queue()
        read_queue: queue.Queue = queue.Queue()

        writer = threading.Thread(
            target=writer_thread,
            args=(write_to, write_queue),
            name="Client debugger API writer",
        )
        writer.daemon = True
        reader = threading.Thread(
            target=reader_thread,
            args=(read_from, read_queue.put, read_queue),
            name="Client debugger API reader",
        )
        reader.daemon = True

        reader.start()
        writer.start()

        self.debugger_api = _DebuggerAPI(
            reader=reader,
            writer=writer,
            write_queue=write_queue,
            read_queue=read_queue,
            dap_resources_dir=None,
        )
        self.started.set()

        try:
            assert self.finish.wait(5)
            write_queue.put(STOP_WRITER_THREAD)
            socket.shutdown(SHUT_WR)
            socket.close()
        except:
            log.exception()
        finally:
            self.sockets_closed.set()
Пример #2
0
def makefile(
    self: socket_cls,
    mode: Union["Literal['r']", "Literal['w']", "Literal['rw']",
                "Literal['wr']", "Literal['']"] = "r",
    buffering: Optional[int] = None,
    *args: Any,
    **kwargs: Any,
) -> Union[BinaryIO, TextIO]:
    # We disable buffering with SecureTransport because it conflicts with
    # the buffering that ST does internally (see issue #1153 for more).
    buffering = 0
    return socket_cls.makefile(self, mode, buffering, *args, **kwargs)
Пример #3
0
def socket_read(socket):
    """Read a quoted request (ending with a newline character) from the given socket.

    Arguments:
    socket         -- A connection socket as returned by socket.accept().

    Returns:
    String         -- after stripping and unquoting the request received.
    """
    rfile = socket.makefile('rb')
    request = unquote(rfile.readline().strip())
    rfile.close()
    return request
Пример #4
0
def socket_write(socket, message):
    """Write the given message as a quoted string to the socket ending with a newline character.

    Arguments:
    socket  -- A connection socket as returned by socket.accept().
    message -- A string or string like object that can be written into the socket.

    Post-condition:
    The message is quoted and then written as a string to the socket appended with a newline character.
    """
    wfile = socket.makefile('wb')
    wfile.write('{}\n'.format(quote(message)))
    wfile.close()
Пример #5
0
 def _fileobject(sock, *args, **kwargs):
      return _original_socket.makefile(sock, *args, **kwargs)
Пример #6
0
 def makefile(self, *args, **kwargs):
     return _original_socket.makefile(self, *args, **kwargs)
Пример #7
0
 def __init__(self, sock, mode='rwb', bufsize=-1, close=False):
     super().__init__()
     self._sock = sock
     self._close = close
     self._obj = __socket__socket__.makefile(sock, mode, bufsize)
Пример #8
0
 def makefile(self, *args, **kwargs):
     return _original_socket.makefile(self, *args, **kwargs)
Пример #9
0
 def __init__(self, sock, mode='rwb', bufsize=-1, close=False):
     super().__init__()
     self._sock = sock
     self._close = close
     self._obj = __socket__socket__.makefile(sock, mode, bufsize)
Пример #10
0
def makefile(self, mode="r", buffering=None, *args, **kwargs):
    # We disable buffering with SecureTransport because it conflicts with
    # the buffering that ST does internally (see issue #1153 for more).
    buffering = 0
    return socket_cls.makefile(self, mode, buffering, *args, **kwargs)