Sample

pyint-6faf2c417d3e-I04

Replace names with deterministic minifier-style shortest identifiers

Matched original source

Lines422

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.0070–1; higher is more readable
Mi0.5610–1; higher is more readable
LLOC192Logical lines; fewer is more readable
DeepSeek V4 Pro30–20; mean of three runs
GPT-6.1 Sol100–20; mean of three runs
BTTF0.2310–1; higher is more readable

Views

Source code

from __future__ import annotations import datetime import encodings.idna # noqa: F401 from collections.abc import Callable, Generator, Iterable, Iterator, Mapping from io import UnsupportedOperation from typing import ( TYPE_CHECKING, Any, Final, Literal, cast, overload, ) from urllib3.exceptions import ( DecodeError, LocationParseError, ProtocolError, ReadTimeoutError, SSLError, ) from urllib3.fields import RequestField from urllib3.filepost import encode_multipart_formdata from urllib3.util import parse_url from . import _types as _t from ._internal_utils import to_native_string, unicode_is_ascii from .auth import HTTPBasicAuth from .compat import ( JSONDecodeError, basestring, builtin_str, chardet, cookielib, urlencode, urlsplit, urlunparse, ) from .compat import json as complexjson from .cookies import ( _copy_cookie_jar, cookiejar_from_dict, get_cookie_header, ) from .exceptions import ( ChunkedEncodingError, ConnectionError, ContentDecodingError, HTTPError, InvalidJSONError, InvalidURL, MissingSchema, StreamConsumedError, ) from .exceptions import JSONDecodeError as RequestsJSONDecodeError from .exceptions import SSLError as RequestsSSLError from .hooks import default_hooks from .status_codes import codes from .structures import CaseInsensitiveDict from .utils import ( check_header_validity, get_auth_from_url, guess_filename, guess_json_utf, iter_slices, parse_header_links, requote_uri, stream_decode_response_unicode, super_len, to_key_val_list, ) class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): """The fully mutable :class:`PreparedRequest <PreparedRequest>` object, containing the exact bytes that will be sent to the server. Instances are generated from a :class:`Request <Request>` object, and should not be instantiated manually; doing so may produce undesirable effects. Usage:: >>> import requests >>> req = requests.Request('GET', 'https://httpbin.org/get') >>> r = req.prepare() >>> r <PreparedRequest [GET]> >>> s = requests.Session() >>> s.send(r) <Response [200]> """ method: str | None url: str | None headers: CaseInsensitiveDict[str | bytes] _cookies: RequestsCookieJar | CookieJar | None body: _t.BodyType hooks: dict[str, list[_t.HookType]] _body_position: int | object | None def __init__(self) -> None: #: HTTP verb to send to the server. self.method = None #: HTTP URL to send the request to. self.url = None #: dictionary of HTTP headers. self.headers = None # type: ignore[assignment] # The `CookieJar` used to create the Cookie header will be stored here # after prepare_cookies is called self._cookies = None #: request body to send to the server. self.body = None #: dictionary of callback hooks, for internal usage. self.hooks = default_hooks() #: integer denoting starting position of a readable file-like body. self._body_position = None def a( self, m: str | None = None, n: _t.UriType | None = None, o: Mapping[str, str | bytes] | None = None, q: _t.FilesType = None, s: _t.DataType = None, t: _t.ParamsType = None, u: _t.AuthType = None, v: RequestsCookieJar | CookieJar | dict[str, str] | None = None, w: _t.HooksInputType | None = None, x: _t.JsonType = None, ) -> None: """Prepares the entire request with the given parameters.""" n = cast("_t.UriType", n) self.c(m) self.f(n, t) self.g(o) self.k(v) self.h(s, q, x) self.j(u, n) # Note that prepare_auth must be last to enable authentication schemes # such as OAuth to work on a fully prepared request. # This MUST go after prepare_auth. Authenticators could add a hook self.l(w) def __repr__(self) -> str: return f"<PreparedRequest [{self.method}]>" def b(self) -> PreparedRequest: y = PreparedRequest() y.method = self.method y.url = self.url y.headers = self.headers.copy() if self.headers is not None else None # type: ignore[assignment] y._cookies = _copy_cookie_jar(self._cookies) y.body = self.body y.hooks = self.hooks y._body_position = self._body_position return y def c(self, z: str | None) -> None: """Prepares the given HTTP method.""" self.method = z if self.method is not None: self.method = to_native_string(self.method.upper()) @staticmethod def d(A: str) -> str: import idna try: A = idna.encode(A, uts46=True).decode("utf-8") except idna.IDNAError: raise UnicodeError return A def f( self, B: _t.UriType, C: _t.ParamsType, ) -> None: """Prepares the given HTTP URL.""" #: Accept objects that have string representations. #: We're unable to blindly call unicode/str functions #: as this will include the bytestring indicator (b'') #: on python 3.x. #: https://github.com/psf/requests/pull/2238 if isinstance(B, bytes): B = B.decode("utf8") else: B = str(B) # Remove leading whitespaces from url B = B.lstrip() # Don't do any URL preparation for non-HTTP schemes like `mailto`, # `data` etc to work around exceptions from `url_parse`, which # handles RFC 3986 only. if ":" in B and not B.lower().startswith("http"): self.url = B return # Support for unicode domain names and paths. try: D, E, F, G, K, H, I = parse_url(B) except LocationParseError as e: raise InvalidURL(*e.args) if not D: raise MissingSchema( f"Invalid URL {B!r}: No scheme supplied. " f"Perhaps you meant https://{B}?" ) if not F: raise InvalidURL(f"Invalid URL {B!r}: No host supplied") # In general, we want to try IDNA encoding the hostname if the string contains # non-ASCII characters. This allows users to automatically get the correct IDNA # behaviour. For strings containing only ASCII characters, we need to also verify # it doesn't start with a wildcard (*), before allowing the unencoded hostname. if not unicode_is_ascii(F): try: F = self.d(F) except UnicodeError: raise InvalidURL("URL has an invalid label.") elif F.startswith(("*", ".")): raise InvalidURL("URL has an invalid label.") # Carefully reconstruct the network location J = E or "" if J: J += "@" J += F if G: J += f":{G}" # Bare domains aren't valid URLs. if not K: K = "/" if isinstance(C, (str, bytes)): C = to_native_string(C) if C is not None: L = self._encode_params(C) else: L = "" if L: if H: H = f"{H}&{L}" else: H = L B = requote_uri(urlunparse((D, J, K, "", H, I))) self.url = B def g(self, M: Mapping[str, str | bytes] | None) -> None: """Prepares the given HTTP headers.""" self.headers = CaseInsensitiveDict() if M: for N in M.items(): # Raise exception on invalid header value. check_header_validity(N) O, P = N self.headers[to_native_string(O)] = P def h( self, Q: _t.DataType, R: _t.FilesType, S: _t.JsonType = None ) -> None: """Prepares the given HTTP body data.""" # Check if file, fo, generator, iterator. # If not, run through normal process. # Nottin' on you. T = None U = None if not Q and S is not None: # urllib3 requires a bytes-like body. Python 2's json.dumps # provides this natively, but Python 3 gives a Unicode string. U = "application/json" try: T = complexjson.dumps(S, allow_nan=False) except ValueError as ve: raise InvalidJSONError(ve, request=self) if not isinstance(T, bytes): T = T.encode("utf-8") # data that proxies attributes to underlying objects needs hasattr V = isinstance(Q, Iterable) or hasattr(Q, "__iter__") if V and not isinstance(Q, (str, bytes, list, tuple, Mapping)): try: W = super_len(Q) except (TypeError, AttributeError, UnsupportedOperation): W = None T = Q if getattr(T, "tell", None) is not None: # Record the current file position before reading. # This will allow us to rewind a file in the event # of a redirect. try: self._body_position = T.tell() # type: ignore[union-attr] # guarded by getattr check except OSError: # This differentiates from None, allowing us to catch # a failed `tell()` later when trying to rewind the body self._body_position = object() if R: raise NotImplementedError( "Streamed bodies and files are mutually exclusive." ) if W: self.headers["Content-Length"] = builtin_str(W) else: self.headers["Transfer-Encoding"] = "chunked" else: # After is_stream filtering, remaining data is raw (not streamed) X = cast("_t.RawDataType | None", Q) # Multi-part file uploads. if R: (T, U) = self._encode_files(R, X) else: if X: T = self._encode_params(X) if isinstance(Q, basestring) or _t.has_read(Q): U = None else: U = "application/x-www-form-urlencoded" self.i(T) # Add content-type if it wasn't explicitly provided. if U and ("content-type" not in self.headers): self.headers["Content-Type"] = U self.body = T # type: ignore[assignment] # body transforms from DataType to BodyType def i(self, Y: _t.BodyType) -> None: """Prepare Content-Length header based on request method and body""" if Y is not None: Z = super_len(Y) if Z: # If length exists, set it. Otherwise, we fallback # to Transfer-Encoding: chunked. self.headers["Content-Length"] = builtin_str(Z) elif ( self.method not in ("GET", "HEAD") and self.headers.get("Content-Length") is None ): # Set Content-Length to 0 for methods that can have a body # but don't provide one. (i.e. not GET or HEAD) self.headers["Content-Length"] = "0" def j( self, aa: _t.AuthType, ab: _t.UriType = "", ) -> None: """Prepares the given HTTP auth data.""" # If no Auth is explicitly provided, extract it from the URL first. if aa is None: ac = get_auth_from_url(cast(str, self.url)) aa = ac if any(ac) else None if aa: if isinstance(aa, tuple) and len(aa) == 2: # type: ignore[arg-type] # pyright widens tuple from Callable in AuthType # special-case basic HTTP auth ad = HTTPBasicAuth(*aa) # type: ignore[arg-type] # pyright widens tuple from Callable in AuthType else: # TODO: can be fixed by flipping the conditionals ad = cast("Callable[..., PreparedRequest]", aa) # Allow auth to make its changes. ae = ad(self) # Update self to reflect the auth changes. self.__dict__.update(ae.__dict__) # Recompute Content-Length self.i(self.body) def k( self, af: RequestsCookieJar | CookieJar | dict[str, str] | None ) -> None: """Prepares the given HTTP cookie data. This function eventually generates a ``Cookie`` header from the given cookies using cookielib. Due to cookielib's design, the header will not be regenerated if it already exists, meaning this function can only be called once for the life of the :class:`PreparedRequest <PreparedRequest>` object. Any subsequent calls to ``prepare_cookies`` will have no actual effect, unless the "Cookie" header is removed beforehand. """ if isinstance(af, cookielib.CookieJar): self._cookies = af else: self._cookies = cookiejar_from_dict(af) ag = cast("CookieJar", self._cookies) ah = get_cookie_header(ag, self) if ah is not None: self.headers["Cookie"] = ah def l(self, ai: _t.HooksInputType | None) -> None: """Prepares the given hooks.""" # hooks can be passed as None to the prepare method and to this # method. To prevent iterating over None, simply use an empty list # if hooks is False-y ai = ai or {} for aj in ai: self.register_hook(aj, ai[aj])

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.13194.193−435.408
Source linesThe number of non-empty source lines.422+168.8
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.459−6.689

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.423−13.941
Indentation frequencyHow rapidly indentation changes from line to line.333+10.781
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.333−7.22
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.421.969+5.488
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.129.967−1.84
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.129.988+1.293
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.416

