From cce8fef8de6ea89f6f9d3b6816d92e99a3368ee3 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Mon, 7 Apr 2025 18:25:19 +0200 Subject: [PATCH] Auto-format using ruff --- tests/system/cli/test_sync.py | 4 +--- tests/unit/utils/test_vobject.py | 7 ++++--- vdirsyncer/http.py | 26 ++++++++++++++++---------- vdirsyncer/storage/dav.py | 8 ++------ 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/system/cli/test_sync.py b/tests/system/cli/test_sync.py index ee2afbc..2824be5 100644 --- a/tests/system/cli/test_sync.py +++ b/tests/system/cli/test_sync.py @@ -553,9 +553,7 @@ def test_fetch_only_necessary_params(tmpdir, runner): type = "filesystem" path = "{path}" fileext.fetch = ["command", "sh", "{script}"] - """.format( - path=str(tmpdir.mkdir("bogus")), script=str(fetch_script) - ) + """.format(path=str(tmpdir.mkdir("bogus")), script=str(fetch_script)) ) ) diff --git a/tests/unit/utils/test_vobject.py b/tests/unit/utils/test_vobject.py index 53659c8..032e4a5 100644 --- a/tests/unit/utils/test_vobject.py +++ b/tests/unit/utils/test_vobject.py @@ -364,13 +364,14 @@ class VobjectMachine(RuleBasedStateMachine): TestVobjectMachine = VobjectMachine.TestCase + def test_dupe_consecutive_keys(): state = VobjectMachine() unparsed_0 = state.get_unparsed_lines(encoded=False, joined=False) parsed_0 = state.parse(unparsed=unparsed_0) - state.add_prop_raw(c=parsed_0, key='0', params=[], value='0') - state.add_prop_raw(c=parsed_0, key='0', params=[], value='0') - state.add_prop(c=parsed_0, key='0', value='1') + state.add_prop_raw(c=parsed_0, key="0", params=[], value="0") + state.add_prop_raw(c=parsed_0, key="0", params=[], value="0") + state.add_prop(c=parsed_0, key="0", value="1") state.teardown() diff --git a/vdirsyncer/http.py b/vdirsyncer/http.py index 9321aba..4d4644e 100644 --- a/vdirsyncer/http.py +++ b/vdirsyncer/http.py @@ -4,7 +4,8 @@ import logging import os import platform import re -from abc import ABC, abstractmethod +from abc import ABC +from abc import abstractmethod from base64 import b64encode from ssl import create_default_context @@ -43,7 +44,11 @@ class AuthMethod(ABC): def __eq__(self, other): if not isinstance(other, AuthMethod): return False - return self.__class__ == other.__class__ and self.username == other.username and self.password == other.password + return ( + self.__class__ == other.__class__ + and self.username == other.username + and self.password == other.password + ) class BasicAuthMethod(AuthMethod): @@ -52,7 +57,7 @@ class BasicAuthMethod(AuthMethod): def get_auth_header(self, _method, _url): auth_str = f"{self.username}:{self.password}" - return "Basic " + b64encode(auth_str.encode('utf-8')).decode("utf-8") + return "Basic " + b64encode(auth_str.encode("utf-8")).decode("utf-8") class DigestAuthMethod(AuthMethod): @@ -64,8 +69,7 @@ class DigestAuthMethod(AuthMethod): super().__init__(username, password) self._auth_helper = self._auth_helpers.get( - (username, password), - requests.auth.HTTPDigestAuth(username, password) + (username, password), requests.auth.HTTPDigestAuth(username, password) ) self._auth_helpers[(username, password)] = self._auth_helper @@ -87,7 +91,7 @@ class DigestAuthMethod(AuthMethod): if not self.auth_helper_vars.chal: # Need to do init request first - return '' + return "" return self._auth_helper.build_digest_header(method, url) @@ -99,10 +103,12 @@ def prepare_auth(auth, username, password): elif auth == "digest": return DigestAuthMethod(username, password) elif auth == "guess": - raise exceptions.UserError(f"'Guess' authentication is not supported in this version of vdirsyncer. \n" - f"Please explicitly specify either 'basic' or 'digest' auth instead. \n" - f"See the following issue for more information: " - f"https://github.com/pimutils/vdirsyncer/issues/1015") + raise exceptions.UserError( + "'Guess' authentication is not supported in this version of vdirsyncer. \n" + "Please explicitly specify either 'basic' or 'digest' auth instead. \n" + "See the following issue for more information: " + "https://github.com/pimutils/vdirsyncer/issues/1015" + ) else: raise exceptions.UserError(f"Unknown authentication method: {auth}") elif auth: diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index 697ebf0..d5b1da6 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -310,9 +310,7 @@ class Discover: """.format( etree.tostring(etree.Element(self._resourcetype), encoding="unicode") - ).encode( - "utf-8" - ) + ).encode("utf-8") response = await self.session.request( "MKCOL", @@ -740,9 +738,7 @@ class DAVStorage(Storage): """.format( etree.tostring(element, encoding="unicode"), action=action, - ).encode( - "utf-8" - ) + ).encode("utf-8") await self.session.request( "PROPPATCH",