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

refactor: Replace xmlrpc with jsonrpclib in server and client #40

Merged
merged 1 commit into from
Aug 15, 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
26 changes: 11 additions & 15 deletions xradios/core/server.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import logging
import sys
import signal
import sys


from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler

from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCRequestHandler
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
from pyradios import RadioBrowser

from tinydb import Query
from tinydb import TinyDB

from xradios import xradios_data_dir
from xradios.core.metadata import metadata_manager
from xradios.core.player import player
from xradios import xradios_data_dir


log = logging.getLogger("xradiosd")
effective_log_level = logging.getLevelName(log.getEffectiveLevel())
Expand All @@ -31,6 +27,7 @@
def cmd(name):
def decorator(func):
command_handlers[name] = func

return decorator


Expand Down Expand Up @@ -93,17 +90,15 @@ def remove_favorite(**station):
log.debug(f"Removing a station from favorites {station=}")


class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ("/", "/RPC2")
class RequestHandler(SimpleJSONRPCRequestHandler):
pass


class RPCServer:
def __init__(self, address):
self._serv = SimpleXMLRPCServer(
self._serv = SimpleJSONRPCServer(
address,
allow_none=True,
requestHandler=RequestHandler,
use_builtin_types=True,
)
self._serv.register_introspection_functions()

Expand All @@ -112,7 +107,7 @@ def __init__(self, address):
self.register_function(getattr(self, key))

def register_function(self, function, name=None):
def _function(args, kwargs):
def _function(*args, **kwargs):
return function(*args, **kwargs)

_function.__name__ = function.__name__
Expand All @@ -134,7 +129,8 @@ def sigterm_handler(signo, frame, server):
def run(host="", port=10000):
server = RPCServer((host, port))
signal.signal(
signal.SIGTERM, lambda signo, frame: sigterm_handler(signo, frame, server)
signal.SIGTERM,
lambda signo, frame: sigterm_handler(signo, frame, server),
)
log.info(f"Serving XML-RPC port: {port}")
server.serve_forever()
Expand Down
15 changes: 2 additions & 13 deletions xradios/tui/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
from xmlrpc.client import ServerProxy
from jsonrpclib import Server


class Proxy:
def __init__(self, url):
self._xmlrpc_server_proxy = ServerProxy(url)
def __getattr__(self, name):
call_proxy = getattr(self._xmlrpc_server_proxy, name)
def _call(*args, **kwargs):
return call_proxy(args, kwargs)
return _call


proxy = Proxy('http://localhost:10000')
proxy = Server("http://localhost:10000")