mirror of
https://github.com/Kozea/Radicale.git
synced 2025-09-15 20:36:55 +00:00
More type hints
This commit is contained in:
parent
11f7559ef3
commit
c93d7b8715
51 changed files with 1374 additions and 957 deletions
|
@ -21,18 +21,24 @@ Take a look at the class ``BaseWeb`` if you want to implement your own.
|
|||
|
||||
"""
|
||||
|
||||
from radicale import httputils, utils
|
||||
from typing import Sequence
|
||||
|
||||
INTERNAL_TYPES = ("none", "internal")
|
||||
from radicale import config, httputils, types, utils
|
||||
|
||||
INTERNAL_TYPES: Sequence[str] = ("none", "internal")
|
||||
|
||||
|
||||
def load(configuration):
|
||||
def load(configuration: "config.Configuration") -> "BaseWeb":
|
||||
"""Load the web module chosen in configuration."""
|
||||
return utils.load_plugin(INTERNAL_TYPES, "web", "Web", configuration)
|
||||
return utils.load_plugin(INTERNAL_TYPES, "web", "Web", BaseWeb,
|
||||
configuration)
|
||||
|
||||
|
||||
class BaseWeb:
|
||||
def __init__(self, configuration):
|
||||
|
||||
configuration: "config.Configuration"
|
||||
|
||||
def __init__(self, configuration: "config.Configuration") -> None:
|
||||
"""Initialize BaseWeb.
|
||||
|
||||
``configuration`` see ``radicale.config`` module.
|
||||
|
@ -42,7 +48,8 @@ class BaseWeb:
|
|||
"""
|
||||
self.configuration = configuration
|
||||
|
||||
def get(self, environ, base_prefix, path, user):
|
||||
def get(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
||||
user: str) -> types.WSGIResponse:
|
||||
"""GET request.
|
||||
|
||||
``base_prefix`` is sanitized and never ends with "/".
|
||||
|
@ -54,7 +61,8 @@ class BaseWeb:
|
|||
"""
|
||||
return httputils.METHOD_NOT_ALLOWED
|
||||
|
||||
def post(self, environ, base_prefix, path, user):
|
||||
def post(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
||||
user: str) -> types.WSGIResponse:
|
||||
"""POST request.
|
||||
|
||||
``base_prefix`` is sanitized and never ends with "/".
|
||||
|
|
|
@ -30,13 +30,14 @@ import os
|
|||
import posixpath
|
||||
import time
|
||||
from http import client
|
||||
from typing import Mapping
|
||||
|
||||
import pkg_resources
|
||||
|
||||
from radicale import httputils, pathutils, web
|
||||
from radicale import config, httputils, pathutils, types, web
|
||||
from radicale.log import logger
|
||||
|
||||
MIMETYPES = {
|
||||
MIMETYPES: Mapping[str, str] = {
|
||||
".css": "text/css",
|
||||
".eot": "application/vnd.ms-fontobject",
|
||||
".gif": "image/gif",
|
||||
|
@ -50,16 +51,20 @@ MIMETYPES = {
|
|||
".woff": "application/font-woff",
|
||||
".woff2": "font/woff2",
|
||||
".xml": "text/xml"}
|
||||
FALLBACK_MIMETYPE = "application/octet-stream"
|
||||
FALLBACK_MIMETYPE: str = "application/octet-stream"
|
||||
|
||||
|
||||
class Web(web.BaseWeb):
|
||||
def __init__(self, configuration):
|
||||
|
||||
folder: str
|
||||
|
||||
def __init__(self, configuration: config.Configuration) -> None:
|
||||
super().__init__(configuration)
|
||||
self.folder = pkg_resources.resource_filename(__name__,
|
||||
"internal_data")
|
||||
|
||||
def get(self, environ, base_prefix, path, user):
|
||||
def get(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
||||
user: str) -> types.WSGIResponse:
|
||||
assert path == "/.web" or path.startswith("/.web/")
|
||||
assert pathutils.sanitize_path(path) == path
|
||||
try:
|
||||
|
|
|
@ -21,11 +21,13 @@ A dummy web backend that shows a simple message.
|
|||
|
||||
from http import client
|
||||
|
||||
from radicale import httputils, pathutils, web
|
||||
from radicale import httputils, pathutils, types, web
|
||||
|
||||
|
||||
class Web(web.BaseWeb):
|
||||
def get(self, environ, base_prefix, path, user):
|
||||
|
||||
def get(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
||||
user: str) -> types.WSGIResponse:
|
||||
assert path == "/.web" or path.startswith("/.web/")
|
||||
assert pathutils.sanitize_path(path) == path
|
||||
if path != "/.web":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue