Cosmetic changes

This commit is contained in:
Unrud 2020-01-19 18:13:05 +01:00
parent e07df9fd1d
commit 866aa34f54
7 changed files with 19 additions and 23 deletions

View File

@ -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:

View File

@ -195,7 +195,7 @@ def get_etag(text):
"""
etag = sha256()
etag.update(text.encode("utf-8"))
etag.update(text.encode())
return '"%s"' % etag.hexdigest()

View File

@ -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()

View File

@ -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:

View File

@ -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)

View File

@ -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 = "<C:filter>{}</C:filter>"
filter_template = "<C:filter>%s</C:filter>"
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 = '<C:filter test="{}">{{}}</C:filter>'.format(
test)
filter_template = '<C:filter test="%s">%%s</C:filter>' % 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,
"""<?xml version="1.0" encoding="utf-8" ?>
@ -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:
</D:prop>
</C:calendar-query>""")
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):

View File

@ -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)