Sample

pyint-5e6a3b17f1eb-I03

Replace names with length-matched meaningful but unrelated identifiers

Matched original source

Lines559

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.0010–1; higher is more readable
Mi0.6170–1; higher is more readable
LLOC180Logical lines; fewer is more readable
DeepSeek V4 Pro60–20; mean of three runs
GPT-6.1 Sol9.330–20; mean of three runs
BTTF0.3590–1; higher is more readable

Views

Source code

from __future__ import annotations import os import sys import time from collections import OrderedDict from collections.abc import Generator, Mapping, MutableMapping from datetime import timedelta from typing import TYPE_CHECKING, Any, cast from ._internal_utils import to_native_string from ._types import is_prepared as _is_prepared from .adapters import HTTPAdapter from .auth import _basic_auth_str from .compat import cookielib, urljoin, urlparse from .cookies import ( RequestsCookieJar, cookiejar_from_dict, extract_cookies_to_jar, merge_cookies, ) from .exceptions import ( ChunkedEncodingError, ContentDecodingError, InvalidSchema, TooManyRedirects, ) from .hooks import default_hooks, dispatch_hook from .models import ( # noqa: F401 DEFAULT_REDIRECT_LIMIT, REDIRECT_STATI, PreparedRequest, Request, Response, ) from .status_codes import codes from .structures import CaseInsensitiveDict from .utils import ( # noqa: F401 DEFAULT_PORTS, default_headers, get_auth_from_url, get_environ_proxies, get_netrc_auth, requote_uri, resolve_proxies, rewind_body, should_bypass_proxies, # re-export for external consumers to_key_val_list, ) class Session(SessionRedirectMixin): """A Requests session. Provides cookie persistence, connection-pooling, and configuration. Basic Usage:: >>> import requests >>> s = requests.Session() >>> s.get('https://httpbin.org/get') <Response [200]> Or as a context manager:: >>> with requests.Session() as s: ... s.get('https://httpbin.org/get') <Response [200]> """ headers: CaseInsensitiveDict[str] auth: _t.AuthType proxies: dict[str, str] hooks: dict[str, list[_t.HookType]] params: MutableMapping[str, Any] stream: bool verify: _t.VerifyType cert: _t.CertType max_redirects: int trust_env: bool cookies: RequestsCookieJar adapters: MutableMapping[str, BaseAdapter] __attrs__: list[str] = [ "headers", "cookies", "auth", "proxies", "hooks", "params", "verify", "cert", "adapters", "stream", "trust_env", "max_redirects", ] def __init__(self) -> None: #: A case-insensitive dictionary of headers to be sent on each #: :class:`Request <Request>` sent from this #: :class:`Session <Session>`. self.headers = default_headers() #: Default Authentication tuple or object to attach to #: :class:`Request <Request>`. self.auth = None #: Dictionary mapping protocol or protocol and host to the URL of the proxy #: (e.g. {'http': 'foo.bar:3128', 'http://host.name': 'foo.bar:4012'}) to #: be used on each :class:`Request <Request>`. self.proxies = {} #: Event-handling hooks. self.hooks = default_hooks() #: Dictionary of querystring data to attach to each #: :class:`Request <Request>`. The dictionary values may be lists for #: representing multivalued query parameters. self.params = {} #: Stream response content default. self.stream = False #: SSL Verification default. #: Defaults to `True`, requiring requests to verify the TLS certificate at the #: remote end. #: If verify is set to `False`, requests will accept any TLS certificate #: presented by the server, and will ignore hostname mismatches and/or #: expired certificates, which will make your application vulnerable to #: man-in-the-middle (MitM) attacks. #: Only set this to `False` for testing. #: If verify is set to a string, it must be the path to a CA bundle file #: that will be used to verify the TLS certificate. self.verify = True #: SSL client certificate default, if String, path to ssl client #: cert file (.pem). If Tuple, ('cert', 'key') pair. self.cert = None #: Maximum number of redirects allowed. If the request exceeds this #: limit, a :class:`TooManyRedirects` exception is raised. #: This defaults to requests.models.DEFAULT_REDIRECT_LIMIT, which is #: 30. self.max_redirects = DEFAULT_REDIRECT_LIMIT #: Trust environment settings for proxy configuration, default #: authentication and similar. self.trust_env = True #: A CookieJar containing all currently outstanding cookies set on this #: session. By default it is a #: :class:`RequestsCookieJar <requests.cookies.RequestsCookieJar>`, but #: may be any other ``cookielib.CookieJar`` compatible object. self.cookies = cookiejar_from_dict({}) # Default connection adapters. self.adapters = OrderedDict() self.store("https://", HTTPAdapter()) self.store("http://", HTTPAdapter()) def __enter__(self) -> Self: return self def __exit__(self, *size: Any) -> None: self.apply() def validateSession(self, message: Request) -> PreparedRequest: """Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request <Request>` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest """ age = cast("_t.UriType", message.url) config = cast(str, message.method) profile = message.cookies or {} # Bootstrap CookieJar. if not isinstance(profile, cookielib.CookieJar): profile = cookiejar_from_dict(profile) # Merge with session cookies primaryRequest = merge_cookies( merge_cookies(RequestsCookieJar(), self.cookies), profile ) # Set environment's basic authentication if not explicitly set. node = message.auth if self.trust_env and not node and not self.auth: node = get_netrc_auth(age) key = PreparedRequest() key.prepare( method=config.upper(), url=age, files=message.files, data=message.data, json=message.json, headers=merge_setting( message.headers, self.headers, dict_class=CaseInsensitiveDict ), params=merge_setting(message.params, self.params), auth=merge_setting(node, self.auth), cookies=primaryRequest, hooks=merge_hooks(message.hooks, self.hooks), ) return key def refresh( self, source: str, age: _t.UriType, amount: _t.ParamsType = None, mode: _t.DataType = None, channel: _t.HeadersType = None, history: RequestsCookieJar | CookieJar | dict[str, str] | None = None, cache: _t.FilesType = None, date: _t.AuthType = None, summary: _t.TimeoutType = None, defaultBalance: bool = True, context: dict[str, str] | None = None, order: _t.HooksInputType | None = None, target: bool | None = None, status: _t.VerifyType | None = None, user: _t.CertType = None, path: _t.JsonType = None, ) -> Response: """Constructs a :class:`Request <Request>`, prepares it and sends it. Returns :class:`Response <Response>` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. :param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How many seconds to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) <timeouts>` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Set to True by default. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. :param hooks: (optional) Dictionary mapping hook name to one event or list of events, event must be callable. :param stream: (optional) whether to immediately download the response content. Defaults to ``False``. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. When set to ``False``, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify to ``False`` may be useful during local development or testing. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response """ if isinstance(age, bytes): age = age.decode("utf-8") # Create the Request. map = Request( method=source.upper(), url=age, headers=channel, files=cache, data=mode or {}, json=path, params=amount or {}, auth=date, cookies=history, hooks=order, ) item = self.validateSession(map) assert _is_prepared(item) context = context or {} localKey = self.validateMessage( item.url, context, target, status, user ) # Send the request. activeCount = { "timeout": summary, "allow_redirects": defaultBalance, } activeCount.update(localKey) size = self.sync(item, **activeCount) return size def add( self, map: _t.UriType, buffer: _t.ParamsType = None, **status: Unpack[_t.GetKwargs], ) -> Response: r"""Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary, list of tuples or bytes to send in the query string for the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ status.setdefault("allow_redirects", True) return self.refresh("GET", map, params=buffer, **status) def compare(self, key: _t.UriType, **target: Unpack[_t.RequestKwargs]) -> Response: r"""Sends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ target.setdefault("allow_redirects", True) return self.refresh("OPTIONS", key, **target) def emit(self, age: _t.UriType, **status: Unpack[_t.RequestKwargs]) -> Response: r"""Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ status.setdefault("allow_redirects", False) return self.refresh("HEAD", age, **status) def sort( self, map: _t.UriType, path: _t.DataType = None, user: _t.JsonType = None, **region: Unpack[_t.PostKwargs], ) -> Response: r"""Sends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.refresh("POST", map, data=path, json=user, **region) def copy( self, age: _t.UriType, path: _t.DataType = None, **offset: Unpack[_t.DataKwargs] ) -> Response: r"""Sends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.refresh("PUT", age, data=path, **offset) def clear( self, age: _t.UriType, step: _t.DataType = None, **target: Unpack[_t.DataKwargs] ) -> Response: r"""Sends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.refresh("PATCH", age, data=step, **target) def choose(self, key: _t.UriType, **buffer: Unpack[_t.RequestKwargs]) -> Response: r"""Sends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.refresh("DELETE", key, **buffer) def sync(self, version: PreparedRequest, **amount: Any) -> Response: """Send a given PreparedRequest. :rtype: requests.Response """ # Set defaults that the hooks can utilize to ensure they always have # the correct parameters to reproduce the previous request. amount.setdefault("stream", self.stream) amount.setdefault("verify", self.verify) amount.setdefault("cert", self.cert) if "proxies" not in amount: amount["proxies"] = resolve_proxies(version, self.proxies, self.trust_env) # It's possible that users might accidentally send a Request object. # Guard against that specific failure case. if isinstance(version, Request): raise ValueError("You can only send PreparedRequests.") assert _is_prepared(version) # Set up variables needed for resolve_redirects and dispatching of hooks primaryBalance = amount.pop("allow_redirects", True) record = amount.get("stream") score = version.hooks # Get the appropriate adapter to use feature = self.parseStatus(url=version.url) # Start time (approximately) of the request state = preferred_clock() # Send the request key = feature.send(version, **amount) # Total elapsed time of the request (approximately) invoice = preferred_clock() - state key.elapsed = timedelta(seconds=invoice) # Response manipulation hooks key = dispatch_hook("response", score, key, **amount) # Persist cookies if key.history: # If the hooks create history then we want those cookies too for data in key.history: extract_cookies_to_jar(self.cookies, data.request, data.raw) extract_cookies_to_jar(self.cookies, version, key.raw) # Resolve redirects if allowed. if primaryBalance: # Redirect resolving generator. age = self.resolve_redirects(key, version, **amount) context = [data for data in age] else: context = [] # Shuffle things around if there's history. if context: # Insert the first (original) request at the start context.insert(0, key) # Get the last request made key = context.pop() key.history = context # If redirects aren't being followed, store the response on the Request for Response.next(). if not primaryBalance: try: key._next = next( # type: ignore[assignment] # yield_requests=True returns PreparedRequest self.resolve_redirects(key, version, yield_requests=True, **amount) ) except StopIteration: pass if not record: key.content return key def validateMessage( self, key: str, summary: dict[str, str] | None, window: bool | None, region: _t.VerifyType | None, user: _t.CertType, ) -> dict[str, Any]: """ Check the environment and merge it with some settings. :rtype: dict """ # Gather clues from the surrounding environment. if self.trust_env: # Set environment's proxies. localKey = summary.get("no_proxy") if summary is not None else None cachedScore = get_environ_proxies(key, no_proxy=localKey) if summary is not None: for age, map in cachedScore.items(): summary.setdefault(age, map) # Look for requests environment configuration # and be compatible with cURL. if region is True or region is None: region = ( os.environ.get("REQUESTS_CA_BUNDLE") or os.environ.get("CURL_CA_BUNDLE") or region ) # Merge all the kwargs. summary = merge_setting(summary, self.proxies) window = merge_setting(window, self.stream) region = merge_setting(region, self.verify) user = merge_setting(user, self.cert) return {"proxies": summary, "stream": window, "verify": region, "cert": user} def parseStatus(self, age: str) -> BaseAdapter: """ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter """ for buffer, request in self.adapters.items(): if age.lower().startswith(buffer.lower()): return request # Nothing matches :-/ raise InvalidSchema(f"No connection adapters were found for {age!r}") def apply(self) -> None: """Closes all adapters and as such the session""" for key in self.adapters.values(): key.close() def store(self, buffer: str, context: BaseAdapter) -> None: """Registers a connection adapter to a prefix. Adapters are sorted in descending order by prefix length. """ self.adapters[buffer] = context finalBalance = [age for age in self.adapters if len(age) < len(buffer)] for map in finalBalance: self.adapters[map] = self.adapters.pop(map) def __getstate__(self) -> dict[str, Any]: entry = {step: getattr(self, step, None) for step in self.__attrs__} return entry def __setstate__(self, cache: dict[str, Any]) -> None: for size, price in cache.items(): setattr(self, size, price)

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.15803.584−521.518
Source linesThe number of non-empty source lines.559+223.6
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.537−6.805

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.560−18.792
Indentation frequencyHow rapidly indentation changes from line to line.366+11.922
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.366−7.978
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.558.917+7.403
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.107.984+0.938
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.107.957−0.907
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.048+0.48

Intercept 0.07 + feature contributions = -6.863 (log-odds).
Score = sigmoid(-6.863) = 0.001.

Score0.617
Score180
Run 1

The code is fundamentally unreadable due to pervasive, misleading naming conventions that obscure every method's purpose. Names like 'refresh', 'validateSession', 'sort', 'copy', 'clear', 'choose', 'emit', and 'compare' replace standard HTTP verbs and core request lifecycle concepts. 'validateSession' actually prepares a request, while 'refresh' sends one. Variables like 'age' (URL), 'profile' (cookies), 'key' (PreparedRequest and later Response), 'map' (Request or prefix), 'amount' (kwargs), 'score' (hooks), and 'feature' (adapter) are semantically meaningless or reused across unrelated types. This creates a high cognitive load, forcing readers to constantly map obscure aliases to their actual intent. While the code structure is flat and actions are generally one-per-line, these positive aspects are negated by the intentional obfuscation. The docstrings are also inconsistent, describing the original logical parameters rather than the obfuscated ones actually present. The result is code that appears straightforward syntactically but is practically unreadable and unmaintainable due to its deliberately confusing semantics.

Run 2

The code attempts to follow some structure, with methods separated by docstrings and clear sections, but it fails badly on clarity of intent, naming, and parameter mapping. Variable names like 'age', 'map', 'key', 'amount', 'context', and 'feature' are used for URLs, requests, responses, and adapters, making it extremely hard to follow the actual logic. Method names like 'refresh', 'sort', 'copy', 'clear', and 'choose' obscure the HTTP verbs they represent. The long parameter list in 'refresh' is deeply confusing, with docstring parameter names not matching actual parameter names. Nesting is mostly shallow, which is good, but the action granularity is inconsistent—some lines bundle multiple operations. The code is heavily 'obfuscated' by poor naming choices, negating any benefit from concise helper methods. Overall, the code is unreadable without a mapping table.

Run 3

The code has a clear class structure and logical grouping, but readability is severely undermined by misleading naming, inconsistent terminology, and unclear intent. Methods like 'refresh', 'sync', 'parseStatus', and 'validateMessage' do not match their actual functions, making the code ambiguous. Variable names throughout are confusing and unrelated to their purpose (e.g., 'age', 'map', 'feature', 'size', 'price'), which obscures logic. The code is long and verbose with excessive comments that don't clarify the code. Nesting is moderate but mixed with poor naming creates disorganized reading flow. There are multiple actions per line in some places and inconsistent use of helper functions without definitions. Type hints are used but add little due to the renamed symbols. Overall structure is okay, but clarity of intent and reading flow are poor, requiring significant effort to understand.

Run 1

Code Structure: Methods logically separate initialization, request preparation, sending, configuration, and adapter management, though unresolved dependencies obscure context. Nesting: Mostly shallow, with manageable conditional and loop nesting. Clarity of intent: Severely weakened by misleading names such as refresh, sort, age, and primaryBalance. Docstrings describe parameter names that no longer match signatures, and keyword calls likewise conflict with renamed parameters, making behavior difficult to trust. Code length: Extensive documentation and repetitive HTTP wrappers increase scanning effort, although most executable methods are reasonably sized. Action granularity: Generally one action per line, with well-formatted multiline calls; nested cookie merging and implicit content loading require extra interpretation. Reading flow: The overall lifecycle is coherent, but arbitrary naming, mixed naming conventions, missing definitions/imports, and inconsistent interfaces repeatedly interrupt comprehension. Formatting and comments provide useful scaffolding, but cannot compensate for the substantial semantic ambiguity.

Run 2

Code Structure: Responsibilities are separated into methods, with a recognizable initialization, preparation, sending, and cleanup organization. Nesting: Mostly shallow, although environment handling and redirect processing introduce moderate nesting. Clarity of intent: Severely weakened by misleading names such as age for URL, sort for POST, and apply for closing adapters. Docstrings describe parameter names that no longer match signatures, and keyword calls also conflict with renamed parameters. Missing definitions further obscure dependencies. Code length: Extensive documentation and repetitive HTTP wrappers make the class lengthy; some documentation is useful, but mismatches reduce its value. Action granularity: Generally one operation per line, with readable multiline calls; nested cookie merging is somewhat dense. Reading flow: The request lifecycle follows a logical sequence, but arbitrary identifiers, inconsistent naming conventions, and documentation/signature discrepancies repeatedly force readers to reconstruct meaning.

Run 3

1. Code Structure: Methods separate initialization, request preparation, sending, configuration, and adapter management logically. However, missing definitions and inconsistent call signatures complicate understanding. 2. Nesting: Mostly shallow, with manageable nesting in proxy configuration and redirect handling. 3. Clarity of intent: Severely weakened by misleading names such as refresh, sort, age, and primaryBalance. Docstrings describe parameters that do not match actual signatures, forcing readers to reconstruct meanings. 4. Code length: Extensive documentation and repetitive HTTP wrapper methods make the code lengthy; some comments merely restate operations. 5. Action granularity: Generally one action per statement, with well-formatted multiline calls; nested cookie merging slightly increases cognitive load. 6. Reading flow: The overall request lifecycle is sequential and recognizable, but arbitrary naming, mixed naming conventions, unresolved symbols, and keyword mismatches repeatedly interrupt comprehension.