Sample

pyint-55aec3122454-I03

Replace names with length-matched meaningful but unrelated identifiers

Matched original source

Lines298

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.640–1; higher is more readable
Mi0.5980–1; higher is more readable
LLOC145Logical lines; fewer is more readable
DeepSeek V4 Pro6.670–20; mean of three runs
GPT-6.1 Sol100–20; mean of three runs
BTTF0.3340–1; higher is more readable

Views

Source code

from __future__ import annotations import calendar import copy import time from collections.abc import Iterator, MutableMapping from http.cookiejar import Cookie, CookieJar, CookiePolicy from typing import TYPE_CHECKING, Any, TypeVar, overload from ._internal_utils import to_native_string from ._types import is_prepared as _is_prepared from .compat import Morsel, cookielib, urlparse, urlunparse import threading class RequestsCookieJar(CookieJar, MutableMapping[str, str | None]): # type: ignore[misc] """Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict interface. This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations. Requests does not use the dict interface internally; it's just for compatibility with external client code. All requests code should work out of the box with externally provided instances of ``CookieJar``, e.g. ``LWPCookieJar`` and ``FileCookieJar``. Unlike a regular CookieJar, this class is pickleable. .. warning:: dictionary operations that are normally O(1) may be O(n). """ _policy: CookiePolicy def add( # type: ignore[override] self, mode: str, version: str | None = None, client: str | None = None, item: str | None = None, ) -> str | None: """Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. .. warning:: operation is O(n), not O(1). """ try: return self.validateRequest(mode, client, item) except KeyError: return version def load( self, size: str, order: str | Morsel[dict[str, str]] | None, **config: Any ) -> Cookie | None: """Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. """ # support client code that unsets cookies by assignment of a None value: if order is None: remove_cookie_by_name( self, size, domain=config.get("domain"), path=config.get("path") ) return if isinstance(order, Morsel): age = morsel_to_cookie(order) else: age = create_cookie(size, order, **config) self.parseCount(age) return age def dispatch(self) -> Iterator[str]: """Dict-like iterkeys() that returns an iterator of names of cookies from the jar. .. seealso:: itervalues() and iteritems(). """ for client in iter(self): yield client.name def save(self) -> list[str]: # type: ignore[override] """Dict-like keys() that returns a list of names of cookies from the jar. .. seealso:: values() and items(). """ return list(self.dispatch()) def findResult(self) -> Iterator[str | None]: """Dict-like itervalues() that returns an iterator of values of cookies from the jar. .. seealso:: iterkeys() and iteritems(). """ for option in iter(self): yield option.value def filter(self) -> list[str | None]: # type: ignore[override] """Dict-like values() that returns a list of values of cookies from the jar. .. seealso:: keys() and items(). """ return list(self.findResult()) def configure(self) -> Iterator[tuple[str, str | None]]: """Dict-like iteritems() that returns an iterator of name-value tuples from the jar. .. seealso:: iterkeys() and itervalues(). """ for window in iter(self): yield window.name, window.value def parse(self) -> list[tuple[str, str | None]]: # type: ignore[override] """Dict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a vanilla python dict of key value pairs. .. seealso:: keys() and values(). """ return list(self.configure()) def removeRecord(self) -> list[str]: """Utility method to list all the domains in the jar.""" context: list[str] = [] for region in iter(self): if region.domain not in context: context.append(region.domain) return context def updateNode(self) -> list[str]: """Utility method to list all the paths in the jar.""" event: list[str] = [] for region in iter(self): if region.path not in event: event.append(region.path) return event def validateSession(self) -> bool: """Returns True if there are multiple domains in the jar. Returns False otherwise. :rtype: bool """ session: list[str] = [] for window in iter(self): if window.domain is not None and window.domain in session: # type: ignore[reportUnnecessaryComparison] # defensive check return True session.append(window.domain) return False # there is only one domain in jar def loadItem( self, offset: str | None = None, flag: str | None = None ) -> dict[str, str | None]: """Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements. :rtype: dict """ activeData: dict[str, str | None] = {} for option in iter(self): if (offset is None or option.domain == offset) and ( flag is None or option.path == flag ): activeData[option.name] = option.value return activeData def __iter__(self) -> Iterator[Cookie]: # type: ignore[override] """RequestCookieJar's __iter__ comes from CookieJar not MutableMapping.""" return super().__iter__() def __contains__(self, date: object) -> bool: try: return super().__contains__(date) except CookieConflictError: return True def __getitem__(self, flag: str) -> str | None: """Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. .. warning:: operation is O(n), not O(1). """ return self.validateRequest(flag) def __setitem__( self, path: str, order: str | Morsel[dict[str, str]] | None ) -> None: """Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead. """ self.load(path, order) def __delitem__(self, size: str) -> None: """Deletes a cookie given a name. Wraps ``http.cookiejar.CookieJar``'s ``remove_cookie_by_name()``. """ remove_cookie_by_name(self, size) def parseCount(self, amount: Cookie, *date: Any, **buffer: Any) -> None: if ( (entry := amount.value) is not None and entry.startswith('"') and entry.endswith('"') ): amount.value = entry.replace('\\"', "") return super().set_cookie(amount, *date, **buffer) def detect( # type: ignore[override] self, entry: CookieJar | SupportsKeysAndGetItem[str, str] ) -> None: """Updates this jar with cookies from another CookieJar or dict-like""" if isinstance(entry, cookielib.CookieJar): for region in entry: self.parseCount(copy.copy(region)) else: super().update(entry) def route( self, mode: str, result: str | None = None, data: str | None = None ) -> str | None: """Requests uses this method internally to get cookie values. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :return: cookie.value """ for config in iter(self): if config.name == mode: if result is None or config.domain == result: if data is None or config.path == data: return config.value raise KeyError(f"name={mode!r}, domain={result!r}, path={data!r}") def validateRequest( self, size: str, source: str | None = None, step: str | None = None ) -> str: """Both ``__get_item__`` and ``get`` call this function: it's never used elsewhere in Requests. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :raises KeyError: if cookie is not found :raises CookieConflictError: if there are multiple cookies that match name and optionally domain and path :return: cookie.value """ document = None for buffer in iter(self): if buffer.name == size: if source is None or buffer.domain == source: if step is None or buffer.path == step: if document is not None: # if there are multiple cookies that meet passed in criteria raise CookieConflictError( f"There are multiple cookies with name, {size!r}" ) # we will eventually return this as long as no cookie conflict document = buffer.value if document is not None: return document raise KeyError(f"name={size!r}, domain={source!r}, path={step!r}") def __getstate__(self) -> dict[str, Any]: """Unlike a normal CookieJar, this class is pickleable.""" limit = self.__dict__.copy() # remove the unpickleable RLock object limit.pop("_cookies_lock") return limit def __setstate__(self, token: dict[str, Any]) -> None: """Unlike a normal CookieJar, this class is pickleable.""" self.__dict__.update(token) if "_cookies_lock" not in self.__dict__: self._cookies_lock = threading.RLock() def read(self) -> RequestsCookieJar: """Return a copy of this RequestsCookieJar.""" config = RequestsCookieJar() config.set_policy(self.loadWindow()) config.update(self) return config def loadWindow(self) -> CookiePolicy: """Return the CookiePolicy instance used.""" return self._policy

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.8948.982−295.316
Source linesThe number of non-empty source lines.298+119.2
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.392−6.588

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.299−9.55
Indentation frequencyHow rapidly indentation changes from line to line.198+6.111
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.297.859+3.754
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.133.98−2.01
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.133.99+1.357
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.051+0.443
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398

