Sample

pyint-76e701e8aab4-I04

Replace names with deterministic minifier-style shortest identifiers

Matched original source

Lines245

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.120–1; higher is more readable
Mi0.4420–1; higher is more readable
LLOC160Logical lines; fewer is more readable
DeepSeek V4 Pro5.330–20; mean of three runs
GPT-6.1 Sol90–20; mean of three runs
BTTF0.2290–1; higher is more readable

Views

Source code

from __future__ import annotations import hashlib import os import re import threading import time import warnings from base64 import b64encode from typing import TYPE_CHECKING, Any, Final, cast, overload from ._internal_utils import to_native_string from .compat import basestring, str, urlparse from .cookies import extract_cookies_to_jar from .utils import parse_dict_header class HTTPDigestAuth(AuthBase): """Attaches HTTP Digest Authentication to the given Request object.""" username: bytes | str password: bytes | str _thread_local: threading.local last_nonce: str nonce_count: int chal: dict[str, str] pos: int | None num_401_calls: int | None @overload def __init__(self, f: str, g: str) -> None: ... @overload def __init__(self, h: bytes, i: bytes) -> None: ... def __init__(self, j: bytes | str, k: bytes | str) -> None: self.username = j self.password = k # Keep state in per-thread local storage self._thread_local = threading.local() def a(self) -> None: # Ensure state is initialized just once per-thread if not hasattr(self._thread_local, "init"): self._thread_local.init = True self._thread_local.last_nonce = "" self._thread_local.nonce_count = 0 self._thread_local.chal = {} self._thread_local.pos = None self._thread_local.num_401_calls = None def b(self, l: str, m: str) -> str | None: """ :rtype: str """ n = self._thread_local.chal["realm"] o = self._thread_local.chal["nonce"] p = self._thread_local.chal.get("qop") q = self._thread_local.chal.get("algorithm") t = self._thread_local.chal.get("opaque") u = None if q is None: v = "MD5" else: v = q.upper() # lambdas assume digest modules are imported at the top level if v == "MD5" or v == "MD5-SESS": def md5_utf8(K: str | bytes) -> str: if isinstance(K, str): K = K.encode("utf-8") return hashlib.md5(K, usedforsecurity=False).hexdigest() u = md5_utf8 elif v == "SHA": def sha_utf8(L: str | bytes) -> str: if isinstance(L, str): L = L.encode("utf-8") return hashlib.sha1(L, usedforsecurity=False).hexdigest() u = sha_utf8 elif v == "SHA-256": def sha256_utf8(M: str | bytes) -> str: if isinstance(M, str): M = M.encode("utf-8") return hashlib.sha256(M, usedforsecurity=False).hexdigest() u = sha256_utf8 elif v == "SHA-512": def sha512_utf8(N: str | bytes) -> str: if isinstance(N, str): N = N.encode("utf-8") return hashlib.sha512(N, usedforsecurity=False).hexdigest() u = sha512_utf8 if u is None: return None def KD(O: str, P: str) -> str: return hash_utf8(f"{O}:{P}") # XXX not implemented yet w = None y = urlparse(m) #: path is request-uri defined in RFC 2616 which should not be empty z = y.path or "/" if y.query: z += f"?{y.query}" A = f"{self.username}:{n}:{self.password}" B = f"{l}:{z}" C = u(A) D = u(B) if o == self._thread_local.last_nonce: self._thread_local.nonce_count += 1 else: self._thread_local.nonce_count = 1 E = f"{self._thread_local.nonce_count:08x}" F = str(self._thread_local.nonce_count).encode("utf-8") F += o.encode("utf-8") F += time.ctime().encode("utf-8") F += os.urandom(8) G = hashlib.sha1(F, usedforsecurity=False).hexdigest()[:16] if v == "MD5-SESS": C = u(f"{C}:{o}:{G}") # type: ignore[reportConstantRedefinition] # RFC 2617 terminology if not p: H = KD(C, f"{o}:{D}") elif p == "auth" or "auth" in p.split(","): I = f"{o}:{E}:{G}:auth:{D}" H = KD(C, I) else: # XXX handle auth-int. return None self._thread_local.last_nonce = o # XXX should the partial digests be encoded too? J = ( f'username="{self.username}", realm="{n}", nonce="{o}", ' f'uri="{z}", response="{H}"' ) if t: J += f', opaque="{t}"' if q: J += f', algorithm="{q}"' if w: J += f', digest="{w}"' if p: J += f', qop="auth", nc={E}, cnonce="{G}"' return f"Digest {J}" def c(self, Q: Response, **R: Any) -> None: """Reset num_401_calls counter on redirects.""" if Q.is_redirect: self._thread_local.num_401_calls = 1 def e(self, S: Response, **T: Any) -> Response: """ Takes the given response and tries digest-auth, if needed. :rtype: requests.Response """ # If response is not 4xx, do not auth # See https://github.com/psf/requests/issues/3772 if not 400 <= S.status_code < 500: self._thread_local.num_401_calls = 1 return S if self._thread_local.pos is not None: # Rewind the file position indicator of the body to where # it was to resend the request. if (U := getattr(S.request.body, "seek", None)) is not None: U(self._thread_local.pos) V = S.headers.get("www-authenticate", "") if "digest" in V.lower() and self._thread_local.num_401_calls < 2: self._thread_local.num_401_calls += 1 W = re.compile(r"digest ", flags=re.IGNORECASE) self._thread_local.chal = parse_dict_header(W.sub("", V, count=1)) # Consume content and release the original connection # to allow our new request to reuse the same one. S.content S.close() X = S.request.copy() Y = cast("CookieJar", X._cookies) extract_cookies_to_jar(Y, S.request, S.raw) X.prepare_cookies(Y) Z = self.b( cast(str, X.method), cast(str, X.url) ) if Z: X.headers["Authorization"] = Z aa = S.connection.send(X, **T) aa.history.append(S) aa.request = X return aa self._thread_local.num_401_calls = 1 return S def __call__(self, ab: PreparedRequest) -> PreparedRequest: # Initialize per-thread state, if needed self.a() # If we have a saved nonce, skip the 401 if self._thread_local.last_nonce: ac = self.b( cast(str, ab.method), cast(str, ab.url) ) if ac: ab.headers["Authorization"] = ac if (ad := getattr(ab.body, "tell", None)) is not None: self._thread_local.pos = ad() else: # In the case of HTTPDigestAuth being reused and the body of # the previous request was a file-like object, pos has the # file position of the previous body. Ensure it's set to # None. self._thread_local.pos = None ab.register_hook("response", self.e) ab.register_hook("response", self.c) self._thread_local.num_401_calls = 1 return ab def __eq__(self, ae: object) -> bool: return all( [ self.username == getattr(ae, "username", None), self.password == getattr(ae, "password", None), ] ) def __ne__(self, af: Any) -> bool: return not self == af

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.10073.379−332.421
Source linesThe number of non-empty source lines.245+98
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.468−6.703

Intercept 8.87 + feature contributions = -232.254 (log-odds).
Score = sigmoid(-232.254) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.246−7.674
Indentation frequencyHow rapidly indentation changes from line to line.219+6.838
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.219−4.605
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.244.922+3.014
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.100.98+0.825
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.100.984−0.612
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.082+0.147

Intercept 0.07 + feature contributions = -1.997 (log-odds).
Score = sigmoid(-1.997) = 0.12.

Score0.442
Score160
Run 1

The code is extremely difficult to read due to deliberately obfuscated naming. Variables like 'a', 'b', 'c', 'e', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 't', 'u', 'v', 'w', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P' have no semantic meaning, making intent completely unclear. Method names are equally opaque. While the structure is technically linear and nesting is moderate, the single-letter variables create artificial complexity. The logic copies standard HTTPDigestAuth but obscures every identifier, making even simple operations like 'hash_utf8' appear as undeclared references. The code length is reasonable for the functionality but unintelligible. Action granularity and reading flow are destroyed by the need to constantly mentally map meaningless symbols to concepts. This reads like deliberately deobfuscated code.

Run 2

The code's core logic is recognizable as HTTP Digest Auth, but readability is severely degraded by single-letter variable names (j, k, l, m, n, o, p, etc.), single-letter method names (a, b, c, e), and generic function names (KD, A, B, C). This obscures intent and forces readers to mentally map symbols to concepts like 'username' or 'nonce'. The structure is reasonably flat and actions are mostly separated per line, but the overly terse naming and excessive use of intermediate variables (like `I` for the qop string) increase cognitive load. The code relies on comments to explain logic that should be self-evident from good naming. While the flow follows authentication steps, the abbreviation of parameters and methods makes it feel disorganized. Overall, the code is functional but unreadable for maintainers.

