]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Small namedtuple refactor (#1329)
authorJohannes <johtso@gmail.com>
Sun, 27 Sep 2020 20:15:04 +0000 (21:15 +0100)
committerGitHub <noreply@github.com>
Sun, 27 Sep 2020 20:15:04 +0000 (22:15 +0200)
Plus order consistency because why not..

httpx/_auth.py

index c91ab7b986454720f055e6b46c914e9a6eb3b1b3..343f9cdd16a5f56c0867c9db9305ebae25af0213 100644 (file)
@@ -197,11 +197,11 @@ class DigestAuth(Auth):
         try:
             realm = header_dict["realm"].encode()
             nonce = header_dict["nonce"].encode()
-            qop = header_dict["qop"].encode() if "qop" in header_dict else None
-            opaque = header_dict["opaque"].encode() if "opaque" in header_dict else None
             algorithm = header_dict.get("algorithm", "MD5")
+            opaque = header_dict["opaque"].encode() if "opaque" in header_dict else None
+            qop = header_dict["qop"].encode() if "qop" in header_dict else None
             return _DigestAuthChallenge(
-                realm=realm, nonce=nonce, qop=qop, opaque=opaque, algorithm=algorithm
+                realm=realm, nonce=nonce, algorithm=algorithm, opaque=opaque, qop=qop
             )
         except KeyError as exc:
             message = "Malformed Digest WWW-Authenticate header"
@@ -296,17 +296,9 @@ class DigestAuth(Auth):
         raise ProtocolError(message, request=request)
 
 
-class _DigestAuthChallenge:
-    def __init__(
-        self,
-        realm: bytes,
-        nonce: bytes,
-        algorithm: str,
-        opaque: typing.Optional[bytes] = None,
-        qop: typing.Optional[bytes] = None,
-    ) -> None:
-        self.realm = realm
-        self.nonce = nonce
-        self.algorithm = algorithm
-        self.opaque = opaque
-        self.qop = qop
+class _DigestAuthChallenge(typing.NamedTuple):
+    realm: bytes
+    nonce: bytes
+    algorithm: str
+    opaque: typing.Optional[bytes]
+    qop: typing.Optional[bytes]