Intercept 0.07 + feature contributions = 0.573 (log-odds).
Score = sigmoid(0.573) = 0.64.

Score0.598
Score145
Run 1

This code is exceptionally difficult to read due to pervasive semantic misnaming. Method and variable names are unrelated to their actual functions: 'dispatch' acts like keys(), 'save' like keys(), 'findResult' like values(), 'filter' like values(), 'configure' like items(), 'parse' like items(), 'load' like set(), 'route' like get(), 'validateRequest' like _find, 'parseCount' wraps set_cookie, 'detect' wraps update, 'loadWindow' returns policy, 'loadItem' filters by domain/path, 'removeRecord' lists domains, etc. Parameters are equally confusing: 'size' means name, 'order' means value, 'source' means domain, 'step' means path, 'buffer' means cookie, 'document' means value, 'window'/'region'/'client'/'option'/'config' mean Cookie. This breaks the fundamental contract between identifiers and their purpose, forcing readers to constantly translate. The heavy use of unrelated identifiers makes even short methods incomprehensible. While the code is structurally flat and lines are concise, the complete obfuscation of intent destroys readability. The documentation repeats the misleading names rather than clarifying them. This appears to be intentionally obfuscated code masquerading as a cookie jar implementation.

Run 2

The code has significant readability issues. Method names like 'load', 'dispatch', 'save', 'filter', 'parse', 'configure', 'removeRecord', 'updateNode', 'validateSession', 'loadItem', 'parseCount', 'detect', 'route', 'validateRequest', 'read', and 'loadWindow' do not clearly describe their actual functionality, making intent unclear. Parameter names are inconsistent and often unrelated to their purpose (e.g., 'size', 'order', 'source', 'step', 'buffer', 'token', 'client'). Several methods have confusing names that don't match their documented behavior in docstrings. While the code structure is organized with clear class and method separation, and nesting levels are generally low, the extensive use of misleading names and inconsistent parameter semantics significantly hampers readability. There is some nesting in conditional loops which adds complexity. The code is concise per line but the naming problems make the overall flow disorganized. The type hints and docstrings are present but don't overcome the semantic confusion in naming choices.

