From 698a3598080ff814a97bccbf028d38c50ff3c996 Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Tue, 24 May 2022 05:47:05 +1000 Subject: [PATCH 1/2] Properly catch websocket CancelledError in websocket handler in Python 3.7 (cherry picked from commit 4ee2e57ec8474cf7c9a4f018de97926d8899f7cb) --- sanic/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index 97c7a177b2..309e6e1080 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -1004,10 +1004,10 @@ async def _websocket_handler( cancelled = False try: await fut - except Exception as e: - self.error_handler.log(request, e) except (CancelledError, ConnectionClosed): cancelled = True + except Exception as e: + self.error_handler.log(request, e) finally: self.websocket_tasks.remove(fut) if cancelled: From 162cb43c4bfc5438965d9055c27d8e51a909a092 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Thu, 30 Jun 2022 12:28:11 +0300 Subject: [PATCH 2/2] Run make pretty --- sanic/config.py | 2 +- sanic/headers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/config.py b/sanic/config.py index c5f05bf262..eefedbbb63 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -39,7 +39,7 @@ "REQUEST_TIMEOUT": 60, # 60 seconds "RESPONSE_TIMEOUT": 60, # 60 seconds "USE_UVLOOP": _default, - "WEBSOCKET_MAX_SIZE": 2 ** 20, # 1 megabyte + "WEBSOCKET_MAX_SIZE": 2**20, # 1 megabyte "WEBSOCKET_PING_INTERVAL": 20, "WEBSOCKET_PING_TIMEOUT": 20, } diff --git a/sanic/headers.py b/sanic/headers.py index b744974c6f..72d4a6e729 100644 --- a/sanic/headers.py +++ b/sanic/headers.py @@ -18,7 +18,7 @@ OptionsIterable = Iterable[Tuple[str, str]] # May contain duplicate keys _token, _quoted = r"([\w!#$%&'*+\-.^_`|~]+)", r'"([^"]*)"' -_param = re.compile(fr";\s*{_token}=(?:{_token}|{_quoted})", re.ASCII) +_param = re.compile(rf";\s*{_token}=(?:{_token}|{_quoted})", re.ASCII) _firefox_quote_escape = re.compile(r'\\"(?!; |\s*$)') _ipv6 = "(?:[0-9A-Fa-f]{0,4}:){2,7}[0-9A-Fa-f]{0,4}" _ipv6_re = re.compile(_ipv6)