Intercept 0.07 + feature contributions = -4.953 (log-odds).
Score = sigmoid(-4.953) = 0.007.

Score0.561
Score192
Run 1

The code is virtually unreadable due to systematically obfuscated identifiers (e.g., methods a, b, c, d; parameters m, n, o, q; local variables B, D, E, F). This destroys clarity of intent and reading flow. The logic structure is preserved but hidden behind meaningless names. Nesting is moderate but irrelevant when names convey nothing. Action granularity is acceptable but negated by the inability to discern what actions mean. The original requests library code is readable, but this version deliberately replaces descriptive names (prepare, prepare_url, prepare_headers, url, params, etc.) with single letters, making all comments and docstrings disconnected from the actual code. Even imports are unaffected; the class definition and docstrings remain, but they cannot compensate for the loss of semantic naming. Overall, this is a textbook example of poor readability due to naming obfuscation, not structural complexity.

Run 2

This code is severely obfuscated. Method names (a through l) and parameter names (m through x, then A through ai) are systematically replaced with meaningless single or double letters, destroying any clarity of intent. While the original structure (imports, class layout, method organization) is logical, the deliberate renaming makes the code unreadable. Docstrings remain but don't match the cryptic implementations. Nesting and length are reasonable, but action granularity and reading flow are completely broken by the loss of semantic naming. This is essentially a manual obfuscation of what was originally readable code.

