Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPV6 support to unoserver #105

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/unoserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import signal
import socket
import subprocess
import sys
import tempfile
Expand All @@ -15,6 +16,22 @@
logger = logging.getLogger("unoserver")


class XMLRPCServer(xmlrpc.server.SimpleXMLRPCServer):
def __init__(
self,
addr: tuple[str, int],
allow_none: bool = False,
) -> None:
addr_info = socket.getaddrinfo(addr[0], addr[1], proto=socket.IPPROTO_TCP)

if len(addr_info) == 0:
raise RuntimeError(f"Could not get interface information for {addr[0]}:{addr[1]}")

self.address_family = addr_info[0][0]
self.socket_type = addr_info[0][1]
super().__init__(addr=addr_info[0][4], allow_none=allow_none)


class UnoServer:
def __init__(
self,
Expand Down Expand Up @@ -84,7 +101,7 @@ def signal_handler(signum, frame):

def serve(self):
# Create server
with xmlrpc.server.SimpleXMLRPCServer(
with XMLRPCServer(
(self.interface, int(self.port)), allow_none=True
) as server:
self.xmlrcp_server = server
Expand Down
20 changes: 20 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@ def test_server_params(popen_mock, thread_mock):
"--accept=socket,host=127.0.0.1,port=2202,tcpNoDelay=1;urp;StarOffice.ComponentContext",
]
)

@mock.patch("threading.Thread")
@mock.patch("subprocess.Popen")
def test_server_ipv6_params(popen_mock, thread_mock):
srv = server.UnoServer(interface="::", port="2203", uno_port="2202")
srv.start()
popen_mock.assert_called_with(
[
"libreoffice",
"--headless",
"--invisible",
"--nocrashreport",
"--nodefault",
"--nologo",
"--nofirststartwizard",
"--norestore",
f"-env:UserInstallation={srv.user_installation}",
"--accept=socket,host=127.0.0.1,port=2202,tcpNoDelay=1;urp;StarOffice.ComponentContext",
]
)
Loading