From da0d33cfd368e2f237ab28bf7a7f00e3d281005a Mon Sep 17 00:00:00 2001 From: Robert S Date: Sun, 7 Aug 2022 18:26:14 +0200 Subject: [PATCH] Fix issues --- .env.example | 2 -- docs/conf.py | 4 ++-- docs/requirements.txt | 2 +- requirements.txt | 3 ++- setup.cfg | 3 ++- src/mofh/__init__.py | 4 +++- src/mofh/main.py | 37 ++++++++++++++----------------------- 7 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index e101f67..0000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -USERNAME= -PASSWORD= \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index facdc83..616d06f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -7,9 +7,9 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = "mofh" -copyright = "2022, Robert S." +copyright = "MMXXII, Robert S" author = "Robert S." -release = "1.0.0" +release = "1.0.1" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/docs/requirements.txt b/docs/requirements.txt index 5bfb3f0..340d3aa 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,2 @@ sphinx==5.1.1 -mofh==1.0.0 \ No newline at end of file +mofh==1.0.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index bbcb117..d58d7e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ aiohttp[speedups]==3.8.1 asyncio==3.4.3 uvloop==0.16.0 -requests==2.28.1 \ No newline at end of file +requests==2.28.1 +defusedxml==0.7.1 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 88c3be8..9396616 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] name = mofh description = API wrapper for https://myownfreehost.net -version = 1.0.0 +version = 1.0.1 author = Robert S. author_email = admin@robert-s.dev url = https://github.com/Wallvon/mofh @@ -38,6 +38,7 @@ install_requires = asyncio>=3.4.3 uvloop>=0.16.0 requests>=2.28.1 + defusedxml>=0.7.1 python_requires = >=3.8 package_dir = =src diff --git a/src/mofh/__init__.py b/src/mofh/__init__.py index 9ce8a4e..6a4294a 100755 --- a/src/mofh/__init__.py +++ b/src/mofh/__init__.py @@ -1 +1,3 @@ -from .main import Client, AsyncClient +from .main import * + +__version__ = "1.0.1" diff --git a/src/mofh/main.py b/src/mofh/main.py index 01ec4d6..dc39a25 100755 --- a/src/mofh/main.py +++ b/src/mofh/main.py @@ -1,8 +1,7 @@ import ast import asyncio -import xml.etree.ElementTree +from defusedxml import ElementTree from typing import Optional, Any, Union -from xml.etree.ElementTree import Element import uvloop from aiohttp import ClientSession, BasicAuth, TCPConnector @@ -12,7 +11,7 @@ from .errors import APIError -class Client(object): +class Client: """ MyOwnFreeHost API client. @@ -55,17 +54,14 @@ def _ensure_session(self) -> Session: return self._session @staticmethod - def _parse_xml(response: str) -> Element: + def _parse_xml(response: str) -> Any: """ Parses the XML response and returns a dictionary. :param response: XML response. """ # Parse the response and get the root element. - tree = xml.etree.ElementTree.ElementTree( - xml.etree.ElementTree.fromstring(response) - ) - root = tree.getroot() + root = ElementTree.fromstring(response) return root @@ -116,10 +112,9 @@ def create( if status == "1": # Return the vPanel username. return root[0][0][1].text - else: - # Raise exception with error. - error = root[0][3].text - raise APIError(error, 0) + # Raise exception with error. + error = root[0][3].text + raise APIError(error, 0) def suspend(self, username: str, reason: str) -> Optional[int]: """ @@ -337,9 +332,9 @@ def close(self) -> None: self._session.close() -class AsyncClient(object): +class AsyncClient: """ - MyOwnFreeHost Async API client. + MyOwnFreeHost async API client. :param username: MyOwnFreeHost API username :param password: MyOwnFreeHost API password @@ -385,17 +380,14 @@ async def _ensure_session(self) -> Any: return self._session @staticmethod - def _parse_xml(response: str) -> Element: + def _parse_xml(response: str) -> Any: """ Parses the XML response and returns a dictionary. :param response: XML response. """ # Parse the response and get the root element. - tree = xml.etree.ElementTree.ElementTree( - xml.etree.ElementTree.fromstring(response) - ) - root = tree.getroot() + root = ElementTree.fromstring(response) return root @@ -446,10 +438,9 @@ async def create( if status == "1": # Return the vPanel username. return root[0][0][1].text - else: - # Raise exception with error. - error = root[0][3].text - raise APIError(error, 0) + # Raise exception with error. + error = root[0][3].text + raise APIError(error, 0) async def suspend(self, username: str, reason: str) -> Optional[int]: """