Run 3

The code is severely obfuscated through meaningless single-letter variable names (a through aj) and method names (a through l), making the code extremely difficult to read and maintain. The original library code is well-structured, but this modification deliberately obscures all semantic meaning. While the underlying organization and control flow remain logical, the naming destroys clarity of intent, reading flow, and action granularity comprehension. The code has moderate nesting and reasonable length, but these are overwhelmed by the impossible-to-follow naming scheme.

Run 1

Code Structure: Request preparation is logically divided into focused methods, with a central orchestration method. Nesting: Mostly moderate, but body preparation contains several nested branches and exception handlers. Clarity of intent: Docstrings, comments, and type annotations help, but single-letter method names and opaque variables severely obscure meaning and force readers to repeatedly infer roles. Comments referencing original method names also create disconnects. Code length: Generally justified by HTTP edge cases, though lengthy imports, verbose annotations, and some redundant comments add overhead. Action granularity: Most lines perform one action, making individual operations straightforward to follow. Reading flow: The preparation sequence is coherent, but cryptic calls, dense type-ignore comments, and long conditional lines interrupt comprehension. Overall, sound organization and documentation partially compensate for pervasive naming obfuscation.

Run 2

Code Structure: Request preparation is logically separated into methods, with a clear orchestration sequence. Nesting: Mostly manageable, but body preparation has several nested branches that increase cognitive load. Clarity of intent: Docstrings, comments, and type annotations help substantially, but opaque method names (a–l) and variable names (B, T, aa) obscure responsibilities and data meanings. Comments also reference descriptive method names absent from this version. Code length: Generally justified by HTTP edge cases, though extensive imports, verbose comments, and typing workarounds add clutter. Action granularity: Most lines perform one action, making individual operations easy to isolate. Reading flow: Preparation stages follow a sensible order, but understanding calls and tracking URL components or body state requires repeatedly consulting definitions and comments. Overall, sound organization is significantly undermined by non-descriptive naming.

Run 3

Code Structure: Request preparation is logically divided into focused methods, although the large import block adds clutter. Nesting: Mostly moderate, but body preparation contains several nested branches that increase cognitive load. Clarity of intent: Docstrings, comments, and type annotations explain responsibilities, but single-letter method and variable names severely obscure operations and data roles; comments referring to original method names compound this problem. Code length: Reasonable for the functionality, though extensive comments, typing workarounds, and some redundant branching add verbosity. Action granularity: Most lines perform one action, making individual statements easy to isolate. Reading flow: Preparation follows a sensible sequence, and validation uses helpful early exits, but understanding calls such as self.f(n, t) requires repeatedly consulting definitions. Overall, sound organization is substantially undermined by opaque naming.