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