Skip to content
Snippets Groups Projects
Commit 870ce715 authored by Moul's avatar Moul
Browse files

[enh] #170: Define and use precise port regex

parent 75be8089
No related branches found
No related tags found
2 merge requests!157v1.0.0rc0: merge dev into master,!145#170: Endpoints' regex improvement
...@@ -143,7 +143,7 @@ BMAEndpointType = TypeVar("BMAEndpointType", bound="BMAEndpoint") ...@@ -143,7 +143,7 @@ BMAEndpointType = TypeVar("BMAEndpointType", bound="BMAEndpoint")
class BMAEndpoint(Endpoint): class BMAEndpoint(Endpoint):
API = "BASIC_MERKLED_API" API = "BASIC_MERKLED_API"
re_inline = re.compile( re_inline = re.compile(
f"^{API}(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))?(?: ([0-9]+))$" f"^{API}(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))?(?: ({const.PORT_REGEX}))$"
) )
def __init__(self, server: str, ipv4: str, ipv6: str, port: int) -> None: def __init__(self, server: str, ipv4: str, ipv6: str, port: int) -> None:
...@@ -236,7 +236,7 @@ SecuredBMAEndpointType = TypeVar("SecuredBMAEndpointType", bound="SecuredBMAEndp ...@@ -236,7 +236,7 @@ SecuredBMAEndpointType = TypeVar("SecuredBMAEndpointType", bound="SecuredBMAEndp
class SecuredBMAEndpoint(BMAEndpoint): class SecuredBMAEndpoint(BMAEndpoint):
API = "BMAS" API = "BMAS"
re_inline = re.compile( re_inline = re.compile(
f"^{API}(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ([0-9]+)(?: ({const.PATH_REGEX}))?$" f"^{API}(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ({const.PORT_REGEX})(?: ({const.PATH_REGEX}))?$"
) )
def __init__(self, server: str, ipv4: str, ipv6: str, port: int, path: str) -> None: def __init__(self, server: str, ipv4: str, ipv6: str, port: int, path: str) -> None:
...@@ -317,7 +317,7 @@ WS2PEndpointType = TypeVar("WS2PEndpointType", bound="WS2PEndpoint") ...@@ -317,7 +317,7 @@ WS2PEndpointType = TypeVar("WS2PEndpointType", bound="WS2PEndpoint")
class WS2PEndpoint(Endpoint): class WS2PEndpoint(Endpoint):
API = "WS2P" API = "WS2P"
re_inline = re.compile( re_inline = re.compile(
f"^{API} ({const.WS2PID_REGEX}) ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})|(?:{const.IPV6_REGEX})) ([0-9]+)?(?: ({const.PATH_REGEX}))?$" f"^{API} ({const.WS2PID_REGEX}) ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})|(?:{const.IPV6_REGEX})) ({const.PORT_REGEX})?(?: ({const.PATH_REGEX}))?$"
) )
def __init__(self, ws2pid: str, server: str, port: int, path: str) -> None: def __init__(self, ws2pid: str, server: str, port: int, path: str) -> None:
...@@ -398,7 +398,7 @@ ESCoreEndpointType = TypeVar("ESCoreEndpointType", bound="ESCoreEndpoint") ...@@ -398,7 +398,7 @@ ESCoreEndpointType = TypeVar("ESCoreEndpointType", bound="ESCoreEndpoint")
class ESCoreEndpoint(Endpoint): class ESCoreEndpoint(Endpoint):
API = "ES_CORE_API" API = "ES_CORE_API"
re_inline = re.compile( re_inline = re.compile(
f"^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ([0-9]+)$" f"^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ({const.PORT_REGEX})$"
) )
def __init__(self, server: str, port: int) -> None: def __init__(self, server: str, port: int) -> None:
...@@ -457,7 +457,7 @@ ESUserEndpointType = TypeVar("ESUserEndpointType", bound="ESUserEndpoint") ...@@ -457,7 +457,7 @@ ESUserEndpointType = TypeVar("ESUserEndpointType", bound="ESUserEndpoint")
class ESUserEndpoint(Endpoint): class ESUserEndpoint(Endpoint):
API = "ES_USER_API" API = "ES_USER_API"
re_inline = re.compile( re_inline = re.compile(
"^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ([0-9]+)$" "^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ({const.PORT_REGEX})$"
) )
def __init__(self, server: str, port: int) -> None: def __init__(self, server: str, port: int) -> None:
...@@ -518,7 +518,7 @@ ESSubscribtionEndpointType = TypeVar( ...@@ -518,7 +518,7 @@ ESSubscribtionEndpointType = TypeVar(
class ESSubscribtionEndpoint(Endpoint): class ESSubscribtionEndpoint(Endpoint):
API = "ES_SUBSCRIPTION_API" API = "ES_SUBSCRIPTION_API"
re_inline = re.compile( re_inline = re.compile(
f"^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ([0-9]+)$" f"^{API} ((?:{const.HOST_REGEX})|(?:{const.IPV4_REGEX})) ({const.PORT_REGEX})$"
) )
def __init__(self, server: str, port: int) -> None: def __init__(self, server: str, port: int) -> None:
...@@ -578,7 +578,7 @@ GVAEndpointType = TypeVar("GVAEndpointType", bound="GVAEndpoint") ...@@ -578,7 +578,7 @@ GVAEndpointType = TypeVar("GVAEndpointType", bound="GVAEndpoint")
class GVAEndpoint(Endpoint): class GVAEndpoint(Endpoint):
API = "GVA" API = "GVA"
endpoint_format = f"^GVA(?: ({const.ENDPOINT_FLAGS_REGEX}))?(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ([0-9]+)(?: ({const.PATH_REGEX}))?$" endpoint_format = f"^GVA(?: ({const.ENDPOINT_FLAGS_REGEX}))?(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ({const.PORT_REGEX})(?: ({const.PATH_REGEX}))?$"
re_inline = re.compile(endpoint_format) re_inline = re.compile(endpoint_format)
def __init__( def __init__(
...@@ -707,7 +707,7 @@ GVASUBEndpointType = TypeVar("GVASUBEndpointType", bound="GVASUBEndpoint") ...@@ -707,7 +707,7 @@ GVASUBEndpointType = TypeVar("GVASUBEndpointType", bound="GVASUBEndpoint")
class GVASUBEndpoint(GVAEndpoint): class GVASUBEndpoint(GVAEndpoint):
API = "GVASUB" API = "GVASUB"
endpoint_format = f"^GVASUB(?: ({const.ENDPOINT_FLAGS_REGEX}))?(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ([0-9]+)(?: ({const.PATH_REGEX}))?$" endpoint_format = f"^GVASUB(?: ({const.ENDPOINT_FLAGS_REGEX}))?(?: ({const.HOST_REGEX}))?(?: ({const.IPV4_REGEX}))?(?: ({const.IPV6_REGEX}))? ({const.PORT_REGEX})(?: ({const.PATH_REGEX}))?$"
re_inline = re.compile(endpoint_format) re_inline = re.compile(endpoint_format)
......
...@@ -51,6 +51,10 @@ IPV6_REGEX = ( ...@@ -51,6 +51,10 @@ IPV6_REGEX = (
"4}:){,6}[0-9A-Fa-f]{1,4})?::)(?:%.+)?" "4}:){,6}[0-9A-Fa-f]{1,4})?::)(?:%.+)?"
) )
HOST_REGEX = "[a-z0-9-_.]*(?:.[a-zA-Z])?" HOST_REGEX = "[a-z0-9-_.]*(?:.[a-zA-Z])?"
# https://stackoverflow.com/a/12968117
PORT_REGEX = (
"[1-9]\\d{0,3}|0|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]"
)
PATH_REGEX = "[/\\w \\.-]*/?" PATH_REGEX = "[/\\w \\.-]*/?"
WS2PID_REGEX = "[0-9a-f]{8}" WS2PID_REGEX = "[0-9a-f]{8}"
WS2P_PRIVATE_PREFIX_REGEX = "O[CT][SAM]" WS2P_PRIVATE_PREFIX_REGEX = "O[CT][SAM]"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment