mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-26 14:47:44 +00:00
Auto-format using ruff
This commit is contained in:
parent
9a0dbc8cd0
commit
cce8fef8de
4 changed files with 23 additions and 22 deletions
|
|
@ -553,9 +553,7 @@ def test_fetch_only_necessary_params(tmpdir, runner):
|
||||||
type = "filesystem"
|
type = "filesystem"
|
||||||
path = "{path}"
|
path = "{path}"
|
||||||
fileext.fetch = ["command", "sh", "{script}"]
|
fileext.fetch = ["command", "sh", "{script}"]
|
||||||
""".format(
|
""".format(path=str(tmpdir.mkdir("bogus")), script=str(fetch_script))
|
||||||
path=str(tmpdir.mkdir("bogus")), script=str(fetch_script)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -364,13 +364,14 @@ class VobjectMachine(RuleBasedStateMachine):
|
||||||
|
|
||||||
TestVobjectMachine = VobjectMachine.TestCase
|
TestVobjectMachine = VobjectMachine.TestCase
|
||||||
|
|
||||||
|
|
||||||
def test_dupe_consecutive_keys():
|
def test_dupe_consecutive_keys():
|
||||||
state = VobjectMachine()
|
state = VobjectMachine()
|
||||||
unparsed_0 = state.get_unparsed_lines(encoded=False, joined=False)
|
unparsed_0 = state.get_unparsed_lines(encoded=False, joined=False)
|
||||||
parsed_0 = state.parse(unparsed=unparsed_0)
|
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_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(c=parsed_0, key="0", value="1")
|
||||||
state.teardown()
|
state.teardown()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC
|
||||||
|
from abc import abstractmethod
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from ssl import create_default_context
|
from ssl import create_default_context
|
||||||
|
|
||||||
|
|
@ -43,7 +44,11 @@ class AuthMethod(ABC):
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, AuthMethod):
|
if not isinstance(other, AuthMethod):
|
||||||
return False
|
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):
|
class BasicAuthMethod(AuthMethod):
|
||||||
|
|
@ -52,7 +57,7 @@ class BasicAuthMethod(AuthMethod):
|
||||||
|
|
||||||
def get_auth_header(self, _method, _url):
|
def get_auth_header(self, _method, _url):
|
||||||
auth_str = f"{self.username}:{self.password}"
|
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):
|
class DigestAuthMethod(AuthMethod):
|
||||||
|
|
@ -64,8 +69,7 @@ class DigestAuthMethod(AuthMethod):
|
||||||
super().__init__(username, password)
|
super().__init__(username, password)
|
||||||
|
|
||||||
self._auth_helper = self._auth_helpers.get(
|
self._auth_helper = self._auth_helpers.get(
|
||||||
(username, password),
|
(username, password), requests.auth.HTTPDigestAuth(username, password)
|
||||||
requests.auth.HTTPDigestAuth(username, password)
|
|
||||||
)
|
)
|
||||||
self._auth_helpers[(username, password)] = self._auth_helper
|
self._auth_helpers[(username, password)] = self._auth_helper
|
||||||
|
|
||||||
|
|
@ -87,7 +91,7 @@ class DigestAuthMethod(AuthMethod):
|
||||||
|
|
||||||
if not self.auth_helper_vars.chal:
|
if not self.auth_helper_vars.chal:
|
||||||
# Need to do init request first
|
# Need to do init request first
|
||||||
return ''
|
return ""
|
||||||
|
|
||||||
return self._auth_helper.build_digest_header(method, url)
|
return self._auth_helper.build_digest_header(method, url)
|
||||||
|
|
||||||
|
|
@ -99,10 +103,12 @@ def prepare_auth(auth, username, password):
|
||||||
elif auth == "digest":
|
elif auth == "digest":
|
||||||
return DigestAuthMethod(username, password)
|
return DigestAuthMethod(username, password)
|
||||||
elif auth == "guess":
|
elif auth == "guess":
|
||||||
raise exceptions.UserError(f"'Guess' authentication is not supported in this version of vdirsyncer. \n"
|
raise exceptions.UserError(
|
||||||
f"Please explicitly specify either 'basic' or 'digest' auth instead. \n"
|
"'Guess' authentication is not supported in this version of vdirsyncer. \n"
|
||||||
f"See the following issue for more information: "
|
"Please explicitly specify either 'basic' or 'digest' auth instead. \n"
|
||||||
f"https://github.com/pimutils/vdirsyncer/issues/1015")
|
"See the following issue for more information: "
|
||||||
|
"https://github.com/pimutils/vdirsyncer/issues/1015"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise exceptions.UserError(f"Unknown authentication method: {auth}")
|
raise exceptions.UserError(f"Unknown authentication method: {auth}")
|
||||||
elif auth:
|
elif auth:
|
||||||
|
|
|
||||||
|
|
@ -310,9 +310,7 @@ class Discover:
|
||||||
</mkcol>
|
</mkcol>
|
||||||
""".format(
|
""".format(
|
||||||
etree.tostring(etree.Element(self._resourcetype), encoding="unicode")
|
etree.tostring(etree.Element(self._resourcetype), encoding="unicode")
|
||||||
).encode(
|
).encode("utf-8")
|
||||||
"utf-8"
|
|
||||||
)
|
|
||||||
|
|
||||||
response = await self.session.request(
|
response = await self.session.request(
|
||||||
"MKCOL",
|
"MKCOL",
|
||||||
|
|
@ -740,9 +738,7 @@ class DAVStorage(Storage):
|
||||||
""".format(
|
""".format(
|
||||||
etree.tostring(element, encoding="unicode"),
|
etree.tostring(element, encoding="unicode"),
|
||||||
action=action,
|
action=action,
|
||||||
).encode(
|
).encode("utf-8")
|
||||||
"utf-8"
|
|
||||||
)
|
|
||||||
|
|
||||||
await self.session.request(
|
await self.session.request(
|
||||||
"PROPPATCH",
|
"PROPPATCH",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue