diff --git a/duniterpy/api/endpoint.py b/duniterpy/api/endpoint.py index f8288382d38b9a04fad5012ccbb03901cdca90c4..20690b74d9de0a86f135e61e77fee3ea260039d5 100644 --- a/duniterpy/api/endpoint.py +++ b/duniterpy/api/endpoint.py @@ -16,7 +16,7 @@ import re from typing import Any, Dict, Optional, Type, TypeVar -from duniterpy import constants +from duniterpy import constants as const from ..documents import MalformedDocumentError @@ -143,11 +143,7 @@ BMAEndpointType = TypeVar("BMAEndpointType", bound="BMAEndpoint") 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=constants.HOST_REGEX, - ipv4_regex=constants.IPV4_REGEX, - ipv6_regex=constants.IPV6_REGEX, - ) + f"^{API}(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))?(?: ([0-9]+))$" ) def __init__(self, server: str, ipv4: str, ipv6: str, port: int) -> None: @@ -240,12 +236,7 @@ SecuredBMAEndpointType = TypeVar("SecuredBMAEndpointType", bound="SecuredBMAEndp class SecuredBMAEndpoint(BMAEndpoint): API = "BMAS" re_inline = re.compile( - "^BMAS(?: ({host_regex}))?(?: ({ipv4_regex}))?(?: ({ipv6_regex}))? ([0-9]+)(?: ({path_regex}))?$".format( - host_regex=constants.HOST_REGEX, - ipv4_regex=constants.IPV4_REGEX, - ipv6_regex=constants.IPV6_REGEX, - path_regex=constants.PATH_REGEX, - ) + f"^{API}(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ([0-9]+)(?: ({const.PATH_REGEX}))?$" ) def __init__(self, server: str, ipv4: str, ipv6: str, port: int, path: str) -> None: @@ -326,13 +317,7 @@ WS2PEndpointType = TypeVar("WS2PEndpointType", bound="WS2PEndpoint") class WS2PEndpoint(Endpoint): API = "WS2P" re_inline = re.compile( - "^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, - ) + f"^{API} ({const.WS2PID_REGEX}) ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})|(?:{const.IPV6_REGEX})) ([0-9]+)?(?: ({const.PATH_REGEX}))?$" ) def __init__(self, ws2pid: str, server: str, port: int, path: str) -> None: @@ -413,9 +398,7 @@ 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=constants.HOST_REGEX, ipv4_regex=constants.IPV4_REGEX - ) + f"^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ([0-9]+)$" ) def __init__(self, server: str, port: int) -> None: @@ -474,9 +457,7 @@ 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=constants.HOST_REGEX, ipv4_regex=constants.IPV4_REGEX - ) + "^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ([0-9]+)$" ) def __init__(self, server: str, port: int) -> None: @@ -537,9 +518,7 @@ ESSubscribtionEndpointType = TypeVar( class ESSubscribtionEndpoint(Endpoint): API = "ES_SUBSCRIPTION_API" re_inline = re.compile( - "^ES_SUBSCRIPTION_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$".format( - host_regex=constants.HOST_REGEX, ipv4_regex=constants.IPV4_REGEX - ) + f"^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ([0-9]+)$" ) def __init__(self, server: str, port: int) -> None: @@ -599,7 +578,7 @@ GVAEndpointType = TypeVar("GVAEndpointType", bound="GVAEndpoint") class GVAEndpoint(Endpoint): API = "GVA" - endpoint_format = f"^GVA(?: ({constants.ENDPOINT_FLAGS_REGEX}))?(?: ({constants.HOST_REGEX}))?(?: ({constants.IPV4_REGEX}))?(?: ({constants.IPV6_REGEX}))? ([0-9]+)(?: ({constants.PATH_REGEX}))?$" + endpoint_format = f"^GVA(?: ({const.ENDPOINT_FLAGS_REGEX}))?(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ([0-9]+)(?: ({const.PATH_REGEX}))?$" re_inline = re.compile(endpoint_format) def __init__( @@ -728,7 +707,7 @@ GVASUBEndpointType = TypeVar("GVASUBEndpointType", bound="GVASUBEndpoint") class GVASUBEndpoint(GVAEndpoint): API = "GVASUB" - endpoint_format = f"^GVASUB(?: ({constants.ENDPOINT_FLAGS_REGEX}))?(?: ({constants.HOST_REGEX}))?(?: ({constants.IPV4_REGEX}))?(?: ({constants.IPV6_REGEX}))? ([0-9]+)(?: ({constants.PATH_REGEX}))?$" + endpoint_format = f"^GVASUB(?: ({const.ENDPOINT_FLAGS_REGEX}))?(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ([0-9]+)(?: ({const.PATH_REGEX}))?$" re_inline = re.compile(endpoint_format)