re-organize top-level imports
This commit is contained in:
parent
f5fb378b0a
commit
4eea3a496c
|
@ -1,19 +1,28 @@
|
|||
__version__ = "0.1.0"
|
||||
|
||||
|
||||
from .application import Application, ExceptionType, ExceptionCallback
|
||||
from .enums import HttpStatus
|
||||
from .application import Application, StaticHandler
|
||||
from .enums import HttpStatus, SassOutputStyle
|
||||
from .error import HttpError
|
||||
from .misc import Color, StateProxy, Stream
|
||||
from .request import Request
|
||||
from .response import Response, FileResponse, TemplateResponse
|
||||
from .runner import run_app
|
||||
from .signal import Signal, SignalCallback
|
||||
from .template import Template
|
||||
from .runner import run_app, handle_run_server
|
||||
from .signal import Signal
|
||||
from .template import FsLoader, SassExtension, Template
|
||||
|
||||
from .misc import (
|
||||
Color,
|
||||
StateProxy,
|
||||
Stream,
|
||||
convert_to_bytes,
|
||||
convert_to_string,
|
||||
is_loop_running
|
||||
)
|
||||
|
||||
from .router import (
|
||||
Router,
|
||||
get_router,
|
||||
set_router,
|
||||
route,
|
||||
connect,
|
||||
delete,
|
||||
|
@ -25,3 +34,13 @@ from .router import (
|
|||
put,
|
||||
trace
|
||||
)
|
||||
|
||||
|
||||
# types
|
||||
from .application import ExceptionType, ExceptionCallback
|
||||
from .misc import ReaderFunction, WriterFunction
|
||||
from .request import AsgiVersionType, ScopeType
|
||||
from .router import RouteHandler
|
||||
from .runner import BackgroundTask
|
||||
from .signal import SignalCallback
|
||||
from .template import TemplateContextCallback
|
||||
|
|
|
@ -15,7 +15,7 @@ from .request import Request, ScopeType
|
|||
from .response import FileResponse, Response
|
||||
from .router import Router, RouteHandler, get_router
|
||||
from .signal import Signal
|
||||
from .template import Template, TemplateContextType
|
||||
from .template import Template, TemplateContextCallback
|
||||
|
||||
|
||||
ExceptionType = TypeVar("ExceptionType", bound = Exception)
|
||||
|
@ -29,7 +29,7 @@ class Application:
|
|||
name: str,
|
||||
template_search: list[Path | str] | None = None,
|
||||
template_env: dict[str, Any] | None = None,
|
||||
template_context: TemplateContextType | None = None,
|
||||
template_context: TemplateContextCallback | None = None,
|
||||
request_class: type[Request] = Request,
|
||||
request_state_class: type[StateProxy] = StateProxy,
|
||||
app_state_class: type[StateProxy] = StateProxy) -> None:
|
||||
|
|
|
@ -23,73 +23,6 @@ ReaderFunction = Callable[..., Awaitable[dict[str, Any]]]
|
|||
WriterFunction = Callable[[dict[str, Any]], Awaitable[None]]
|
||||
|
||||
|
||||
HTTP_STATUS = {
|
||||
100: "Continue",
|
||||
101: "Switching Protocols",
|
||||
102: "Processing",
|
||||
200: "OK",
|
||||
201: "Created",
|
||||
202: "Accepted",
|
||||
203: "Non-authritative Information",
|
||||
204: "No Content",
|
||||
205: "Reset Content",
|
||||
206: "Partial Content",
|
||||
207: "Multi-Status",
|
||||
208: "Already Reported",
|
||||
226: "IM Used",
|
||||
300: "Multiple Choices",
|
||||
301: "Moved Permanently",
|
||||
302: "Found",
|
||||
303: "See Other",
|
||||
304: "Not Modified",
|
||||
305: "Use Proxy",
|
||||
307: "Temporary Redirect",
|
||||
308: "Permanent Redirect",
|
||||
400: "Bad Request",
|
||||
401: "Unauthorized",
|
||||
402: "Payment Required",
|
||||
403: "Forbidden",
|
||||
404: "Not Found",
|
||||
405: "Method Not Allowed",
|
||||
406: "Not Acceptable",
|
||||
407: "Proxy Authentication Required",
|
||||
408: "Request Timeout",
|
||||
409: "Conflict",
|
||||
410: "Gone",
|
||||
411: "Length Required",
|
||||
412: "Precondition Failed",
|
||||
413: "Payload Too Large",
|
||||
414: "Request-URI Too Long",
|
||||
415: "Unsupported Media Type",
|
||||
416: "Requested Range Not Satisfiable",
|
||||
417: "Expectation Failed",
|
||||
418: "I'm A Teapot",
|
||||
421: "Misdirected Request",
|
||||
422: "Unprocessable Entity",
|
||||
423: "Locked",
|
||||
424: "Failed Dependency",
|
||||
426: "Upgrade Required",
|
||||
428: "Precondition Required",
|
||||
429: "Too Many Requests",
|
||||
431: "Request Header Fields Too Large",
|
||||
444: "Connection Closed Without Response",
|
||||
451: "Unavailable For Legal Reasons",
|
||||
499: "Client Closed Request",
|
||||
500: "Internal Server Error",
|
||||
501: "Not Implemented",
|
||||
502: "Bad Gateway",
|
||||
503: "Service Unavailable",
|
||||
504: "Gateway Timeout",
|
||||
505: "HTTP Version Not Supported",
|
||||
506: "Variant Also Negotiates",
|
||||
507: "Insufficient Storage",
|
||||
508: "Loop Detected",
|
||||
510: "Not Extended",
|
||||
511: "Network Authentication Required",
|
||||
599: "Network Connect Timeout Error"
|
||||
}
|
||||
|
||||
|
||||
PRIDE_COLORS = {
|
||||
"lgbt": ["#9400D3", "#4B0082", "#0000FF", "#00FF00", "#FFFF00", "#FF7F00", "#FF0000"],
|
||||
"lesbian": ["#D52D00", "#EF7627", "#FF9A56", "#FFFFFF", "#D162A4", "#B55690", "#A30262"],
|
||||
|
|
|
@ -17,7 +17,7 @@ from .enums import SassOutputStyle
|
|||
from .misc import Color
|
||||
|
||||
|
||||
TemplateContextType = Callable[[Environment, dict[str, Any]], dict[str, Any]]
|
||||
TemplateContextCallback = Callable[[Environment, dict[str, Any]], dict[str, Any]]
|
||||
|
||||
|
||||
# jinja's annotation for the `searchpath` property was weird, so this fixes it
|
||||
|
@ -89,7 +89,7 @@ class SassExtension(Extension):
|
|||
class Template(Environment):
|
||||
def __init__(self,
|
||||
*search: str | Path,
|
||||
context_function: TemplateContextType | None = None,
|
||||
context_function: TemplateContextCallback | None = None,
|
||||
**global_env: Any):
|
||||
|
||||
self.search: FsLoader = FsLoader([])
|
||||
|
@ -108,7 +108,7 @@ class Template(Environment):
|
|||
self.add_search_path(path)
|
||||
|
||||
self.autoescape: bool = True
|
||||
self.context_function: TemplateContextType | None = None
|
||||
self.context_function: TemplateContextCallback | None = None
|
||||
|
||||
if context_function:
|
||||
self.set_context_function(context_function)
|
||||
|
@ -141,7 +141,7 @@ class Template(Environment):
|
|||
self.search.searchpath.insert(index, str(path))
|
||||
|
||||
|
||||
def set_context_function(self, context: TemplateContextType) -> TemplateContextType:
|
||||
def set_context_function(self, context: TemplateContextCallback) -> TemplateContextCallback:
|
||||
if not hasattr(context, "__call__"):
|
||||
raise TypeError("Context is not callable")
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ requires-python = ">= 3.11"
|
|||
dependencies = [
|
||||
"activitypub-utils == 0.2.3",
|
||||
"barkshark-sql == 0.1.3",
|
||||
"gemi-python == 0.1.1",
|
||||
"http-router == 4.1.2",
|
||||
"httpx[http2] == 0.27.0",
|
||||
"jinja2-haml == 0.3.5",
|
||||
|
|
Loading…
Reference in a new issue