Skip to content

Commit

Permalink
refactor: Replace xmlrpc with jsonrpclib in server and client
Browse files Browse the repository at this point in the history
  • Loading branch information
andreztz committed Aug 15, 2024
1 parent a5ecd21 commit ea6910d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
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")

0 comments on commit ea6910d

Please sign in to comment.