Compare commits
2 Commits
simple-sig
...
motd_addre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0489dd9aaf | ||
|
|
47215d4635 |
7
.github/workflows/tests.yml
vendored
7
.github/workflows/tests.yml
vendored
@@ -1,6 +1,13 @@
|
|||||||
name: Tests
|
name: Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- current-release
|
||||||
|
- "*LTS"
|
||||||
|
tags:
|
||||||
|
- "!*"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|||||||
@@ -657,10 +657,9 @@ class StartupMixin(metaclass=SanicMeta):
|
|||||||
def get_server_location(
|
def get_server_location(
|
||||||
server_settings: Optional[Dict[str, Any]] = None
|
server_settings: Optional[Dict[str, Any]] = None
|
||||||
) -> str:
|
) -> str:
|
||||||
serve_location = ""
|
|
||||||
proto = "http"
|
proto = "http"
|
||||||
if not server_settings:
|
if not server_settings:
|
||||||
return serve_location
|
return ""
|
||||||
|
|
||||||
host = server_settings["host"]
|
host = server_settings["host"]
|
||||||
port = server_settings["port"]
|
port = server_settings["port"]
|
||||||
@@ -668,16 +667,33 @@ class StartupMixin(metaclass=SanicMeta):
|
|||||||
if server_settings.get("ssl") is not None:
|
if server_settings.get("ssl") is not None:
|
||||||
proto = "https"
|
proto = "https"
|
||||||
if server_settings.get("unix"):
|
if server_settings.get("unix"):
|
||||||
serve_location = f'{server_settings["unix"]} {proto}://...'
|
return f'{server_settings["unix"]} {proto}://localhost'
|
||||||
elif server_settings.get("sock"):
|
if server_settings.get("sock"):
|
||||||
host, port, *_ = server_settings["sock"].getsockname()
|
host, port, *_ = server_settings["sock"].getsockname()
|
||||||
|
if not host or not port:
|
||||||
|
return ""
|
||||||
|
|
||||||
if not serve_location and host and port:
|
# colon(:) is legal for a host only in an ipv6 address
|
||||||
# colon(:) is legal for a host only in an ipv6 address
|
url_host = f"[{host}]" if ":" in host else host
|
||||||
display_host = f"[{host}]" if ":" in host else host
|
url_port = (
|
||||||
serve_location = f"{proto}://{display_host}:{port}"
|
""
|
||||||
|
if (
|
||||||
|
(proto == "https" and port == 443)
|
||||||
|
or (proto == "http" and port == 80)
|
||||||
|
)
|
||||||
|
else f":{port}"
|
||||||
|
)
|
||||||
|
|
||||||
return serve_location
|
special = {
|
||||||
|
"127.0.0.1": "IPv4",
|
||||||
|
"0.0.0.0": "IPv4 wildcard",
|
||||||
|
"::1": "IPv6",
|
||||||
|
"::": "IPv6 wildcard",
|
||||||
|
}.get(host, "")
|
||||||
|
if special:
|
||||||
|
return f"({special}) {proto}://localhost{url_port}"
|
||||||
|
|
||||||
|
return f"{proto}://{url_host}{url_port}"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_address(
|
def get_address(
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ class Event(Enum):
|
|||||||
|
|
||||||
|
|
||||||
RESERVED_NAMESPACES = {
|
RESERVED_NAMESPACES = {
|
||||||
"sanic": ("sanic.__signal__.__init__",),
|
|
||||||
"server": (
|
"server": (
|
||||||
Event.SERVER_EXCEPTION_REPORT.value,
|
Event.SERVER_EXCEPTION_REPORT.value,
|
||||||
Event.SERVER_INIT_AFTER.value,
|
Event.SERVER_INIT_AFTER.value,
|
||||||
@@ -66,8 +65,6 @@ RESERVED_NAMESPACES = {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
GENERIC_SIGNAL_FORMAT = "__generic__.__signal__.%s"
|
|
||||||
|
|
||||||
|
|
||||||
def _blank():
|
def _blank():
|
||||||
...
|
...
|
||||||
@@ -92,26 +89,11 @@ class SignalRouter(BaseRouter):
|
|||||||
self.allow_fail_builtin = True
|
self.allow_fail_builtin = True
|
||||||
self.ctx.loop = None
|
self.ctx.loop = None
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def format_event(event: str) -> str:
|
|
||||||
"""Ensure event strings in proper format
|
|
||||||
|
|
||||||
Args:
|
|
||||||
event (str): event string
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: formatted event string
|
|
||||||
"""
|
|
||||||
if "." not in event:
|
|
||||||
event = GENERIC_SIGNAL_FORMAT % event
|
|
||||||
return event
|
|
||||||
|
|
||||||
def get( # type: ignore
|
def get( # type: ignore
|
||||||
self,
|
self,
|
||||||
event: str,
|
event: str,
|
||||||
condition: Optional[Dict[str, str]] = None,
|
condition: Optional[Dict[str, str]] = None,
|
||||||
):
|
):
|
||||||
event = self.format_event(event)
|
|
||||||
extra = condition or {}
|
extra = condition or {}
|
||||||
try:
|
try:
|
||||||
group, param_basket = self.find_route(
|
group, param_basket = self.find_route(
|
||||||
@@ -151,7 +133,6 @@ class SignalRouter(BaseRouter):
|
|||||||
fail_not_found: bool = True,
|
fail_not_found: bool = True,
|
||||||
reverse: bool = False,
|
reverse: bool = False,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
event = self.format_event(event)
|
|
||||||
try:
|
try:
|
||||||
group, handlers, params = self.get(event, condition=condition)
|
group, handlers, params = self.get(event, condition=condition)
|
||||||
except NotFound as e:
|
except NotFound as e:
|
||||||
@@ -214,7 +195,6 @@ class SignalRouter(BaseRouter):
|
|||||||
inline: bool = False,
|
inline: bool = False,
|
||||||
reverse: bool = False,
|
reverse: bool = False,
|
||||||
) -> Union[asyncio.Task, Any]:
|
) -> Union[asyncio.Task, Any]:
|
||||||
event = self.format_event(event)
|
|
||||||
dispatch = self._dispatch(
|
dispatch = self._dispatch(
|
||||||
event,
|
event,
|
||||||
context=context,
|
context=context,
|
||||||
@@ -238,7 +218,6 @@ class SignalRouter(BaseRouter):
|
|||||||
condition: Optional[Dict[str, Any]] = None,
|
condition: Optional[Dict[str, Any]] = None,
|
||||||
exclusive: bool = True,
|
exclusive: bool = True,
|
||||||
) -> Signal:
|
) -> Signal:
|
||||||
event = self.format_event(event)
|
|
||||||
event_definition = event
|
event_definition = event
|
||||||
parts = self._build_event_parts(event)
|
parts = self._build_event_parts(event)
|
||||||
if parts[2].startswith("<"):
|
if parts[2].startswith("<"):
|
||||||
|
|||||||
Reference in New Issue
Block a user