Skip to content

Commit

Permalink
refactoring maps code on set comprehension (python-caldav#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemIsmagilov authored Jun 13, 2024
1 parent 1a700ca commit 3031145
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 3 additions & 5 deletions caldav/davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,9 @@ def delete(self, url: str) -> DAVResponse:
def options(self, url: str) -> DAVResponse:
return self.request(url, "OPTIONS")

def extract_auth_types(self, header):
auth_types = header.lower().split(",")
auth_types = map(lambda auth_type: auth_type.strip(), auth_types)
auth_types = map(lambda auth_type: auth_type.split(" ")[0], auth_types)
return list(filter(lambda auth_type: auth_type, auth_types))
def extract_auth_types(self, header: str):
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate#syntax
return {h.split()[0] for h in header.lower().split(",")}

def request(
self,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_caldav_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,12 +1293,12 @@ def testExtractAuth(self):
"""
cal_url = "http://me:[email protected]:80/"
with DAVClient(url=cal_url) as client:
assert client.extract_auth_types("Basic\n") == ["basic"]
assert client.extract_auth_types("Basic") == ["basic"]
assert client.extract_auth_types('Basic Realm=foo;charset="UTF-8"') == [
assert client.extract_auth_types("Basic\n") == {"basic"}
assert client.extract_auth_types("Basic") == {"basic"}
assert client.extract_auth_types('Basic Realm=foo;charset="UTF-8"') == {
"basic"
]
assert client.extract_auth_types("Basic,dIGEST Realm=foo") == [
}
assert client.extract_auth_types("Basic,dIGEST Realm=foo") == {
"basic",
"digest",
]
}

0 comments on commit 3031145

Please sign in to comment.