4
4
import os
5
5
import platform
6
6
import re
7
- from abc import ABC , abstractmethod
7
+ from abc import ABC
8
+ from abc import abstractmethod
8
9
from base64 import b64encode
9
10
from ssl import create_default_context
10
11
@@ -43,7 +44,11 @@ def get_auth_header(self, method, url):
43
44
def __eq__ (self , other ):
44
45
if not isinstance (other , AuthMethod ):
45
46
return False
46
- return self .__class__ == other .__class__ and self .username == other .username and self .password == other .password
47
+ return (
48
+ self .__class__ == other .__class__
49
+ and self .username == other .username
50
+ and self .password == other .password
51
+ )
47
52
48
53
49
54
class BasicAuthMethod (AuthMethod ):
@@ -52,7 +57,7 @@ def handle_401(self, _response):
52
57
53
58
def get_auth_header (self , _method , _url ):
54
59
auth_str = f"{ self .username } :{ self .password } "
55
- return "Basic " + b64encode (auth_str .encode (' utf-8' )).decode ("utf-8" )
60
+ return "Basic " + b64encode (auth_str .encode (" utf-8" )).decode ("utf-8" )
56
61
57
62
58
63
class DigestAuthMethod (AuthMethod ):
@@ -64,8 +69,7 @@ def __init__(self, username, password):
64
69
super ().__init__ (username , password )
65
70
66
71
self ._auth_helper = self ._auth_helpers .get (
67
- (username , password ),
68
- requests .auth .HTTPDigestAuth (username , password )
72
+ (username , password ), requests .auth .HTTPDigestAuth (username , password )
69
73
)
70
74
self ._auth_helpers [(username , password )] = self ._auth_helper
71
75
@@ -87,7 +91,7 @@ def get_auth_header(self, method, url):
87
91
88
92
if not self .auth_helper_vars .chal :
89
93
# Need to do init request first
90
- return ''
94
+ return ""
91
95
92
96
return self ._auth_helper .build_digest_header (method , url )
93
97
@@ -99,10 +103,12 @@ def prepare_auth(auth, username, password):
99
103
elif auth == "digest" :
100
104
return DigestAuthMethod (username , password )
101
105
elif auth == "guess" :
102
- raise exceptions .UserError (f"'Guess' authentication is not supported in this version of vdirsyncer. \n "
103
- f"Please explicitly specify either 'basic' or 'digest' auth instead. \n "
104
- f"See the following issue for more information: "
105
- f"https://github.com/pimutils/vdirsyncer/issues/1015" )
106
+ raise exceptions .UserError (
107
+ "'Guess' authentication is not supported in this version of vdirsyncer. \n "
108
+ "Please explicitly specify either 'basic' or 'digest' auth instead. \n "
109
+ "See the following issue for more information: "
110
+ "https://github.com/pimutils/vdirsyncer/issues/1015"
111
+ )
106
112
else :
107
113
raise exceptions .UserError (f"Unknown authentication method: { auth } " )
108
114
elif auth :
0 commit comments