Skip to content
Snippets Groups Projects
Commit 6bbbc620 authored by Moul's avatar Moul
Browse files

[mod] #146, #170: Define endpoints regex with f-string

Import constants as const
parent f8b9b80f
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment