From 866aa34f54f8492199b4198eaf565c39b6b3cead Mon Sep 17 00:00:00 2001 From: Unrud Date: Sun, 19 Jan 2020 18:13:05 +0100 Subject: [PATCH] Cosmetic changes --- radicale/__main__.py | 9 ++++----- radicale/item/__init__.py | 2 +- radicale/storage/__init__.py | 2 +- radicale/storage/multifilesystem/sync.py | 2 +- radicale/tests/__init__.py | 4 ++-- radicale/tests/test_base.py | 18 ++++++++---------- radicale/tests/test_server.py | 5 ++--- 7 files changed, 19 insertions(+), 23 deletions(-) diff --git a/radicale/__main__.py b/radicale/__main__.py index e0a58b8..323b57f 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -58,11 +58,10 @@ def run(): if option.startswith("_"): continue kwargs = data.copy() - long_name = "--{0}-{1}".format( - section, option.replace("_", "-")) + long_name = "--%s-%s" % (section, option.replace("_", "-")) args = kwargs.pop("aliases", []) args.append(long_name) - kwargs["dest"] = "{0}_{1}".format(section, option) + kwargs["dest"] = "%s_%s" % (section, option) groups[group].append(kwargs["dest"]) del kwargs["value"] if "internal" in kwargs: @@ -73,11 +72,11 @@ def run(): kwargs["action"] = "store_const" kwargs["const"] = "True" opposite_args = kwargs.pop("opposite", []) - opposite_args.append("--no{0}".format(long_name[1:])) + opposite_args.append("--no%s" % long_name[1:]) group.add_argument(*args, **kwargs) kwargs["const"] = "False" - kwargs["help"] = "do not {0} (opposite of {1})".format( + kwargs["help"] = "do not %s (opposite of %s)" % ( kwargs["help"], long_name) group.add_argument(*opposite_args, **kwargs) else: diff --git a/radicale/item/__init__.py b/radicale/item/__init__.py index 91a2501..aef6d9e 100644 --- a/radicale/item/__init__.py +++ b/radicale/item/__init__.py @@ -195,7 +195,7 @@ def get_etag(text): """ etag = sha256() - etag.update(text.encode("utf-8")) + etag.update(text.encode()) return '"%s"' % etag.hexdigest() diff --git a/radicale/storage/__init__.py b/radicale/storage/__init__.py index b214587..2437834 100644 --- a/radicale/storage/__init__.py +++ b/radicale/storage/__init__.py @@ -81,7 +81,7 @@ class BaseCollection: """Encoded as quoted-string (see RFC 2616).""" etag = sha256() for item in self.get_all(): - etag.update((item.href + "/" + item.etag).encode("utf-8")) + etag.update((item.href + "/" + item.etag).encode()) etag.update(json.dumps(self.get_meta(), sort_keys=True).encode()) return '"%s"' % etag.hexdigest() diff --git a/radicale/storage/multifilesystem/sync.py b/radicale/storage/multifilesystem/sync.py index d1ffcb1..21c00c1 100644 --- a/radicale/storage/multifilesystem/sync.py +++ b/radicale/storage/multifilesystem/sync.py @@ -54,7 +54,7 @@ class CollectionSyncMixin: ((href, None) for href in self._get_deleted_history_hrefs())): history_etag = self._update_history_etag(href, item) state[href] = history_etag - token_name_hash.update((href + "/" + history_etag).encode("utf-8")) + token_name_hash.update((href + "/" + history_etag).encode()) token_name = token_name_hash.hexdigest() token = "http://radicale.org/ns/sync/%s" % token_name if token_name == old_token_name: diff --git a/radicale/tests/__init__.py b/radicale/tests/__init__.py index 4e6b12a..984aa1a 100644 --- a/radicale/tests/__init__.py +++ b/radicale/tests/__init__.py @@ -62,7 +62,7 @@ class BaseTest: args["REQUEST_METHOD"] = method.upper() args["PATH_INFO"] = path if data: - data = data.encode("utf-8") + data = data.encode() args["wsgi.input"] = BytesIO(data) args["CONTENT_LENGTH"] = str(len(data)) args["wsgi.errors"] = sys.stderr @@ -75,4 +75,4 @@ class BaseTest: answer = self.application(args, start_response) return (int(status.split()[0]), dict(headers), - answer[0].decode("utf-8") if answer else None) + answer[0].decode() if answer else None) diff --git a/radicale/tests/test_base.py b/radicale/tests/test_base.py index 134b1ea..3d60f79 100644 --- a/radicale/tests/test_base.py +++ b/radicale/tests/test_base.py @@ -444,20 +444,19 @@ class BaseRequestsMixIn: assert answer.count("BEGIN:VEVENT") == 2 def _test_filter(self, filters, kind="event", test=None, items=(1,)): - filter_template = "{}" + filter_template = "%s" if kind in ("event", "journal", "todo"): create_collection_fn = partial(self.request, "MKCALENDAR") path = "/calendar.ics/" - filename_template = "{}{}.ics" + filename_template = "%s%d.ics" namespace = "urn:ietf:params:xml:ns:caldav" report = "calendar-query" elif kind == "contact": create_collection_fn = self._create_addressbook if test: - filter_template = '{{}}'.format( - test) + filter_template = '%%s' % test path = "/contacts.vcf/" - filename_template = "{}{}.vcf" + filename_template = "%s%d.vcf" namespace = "urn:ietf:params:xml:ns:carddav" report = "addressbook-query" else: @@ -467,13 +466,12 @@ class BaseRequestsMixIn: status, _, _ = create_collection_fn(path) assert status == 201 for i in items: - filename = filename_template.format(kind, i) + filename = filename_template % (kind, i) event = get_file_content(filename) status, _, _ = self.request( "PUT", posixpath.join(path, filename), event) assert status == 201 - filters_text = "".join( - filter_template.format(filter_) for filter_ in filters) + filters_text = "".join(filter_template % f for f in filters) status, _, answer = self.request( "REPORT", path, """ @@ -1350,7 +1348,7 @@ class BaseRequestsMixIn: status, _, _ = self.request("MKCALENDAR", "/test/") assert status == 201 for component in ("event", "todo", "journal"): - event = get_file_content("{}1.ics".format(component)) + event = get_file_content("%s1.ics" % component) status, _, _ = self.request("DELETE", "/test/test.ics") assert status in (200, 404) status, _, _ = self.request("PUT", "/test/test.ics", event) @@ -1364,7 +1362,7 @@ class BaseRequestsMixIn: """) assert status == 207 - assert ">text/calendar;charset=utf-8;component=V{}<".format( + assert ">text/calendar;charset=utf-8;component=V%s<" % ( component.upper()) in answer def test_addressbook_getcontenttype(self): diff --git a/radicale/tests/test_server.py b/radicale/tests/test_server.py index 70919e3..df858a8 100644 --- a/radicale/tests/test_server.py +++ b/radicale/tests/test_server.py @@ -151,11 +151,10 @@ class TestBaseServerRequests: for option, data in values.items(): if option.startswith("_"): continue - long_name = "--{0}-{1}".format( - section, option.replace("_", "-")) + long_name = "--%s-%s" % (section, option.replace("_", "-")) if data["type"] == bool: if not self.configuration.get(section, option): - long_name = "--no{0}".format(long_name[1:]) + long_name = "--no%s" % long_name[1:] config_args.append(long_name) else: config_args.append(long_name)