Run 3

The code is very difficult to read due to single-letter variable names throughout (a, b, c, e, j, k, l, m, n, o, p, q, t, u, v, etc.), which obscures intent and breaks reading flow. Method names are also meaningless (a, b, c, e). While structure is somewhat organized, the heavy use of cryptic abbreviations, inline walrus operators, and compact f-strings reduces clarity. Nesting is moderate but combined with poor naming makes comprehension difficult. Action granularity is acceptable but readability suffers significantly.

Run 1

Code Structure: Class methods separate initialization, digest construction, response handling, and request setup, but digest construction combines many responsibilities. Nesting: Generally moderate, with early returns limiting depth; nested hash helpers and conditionals add complexity. Clarity of intent: The class name, comments, and type hints provide context, but single-letter method names and sequential variable names severely obscure meaning. KD references undefined hash_utf8 rather than the selected hash function, further confusing the logic. Code length: Repeated encoding/hash helpers and verbose state management make the implementation longer than necessary. Action granularity: Most lines perform one action, although assignment expressions and standalone S.content introduce less obvious operations. Reading flow: Authentication steps follow a mostly logical sequence, but tracing anonymous variables across the long digest method and between cryptically named methods requires substantial effort.

Run 2

Code Structure: Responsibilities are separated into methods, but the large digest-building method mixes algorithm selection, state updates, hashing, and header formatting. Nesting: Mostly moderate, with early returns limiting depth; nested hash functions add complexity. Clarity of intent: The class name, comments, and some attributes explain authentication behavior, but single-letter method and variable names severely obscure meaning. KD references undefined hash_utf8 rather than the selected hashing function, further confusing interpretation. Code length: Repeated hashing wrappers and verbose thread-local accesses make the implementation longer than necessary. Action granularity: Generally one action per line, with readable statement separation; assignment expressions introduce minor compression. Reading flow: Authentication follows a broadly logical sequence, but readers must repeatedly decode opaque identifiers and track mutable state across methods. Stale comments, unused imports, and unresolved names also interrupt comprehension.

Run 3

Code Structure: Authentication responsibilities are separated into methods, but the digest-building method mixes algorithm selection, nonce management, hashing, and header formatting. Nesting: Generally moderate, with early returns limiting depth; nested hashing functions add some complexity. Clarity of intent: The class name, comments, and some state fields are informative, but single-letter method names and pervasive arbitrary variable names obscure most operations. KD references undefined hash_utf8 rather than the selected hashing function, further confusing intent. Code length: Repeated hashing wrappers and verbose thread-local accesses make the implementation longer than necessary. Action granularity: Most lines perform one action, although assignment expressions combine lookup and branching. Reading flow: The overall initialization, challenge handling, and request-retry sequence is logical, but cryptic identifiers force repeated backtracking, and stale comments and minimal docstrings provide insufficient guidance.