Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f613818263 | ||
|
|
36ea283b42 | ||
|
|
a7766de797 | ||
|
|
b67e31efe8 | ||
|
|
7ac4933386 |
@@ -22,6 +22,7 @@ span.linenos.special { color: #000000; background-color: #ffffc0; padding-left:
|
||||
.cs { color: #a2a2a2; font-style: italic } /* Comment.Special */
|
||||
.gd { color: #777777 } /* Generic.Deleted */
|
||||
.ge { color: #777777 } /* Generic.Emph */
|
||||
.ges { color: #777777 } /* Generic.EmphStrong */
|
||||
.gr { color: #777777 } /* Generic.Error */
|
||||
.gh { color: #777777 } /* Generic.Heading */
|
||||
.gi { color: #777777 } /* Generic.Inserted */
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
sanic>=23.6.*
|
||||
sanic-ext>=23.6.*
|
||||
msgspec
|
||||
python-frontmatter
|
||||
pygments
|
||||
docstring-parser
|
||||
libsass
|
||||
mistune
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
"""Sanic User Guide
|
||||
|
||||
https://sanic.dev
|
||||
|
||||
Built using the SHH stack:
|
||||
- Sanic
|
||||
- html5tagger
|
||||
- HTMX"""
|
||||
from pathlib import Path
|
||||
|
||||
from webapp.worker.factory import create_app
|
||||
|
||||
@@ -3,7 +3,6 @@ from __future__ import annotations
|
||||
import os
|
||||
import ssl
|
||||
|
||||
from pathlib import Path, PurePath
|
||||
from typing import Any, Dict, Iterable, Optional, Union
|
||||
|
||||
from sanic.log import logger
|
||||
@@ -40,23 +39,23 @@ def create_context(
|
||||
|
||||
|
||||
def shorthand_to_ctx(
|
||||
ctxdef: Union[None, ssl.SSLContext, dict, PurePath, str]
|
||||
ctxdef: Union[None, ssl.SSLContext, dict, str]
|
||||
) -> Optional[ssl.SSLContext]:
|
||||
"""Convert an ssl argument shorthand to an SSLContext object."""
|
||||
if ctxdef is None or isinstance(ctxdef, ssl.SSLContext):
|
||||
return ctxdef
|
||||
if isinstance(ctxdef, (PurePath, str)):
|
||||
return load_cert_dir(Path(ctxdef))
|
||||
if isinstance(ctxdef, str):
|
||||
return load_cert_dir(ctxdef)
|
||||
if isinstance(ctxdef, dict):
|
||||
return CertSimple(**ctxdef)
|
||||
raise ValueError(
|
||||
f"Invalid ssl argument {type(ctxdef)}."
|
||||
" Expecting one/list of: certdir | dict | SSLContext"
|
||||
" Expecting a list of certdirs, a dict or an SSLContext."
|
||||
)
|
||||
|
||||
|
||||
def process_to_context(
|
||||
ssldef: Union[None, ssl.SSLContext, dict, PurePath, str, list, tuple]
|
||||
ssldef: Union[None, ssl.SSLContext, dict, str, list, tuple]
|
||||
) -> Optional[ssl.SSLContext]:
|
||||
"""Process app.run ssl argument from easy formats to full SSLContext."""
|
||||
return (
|
||||
@@ -66,11 +65,11 @@ def process_to_context(
|
||||
)
|
||||
|
||||
|
||||
def load_cert_dir(p: Path) -> ssl.SSLContext:
|
||||
if p.is_file():
|
||||
def load_cert_dir(p: str) -> ssl.SSLContext:
|
||||
if os.path.isfile(p):
|
||||
raise ValueError(f"Certificate folder expected but {p} is a file.")
|
||||
keyfile = p / "privkey.pem"
|
||||
certfile = p / "fullchain.pem"
|
||||
keyfile = os.path.join(p, "privkey.pem")
|
||||
certfile = os.path.join(p, "fullchain.pem")
|
||||
if not os.access(keyfile, os.R_OK):
|
||||
raise ValueError(
|
||||
f"Certificate not found or permission denied {keyfile}"
|
||||
|
||||
@@ -20,7 +20,6 @@ from pytest import LogCaptureFixture
|
||||
|
||||
from sanic import Request, Sanic
|
||||
from sanic.compat import Header
|
||||
from sanic.constants import DEFAULT_HTTP_CONTENT_TYPE
|
||||
from sanic.cookies import CookieJar
|
||||
from sanic.response import (
|
||||
HTTPResponse,
|
||||
@@ -546,7 +545,7 @@ def test_raw_response(app):
|
||||
return raw(b"raw_response")
|
||||
|
||||
request, response = app.test_client.get("/test")
|
||||
assert response.content_type == DEFAULT_HTTP_CONTENT_TYPE
|
||||
assert response.content_type == "application/octet-stream"
|
||||
assert response.body == b"raw_response"
|
||||
|
||||
|
||||
|
||||
@@ -502,7 +502,7 @@ def test_dynamic_route_int(app):
|
||||
|
||||
request, response = app.test_client.get("/folder/12345")
|
||||
assert response.text == "OK"
|
||||
assert isinstance(results[0], int)
|
||||
assert type(results[0]) is int
|
||||
|
||||
request, response = app.test_client.get("/folder/asdf")
|
||||
assert response.status == 404
|
||||
@@ -518,7 +518,7 @@ def test_dynamic_route_number(app):
|
||||
|
||||
request, response = app.test_client.get("/weight/12345")
|
||||
assert response.text == "OK"
|
||||
assert isinstance(results[0], float)
|
||||
assert type(results[0]) is float
|
||||
|
||||
request, response = app.test_client.get("/weight/1234.56")
|
||||
assert response.status == 200
|
||||
@@ -567,7 +567,7 @@ def test_dynamic_route_uuid(app):
|
||||
url = "/quirky/123e4567-e89b-12d3-a456-426655440000"
|
||||
request, response = app.test_client.get(url)
|
||||
assert response.text == "OK"
|
||||
assert isinstance(results[0], uuid.UUID)
|
||||
assert type(results[0]) is uuid.UUID
|
||||
|
||||
generated_uuid = uuid.uuid4()
|
||||
request, response = app.test_client.get(f"/quirky/{generated_uuid}")
|
||||
@@ -861,7 +861,7 @@ def test_dynamic_add_route_int(app):
|
||||
|
||||
request, response = app.test_client.get("/folder/12345")
|
||||
assert response.text == "OK"
|
||||
assert isinstance(results[0], int)
|
||||
assert type(results[0]) is int
|
||||
|
||||
request, response = app.test_client.get("/folder/asdf")
|
||||
assert response.status == 404
|
||||
@@ -878,7 +878,7 @@ def test_dynamic_add_route_number(app):
|
||||
|
||||
request, response = app.test_client.get("/weight/12345")
|
||||
assert response.text == "OK"
|
||||
assert isinstance(results[0], float)
|
||||
assert type(results[0]) is float
|
||||
|
||||
request, response = app.test_client.get("/weight/1234.56")
|
||||
assert response.status == 200
|
||||
|
||||
Reference in New Issue
Block a user