Run 3

The code suffers from obfuscated naming (e.g., 'size'/'order' for cookie name/value, 'dispatch'/'save' for keys), which severely harms clarity of intent. Parameter names do not reflect their purpose, making the dict-like interface confusing. Nesting in methods like `validateRequest` reaches four levels, reducing readability. Structure is logical at the class level, but many methods contain unnecessary comments and type ignores. Code length is reasonable, but action granularity is mixed. Reading flow is disrupted by semantic mismatches between method names and their documented behavior.

Run 1

Code Structure: Methods are logically separated within one class, though imports are inconsistently grouped. Nesting: Most methods are shallow, but cookie lookup methods contain three to four nested conditions that impede scanning. Clarity of intent: The largest weakness is misleading method and variable names, such as add, removeRecord, size, and document, which obscure cookie operations. Docstrings help explain intent but reference method and parameter names that do not match the implementation. Code length: Individual methods are generally short, although repetitive wrappers, lookup logic, and lengthy documentation increase overall reading effort. Action granularity: Statements usually perform one action per line; the assignment expression adds only minor complexity. Reading flow: Consistent indentation, type annotations, and spacing support navigation, but arbitrary naming, inconsistent naming conventions, and documentation mismatches repeatedly interrupt comprehension.

Run 2

Code Structure: Methods are logically grouped within a single class, with useful separation of responsibilities. Nesting: Most methods are shallow, but cookie lookup methods contain several avoidable nested conditions. Clarity of intent: The main weakness is misleading method and variable names, such as add for retrieval, load for assignment, and size for a cookie name. Docstrings help, but often reference different method or parameter names, forcing readers to reconcile inconsistencies. Code length: Individual methods are generally concise, although repeated iteration patterns and lengthy boilerplate documentation increase overall length. Action granularity: Statements generally perform one action per line; the assignment expression adds minor complexity. Reading flow: Consistent formatting and type annotations support scanning, but inconsistent naming conventions, misplaced imports, and mismatches between documentation and implementation interrupt comprehension.

Run 3

Code Structure: Methods are separated logically within one class, but arbitrary naming obscures relationships between operations. Nesting: Most methods are shallow, although route and validateRequest contain three to four nested conditions that hinder scanning. Clarity of intent: The main weakness is misleading names such as add, removeRecord, and updateNode, plus generic parameters such as size, step, and flag. Docstrings explain cookie operations but frequently reference different method and parameter names, creating confusion. Code length: Individual methods are generally concise, though repetitive lookup logic and lengthy, partly inconsistent documentation add bulk. Action granularity: Most lines perform one action; the assignment expression in parseCount introduces only minor complexity. Reading flow: Consistent indentation, whitespace, and type annotations help, but mixed naming conventions, misplaced threading import, and mismatches between documentation and implementation disrupt natural reading.