Refactor ('unvendor') parse_auth_header

This commit is contained in:
Klaas van Schelven
2023-11-09 23:34:27 +01:00
parent 00b4cceca7
commit 641f9c695a

View File

@@ -1,8 +1,3 @@
def _make_key_value(val):
# strip, and then split on '='
return val.strip().split("=", 1)
def parse_auth_header(header):
# KvS: isn't this always either bytes or strings? I'd like to learn more (first quickly, and then formalizing for
# actual uses)
@@ -14,8 +9,9 @@ def parse_auth_header(header):
print("not bytes, already a string")
try:
# the the RHS of the header (question: what's left of the space), split it on "," and put the x=y pairs into a
# dict as key-values
return dict(map(_make_key_value, header.split(" ", 1)[1].split(",")))
_, rhs = header.split(" ", 1)
return {
k: v for (k, v) in [part.strip().split('=', 1) for part in rhs.split(",")]
}
except Exception:
return {}