File: xmlrpc.py

package info (click to toggle)
webmin-xmlrpc 0.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 84 kB
  • sloc: python: 57; makefile: 7
file content (23 lines) | stat: -rw-r--r-- 775 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""The XMLRPC client."""

import xmlrpc.client
from typing import Any

from aiohttp import ClientSession


class XMLRPCClient:
    """Represent a XMLRPC client."""

    def __init__(self, session: ClientSession, url: str = "/xmlrpc.cgi"):
        """Initialize the XMLRPC client."""
        self._session = session
        self._url = url

    async def call(self, method_name: str, params: tuple = ()) -> Any:
        """Call a XML-RPC method."""
        xmlrequest = xmlrpc.client.dumps(methodname=method_name, params=params)
        async with self._session.post(url=self._url, data=xmlrequest) as response:
            response.raise_for_status()
            xmlresponse = xmlrpc.client.loads((await response.read()).decode("utf-8"))
            return xmlresponse[0][0]