Skip to content
Snippets Groups Projects
Commit 04ed7ad4 authored by Vincent Texier's avatar Vincent Texier
Browse files

[enh] #91 fix pylint alerts in api.endpoint module

Remove some alerts
parent ad9847be
No related branches found
No related tags found
1 merge request!60Pylint
......@@ -17,4 +17,4 @@ mypy:
# check code errors
pylint:
pylint --disable=C --enable=C0121,C0202,C0321 --jobs=0 duniterpy/
pylint --disable=C,R0913,R0903 --enable=C0121,C0202,C0321 --jobs=0 duniterpy/
......@@ -3,7 +3,7 @@ from typing import Any, Optional, TypeVar, Type, Dict
from aiohttp import ClientSession
from ..constants import *
import duniterpy.constants as constants
from ..documents import MalformedDocumentError
......@@ -137,9 +137,9 @@ class BMAEndpoint(Endpoint):
API = "BASIC_MERKLED_API"
re_inline = re.compile(
'^BASIC_MERKLED_API(?: ({host_regex}))?(?: ({ipv4_regex}))?(?: ({ipv6_regex}))?(?: ([0-9]+))$'.format(
host_regex=HOST_REGEX,
ipv4_regex=IPV4_REGEX,
ipv6_regex=IPV6_REGEX))
host_regex=constants.HOST_REGEX,
ipv4_regex=constants.IPV4_REGEX,
ipv6_regex=constants.IPV6_REGEX))
def __init__(self, server: str, ipv4: str, ipv6: str, port: int) -> None:
"""
......@@ -193,11 +193,13 @@ class BMAEndpoint(Endpoint):
:return:
"""
if self.server:
return ConnectionHandler("http", "ws", self.server, self.port, "", session, proxy)
conn_handler = ConnectionHandler("http", "ws", self.server, self.port, "", session, proxy)
elif self.ipv6:
return ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, "", session, proxy)
conn_handler = ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, "", session, proxy)
else:
conn_handler = ConnectionHandler("http", "ws", self.ipv4, self.port, "", session, proxy)
return ConnectionHandler("http", "ws", self.ipv4, self.port, "", session, proxy)
return conn_handler
def __str__(self) -> str:
return self.inline()
......@@ -220,10 +222,10 @@ class SecuredBMAEndpoint(BMAEndpoint):
API = "BMAS"
re_inline = re.compile(
'^BMAS(?: ({host_regex}))?(?: ({ipv4_regex}))?(?: ({ipv6_regex}))? ([0-9]+)(?: ({path_regex}))?$'.format(
host_regex=HOST_REGEX,
ipv4_regex=IPV4_REGEX,
ipv6_regex=IPV6_REGEX,
path_regex=PATH_REGEX))
host_regex=constants.HOST_REGEX,
ipv4_regex=constants.IPV4_REGEX,
ipv6_regex=constants.IPV6_REGEX,
path_regex=constants.PATH_REGEX))
def __init__(self, server: str, ipv4: str, ipv6: str, port: int, path: str) -> None:
"""
......@@ -276,11 +278,14 @@ class SecuredBMAEndpoint(BMAEndpoint):
:return:
"""
if self.server:
return ConnectionHandler("https", "wss", self.server, self.port, self.path, session, proxy)
conn_handler = ConnectionHandler("https", "wss", self.server, self.port, self.path, session, proxy)
elif self.ipv6:
return ConnectionHandler("https", "wss", "[{0}]".format(self.ipv6), self.port, self.path, session, proxy)
conn_handler = ConnectionHandler("https", "wss", "[{0}]".format(self.ipv6), self.port, self.path, session,
proxy)
else:
conn_handler = ConnectionHandler("https", "wss", self.ipv4, self.port, self.path, session, proxy)
return ConnectionHandler("https", "wss", self.ipv4, self.port, self.path, session, proxy)
return conn_handler
# required to type hint cls in classmethod
......@@ -290,12 +295,15 @@ WS2PEndpointType = TypeVar('WS2PEndpointType', bound='WS2PEndpoint')
class WS2PEndpoint(Endpoint):
API = "WS2P"
re_inline = re.compile(
'^WS2P ({ws2pid_regex}) ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)?(?: ({path_regex}))?$'.format(
ws2pid_regex=WS2PID_REGEX,
host_regex=HOST_REGEX,
ipv4_regex=IPV4_REGEX,
ipv6_regex=IPV6_REGEX,
path_regex=PATH_REGEX))
'^WS2P ({ws2pid_regex}) ((?:{host_regex})|(?:{ipv4_regex})|(?:{ipv6_regex})) ([0-9]+)?(?: ({path_regex}))?$'
.format(
ws2pid_regex=constants.WS2PID_REGEX,
host_regex=constants.HOST_REGEX,
ipv4_regex=constants.IPV4_REGEX,
ipv6_regex=constants.IPV6_REGEX,
path_regex=constants.PATH_REGEX
)
)
def __init__(self, ws2pid: str, server: str, port: int, path: str) -> None:
self.ws2pid = ws2pid
......@@ -361,8 +369,8 @@ ESCoreEndpointType = TypeVar('ESCoreEndpointType', bound='ESCoreEndpoint')
class ESCoreEndpoint(Endpoint):
API = "ES_CORE_API"
re_inline = re.compile(
'^ES_CORE_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$'.format(host_regex=HOST_REGEX,
ipv4_regex=IPV4_REGEX))
'^ES_CORE_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$'.format(host_regex=constants.HOST_REGEX,
ipv4_regex=constants.IPV4_REGEX))
def __init__(self, server: str, port: int) -> None:
self.server = server
......@@ -421,8 +429,8 @@ ESUserEndpointType = TypeVar('ESUserEndpointType', bound='ESUserEndpoint')
class ESUserEndpoint(Endpoint):
API = "ES_USER_API"
re_inline = re.compile(
'^ES_USER_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$'.format(host_regex=HOST_REGEX,
ipv4_regex=IPV4_REGEX))
'^ES_USER_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$'.format(host_regex=constants.HOST_REGEX,
ipv4_regex=constants.IPV4_REGEX))
def __init__(self, server: str, port: int) -> None:
self.server = server
......@@ -481,8 +489,8 @@ ESSubscribtionEndpointType = TypeVar('ESSubscribtionEndpointType', bound='ESSubs
class ESSubscribtionEndpoint(Endpoint):
API = "ES_SUBSCRIPTION_API"
re_inline = re.compile(
'^ES_SUBSCRIPTION_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$'.format(host_regex=HOST_REGEX,
ipv4_regex=IPV4_REGEX))
'^ES_SUBSCRIPTION_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$'.format(host_regex=constants.HOST_REGEX,
ipv4_regex=constants.IPV4_REGEX))
def __init__(self, server: str, port: int) -> None:
self.server = server
......@@ -551,12 +559,17 @@ def endpoint(value: Any) -> Any:
:param value: Endpoint string or subclass
:return:
"""
result = UnknownEndpoint.from_inline(value)
# if Endpoint instance...
if issubclass(type(value), Endpoint):
return value
result = value
# if str...
elif isinstance(value, str):
# find Endpoint instance
for api, cls in MANAGED_API.items():
if value.startswith(api + " "):
return cls.from_inline(value)
return UnknownEndpoint.from_inline(value)
result = cls.from_inline(value)
else:
raise TypeError("Cannot convert {0} to endpoint".format(value))
return result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment