Compare commits
	
		
			1 Commits
		
	
	
		
			bind_excep
			...
			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 | ||||
|   | ||||
| @@ -49,7 +49,7 @@ from sanic.application.motd import MOTD | ||||
| from sanic.application.state import ApplicationServerInfo, Mode, ServerStage | ||||
| from sanic.base.meta import SanicMeta | ||||
| from sanic.compat import OS_IS_WINDOWS, StartMethod | ||||
| from sanic.exceptions import SanicException, ServerKilled | ||||
| from sanic.exceptions import ServerKilled | ||||
| from sanic.helpers import Default, _default, is_atty | ||||
| from sanic.http.constants import HTTP | ||||
| from sanic.http.tls import get_ssl_context, process_to_context | ||||
| @@ -880,18 +880,12 @@ class StartupMixin(metaclass=SanicMeta): | ||||
|             manager.run() | ||||
|         except ServerKilled: | ||||
|             exit_code = 1 | ||||
|         except SanicException as e: | ||||
|             exit_code = 1 | ||||
|             kwargs = primary_server_info.settings | ||||
|             if e.quiet: | ||||
|                 error_logger.error(str(e)) | ||||
|             else: | ||||
|                 raise | ||||
|         except BaseException: | ||||
|             kwargs = primary_server_info.settings | ||||
|             error_logger.exception( | ||||
|                 "Experienced exception while trying to serve" | ||||
|             ) | ||||
|             raise | ||||
|         finally: | ||||
|             logger.info("Server Stopped") | ||||
|             for app in apps: | ||||
|   | ||||
| @@ -47,10 +47,10 @@ def bind_unix_socket(path: str, *, mode=0o666, backlog=100) -> socket.socket: | ||||
|     path = os.path.abspath(path) | ||||
|     folder = os.path.dirname(path) | ||||
|     if not os.path.isdir(folder): | ||||
|         raise FileNotFoundError("Socket folder does not exist") | ||||
|         raise FileNotFoundError(f"Socket folder does not exist: {folder}") | ||||
|     try: | ||||
|         if not stat.S_ISSOCK(os.stat(path, follow_symlinks=False).st_mode): | ||||
|             raise FileExistsError("Existing file is not a socket") | ||||
|             raise FileExistsError(f"Existing file is not a socket: {path}") | ||||
|     except FileNotFoundError: | ||||
|         pass | ||||
|     # Create new socket with a random temporary name | ||||
| @@ -103,10 +103,7 @@ def configure_socket( | ||||
|     unix = server_settings["unix"] | ||||
|     backlog = server_settings["backlog"] | ||||
|     if unix: | ||||
|         try: | ||||
|             sock = bind_unix_socket(unix, backlog=backlog) | ||||
|         except OSError as e: | ||||
|             raise ServerError(f"Error binding {unix}: {e}", quiet=True) | ||||
|         sock = bind_unix_socket(unix, backlog=backlog) | ||||
|         server_settings["unix"] = unix | ||||
|     if sock is None: | ||||
|         try: | ||||
| @@ -115,17 +112,6 @@ def configure_socket( | ||||
|                 server_settings["port"], | ||||
|                 backlog=backlog, | ||||
|             ) | ||||
|         except PermissionError: | ||||
|             p = server_settings["port"] | ||||
|             if not p or p >= 1024: | ||||
|                 raise | ||||
|             addr = f"{server_settings['host']}:{p}" | ||||
|             error = ServerError( | ||||
|                 f"Permission denied binding to {addr}.\n\n" | ||||
|                 "Use `sudo sanic` to run on a privileged port.\n" | ||||
|             ) | ||||
|             error.quiet = True | ||||
|             raise error | ||||
|         except OSError as e:  # no cov | ||||
|             error = ServerError( | ||||
|                 f"Sanic server could not start: {e}.\n\n" | ||||
|   | ||||
| @@ -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