From 2cf34a0d671c6c46a28f9b98302d9b632a909740 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 21 Oct 2014 13:13:16 +0200 Subject: [PATCH] Cosmetic changes --- radicale/__init__.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index dc56019..1216d7a 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -56,7 +56,6 @@ VERSION = "0.9" # Standard "not allowed" response that is returned when an authenticated user # tries to access information they don't have rights to NOT_ALLOWED = (client.FORBIDDEN, {}, None) -WELLKNOWNRE = re.compile(r'/.well-known/(carddav|caldav)/?') class HTTPServer(wsgiref.simple_server.WSGIServer, object): @@ -100,9 +99,8 @@ class HTTPSServer(HTTPServer): server_side=True, certfile=config.get("server", "certificate"), keyfile=config.get("server", "key"), - ssl_version=getattr(ssl, config.get("server", "protocol"), - ssl.PROTOCOL_SSLv23) - ) + ssl_version=getattr( + ssl, config.get("server", "protocol"), ssl.PROTOCOL_SSLv23)) # add ciphers argument only if supported (Python 2.7+) if sys.version_info >= (2, 7): ssl_kwargs["ciphers"] = config.get("server", "ciphers") or None @@ -279,22 +277,24 @@ class Application(object): user = environ.get("REMOTE_USER") password = None - wkfragment = WELLKNOWNRE.match(path) - if wkfragment: - if not user: del user - redirect = config.get("well-known", wkfragment.group(1)) + well_known = re.compile(r"/.well-known/(carddav|caldav)/?").match(path) + if well_known: + redirect = config.get("well-known", well_known.group(1)) try: - redirect = redirect % locals() - status = client.SEE_OTHER - log.LOGGER.info("/.well-known/ redirection to: %s" % redirect) - headers = {"Location": redirect.encode('utf8')} + redirect = redirect % ({"user": user} if user else {}) except KeyError: status = client.UNAUTHORIZED headers = { "WWW-Authenticate": "Basic realm=\"%s\"" % config.get("server", "realm")} - log.LOGGER.info("refused /.well-known/ redirection to anonymous user") - status = "%i %s" % (status, client.responses.get(status, "Unknown")) + log.LOGGER.info( + "Refused /.well-known/ redirection to anonymous user") + else: + status = client.SEE_OTHER + log.LOGGER.info("/.well-known/ redirection to: %s" % redirect) + headers = {"Location": redirect.encode("utf8")} + status = "%i %s" % ( + status, client.responses.get(status, "Unknown")) start_response(status, headers.items()) return []