From eea6ccb57378baa0f1d1fc4f114afa1a84489e5e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 18 May 2016 22:43:56 +0200 Subject: [PATCH 1/5] Fix UnboundLocalError --- radicale/xmlutils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 0c42d72..49f520d 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -133,6 +133,9 @@ def _comp_match(item, filter_, scope="collection"): for component in item.components(): if component.name in ("VTODO", "VEVENT", "VJOURNAL"): tag = component.name + break + else: + return False if filter_length == 0: # Point #1 of rfc4791-9.7.1 return filter_.get("name") == tag From 3a2cc58f3bbb8e102228e4640077342e8d0e6d0f Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 18 May 2016 22:57:05 +0200 Subject: [PATCH 2/5] Fix tox env once and for all --- .travis.yml | 5 ++--- tox.ini | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 155808f..3252b1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,9 @@ python: - 3.5 install: - - pip install -e . - - pip install tox flake8 + - pip install tox script: - - tox -r -e py + - tox -e py sudo: false diff --git a/tox.ini b/tox.ini index 02e5637..fed01a0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,11 @@ [tox] envlist = py33, py34, py35 -[base] +[testenv] deps = flake8 pytest -[testenv] commands = flake8 py.test From b810d61ce3d309c0437a87edcfd527e99399b3e6 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 21 May 2016 01:41:00 +0200 Subject: [PATCH 3/5] Don't sanitize local paths using posixpath This doesn't work as expected on Windows. --- radicale/storage.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/radicale/storage.py b/radicale/storage.py index 982026f..a6f744f 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -97,7 +97,6 @@ def path_to_filesystem(root, *paths): Conversion is done in a secure manner, or raises ``ValueError``. """ - root = sanitize_path(root) paths = [sanitize_path(path).strip("/") for path in paths] safe_path = root for path in paths: @@ -303,7 +302,7 @@ class Collection(BaseCollection): _, directories, _ = next(os.walk(collection._filesystem_path)) for sub_path in directories: full_path = os.path.join(collection._filesystem_path, sub_path) - if os.path.exists(path_to_filesystem(full_path)): + if os.path.exists(full_path): yield cls(posixpath.join(path, sub_path)) @classmethod From de2f41182033d85a89aa8ce05c291707f74ab97c Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 21 May 2016 01:49:22 +0200 Subject: [PATCH 4/5] Use nonlocal instead of container Python 3 --- radicale/__main__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/radicale/__main__.py b/radicale/__main__.py index 73f7f2b..9672214 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -173,7 +173,7 @@ def run(): if not configuration.getboolean("server", "dns_lookup"): RequestHandler.address_string = lambda self: self.client_address[0] - shutdown_program = [False] + shutdown_program = False for host in configuration.get("server", "hosts").split(","): address, port = host.strip().rsplit(":", 1) @@ -198,11 +198,12 @@ def run(): # SIGTERM and SIGINT (aka KeyboardInterrupt) should just mark this for # shutdown def shutdown(*args): - if shutdown_program[0]: + nonlocal shutdown_program + if shutdown_program: # Ignore following signals return logger.info("Stopping Radicale") - shutdown_program[0] = True + shutdown_program = True if shutdown_program_socket_in: shutdown_program_socket_in.sendall(b"goodbye") signal.signal(signal.SIGTERM, shutdown) @@ -218,7 +219,7 @@ def run(): # Fallback to busy waiting select_timeout = 1.0 logger.debug("Radicale server ready") - while not shutdown_program[0]: + while not shutdown_program: try: rlist, _, xlist = select.select( sockets, [], sockets, select_timeout) From a24613da9cb4b209430b0c6309dcb6a636ac0374 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 21 May 2016 02:26:03 +0200 Subject: [PATCH 5/5] Compress answer The protocol uses verbose XML and compression reduces the size significantly. --- radicale/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/radicale/__init__.py b/radicale/__init__.py index 35ab75d..5251bfc 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -33,6 +33,7 @@ import socket import ssl import wsgiref.simple_server import re +import zlib from http import client from urllib.parse import unquote, urlparse @@ -314,6 +315,13 @@ class Application: if answer: self.logger.debug("Response content:\n%s" % answer, environ) answer = answer.encode(self.encoding) + accept_encoding = [ + encoding.strip() for encoding in + environ.get("HTTP_ACCEPT_ENCODING", "").split(",") + if encoding.strip()] + if "deflate" in accept_encoding: + answer = zlib.compress(answer) + headers["Content-Encoding"] = "deflate" headers["Content-Length"] = str(len(answer)) if self.configuration.has_section("headers"):