diff options
author | Unrud <unrud@outlook.com> | 2020-05-19 07:25:21 +0200 |
---|---|---|
committer | Unrud <unrud@outlook.com> | 2020-05-19 07:25:21 +0200 |
commit | c4925ae7db6704ca440a6bf3bc3195e0262d7722 (patch) | |
tree | cb01b9862588ff7530bbadb9f5c72dbf8e17577c | |
parent | Add .gitignore (diff) | |
download | radicaleinfcloud-c4925ae7db6704ca440a6bf3bc3195e0262d7722.tar.gz radicaleinfcloud-c4925ae7db6704ca440a6bf3bc3195e0262d7722.tar.bz2 radicaleinfcloud-c4925ae7db6704ca440a6bf3bc3195e0262d7722.zip |
Update for Radicale 3.0.x
-rw-r--r-- | radicale_infcloud/__init__.py | 45 | ||||
-rwxr-xr-x | setup.py | 4 |
2 files changed, 27 insertions, 22 deletions
diff --git a/radicale_infcloud/__init__.py b/radicale_infcloud/__init__.py index 7f1b3ea..8dc04df 100644 --- a/radicale_infcloud/__init__.py +++ b/radicale_infcloud/__init__.py @@ -1,5 +1,5 @@ # RadicaleWeb web interface for Radicale. -# Copyright (C) 2017 Unrud <unrud@outlook.com> +# Copyright © 2017-2018, 2020 Unrud <unrud@outlook.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,18 +15,22 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import os -import pkg_resources import posixpath import time - from http import client -from radicale import storage, web -from radicale.web import NOT_FOUND, MIMETYPES, FALLBACK_MIMETYPE +from radicale import httputils, pathutils +from radicale.log import logger +from radicale.web import internal +from radicale.web.internal import MIMETYPES, FALLBACK_MIMETYPE + +import pkg_resources + +PLUGIN_CONFIG_SCHEMA = {"web": {}} -class Web(web.Web): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) +class Web(internal.Web): + def __init__(self, configuration): + super().__init__(configuration.copy(PLUGIN_CONFIG_SCHEMA)) self.infcloud_folder = pkg_resources.resource_filename(__name__, "web") def get(self, environ, base_prefix, path, user): @@ -35,28 +39,29 @@ class Web(web.Web): user) if status == client.OK and path in ("/.web/", "/.web/index.html"): answer = answer.replace(b"""\ - <nav> - <ul>""", b"""\ - <nav> - <ul> - <li><a href="infcloud">InfCloud</a></li>""") +<nav> + <ul>""", b"""\ +<nav> + <ul> + <li><a href="infcloud">InfCloud</a></li>""") return status, headers, answer + assert pathutils.sanitize_path(path) == path try: - filesystem_path = storage.path_to_filesystem( - self.infcloud_folder, path[len("/.web/infcloud"):]) + filesystem_path = pathutils.path_to_filesystem( + self.infcloud_folder, path[len("/.web/infcloud"):].strip("/")) except ValueError as e: - self.logger.debug("Web content with unsafe path %r requested: %s", - path, e, exc_info=True) - return NOT_FOUND + logger.debug("Web content with unsafe path %r requested: %s", + path, e, exc_info=True) + return httputils.NOT_FOUND if os.path.isdir(filesystem_path) and not path.endswith("/"): location = posixpath.basename(path) + "/" - return (client.SEE_OTHER, + return (client.FOUND, {"Location": location, "Content-Type": "text/plain"}, "Redirected to %s" % location) if os.path.isdir(filesystem_path): filesystem_path = os.path.join(filesystem_path, "index.html") if not os.path.isfile(filesystem_path): - return NOT_FOUND + return httputils.NOT_FOUND content_type = MIMETYPES.get( os.path.splitext(filesystem_path)[1].lower(), FALLBACK_MIMETYPE) with open(filesystem_path, "rb") as f: @@ -4,7 +4,7 @@ import os from setuptools import setup -VERSION = "2.0.0" +VERSION = "3.0.0" os.chdir("radicale_infcloud") web_data = sum(([os.path.join(root, f) for f in files @@ -23,4 +23,4 @@ setup( platforms="Any", packages=["radicale_infcloud"], package_data={"radicale_infcloud": web_data}, - install_requires=["radicale>=2.1.0"]) + install_requires=["radicale>=3.0.0"]) |