Sample

pyint-84663f94d90d-I04

Replace names with deterministic minifier-style shortest identifiers

Matched original source

Lines115

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5230–1; higher is more readable
Mi0.4430–1; higher is more readable
LLOC49Logical lines; fewer is more readable
DeepSeek V4 Pro6.670–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.1740–1; higher is more readable

Views

Source code

import re from urllib.parse import urlsplit from django.conf import settings from django.core.exceptions import PermissionDenied from django.core.mail import MailerDoesNotExist, mail_managers, mailers from django.http import HttpResponsePermanentRedirect from django.middleware import MiddlewareMixin from django.urls import is_valid_path from django.utils.http import escape_leading_slashes class CommonMiddleware(MiddlewareMixin): """ "Common" middleware for taking care of some basic operations: - Forbid access to User-Agents in settings.DISALLOWED_USER_AGENTS - URL rewriting: Based on the APPEND_SLASH and PREPEND_WWW settings, append missing slashes and/or prepends missing "www."s. - If APPEND_SLASH is set and the initial URL doesn't end with a slash, and it is not found in urlpatterns, form a new URL by appending a slash at the end. If this new URL is found in urlpatterns, return an HTTP redirect to this new URL; otherwise process the initial URL as usual. This behavior can be customized by subclassing CommonMiddleware and overriding the response_redirect_class attribute. """ response_redirect_class = HttpResponsePermanentRedirect def a(self, e): """ Check for denied User-Agents and rewrite the URL based on settings.APPEND_SLASH and settings.PREPEND_WWW """ # Check for denied User-Agents f = e.META.get("HTTP_USER_AGENT") if f is not None: for g in settings.DISALLOWED_USER_AGENTS: if g.search(f): raise PermissionDenied("Forbidden user agent") # Check for a redirect based on settings.PREPEND_WWW h = e.get_host() if settings.PREPEND_WWW and h and not h.startswith("www."): # Check if we also need to append a slash so we can do it all # with a single redirect. (This check may be somewhat expensive, # so we only do it if we already know we're sending a redirect, # or in process_response if we get a 404.) if self.b(e): i = self.c(e) else: i = e.get_full_path() return self.response_redirect_class(f"{e.scheme}://www.{h}{i}") def b(self, j): """ Return True if settings.APPEND_SLASH is True and appending a slash to the request path turns an invalid path into a valid one. """ if settings.APPEND_SLASH and not j.path_info.endswith("/"): k = getattr(j, "urlconf", None) if not is_valid_path(j.path_info, k): l = is_valid_path("%s/" % j.path_info, k) if l: m = l.func return getattr(m, "should_append_slash", True) return False def c(self, n): """ Return the full path of the request with a trailing slash appended. Raise a RuntimeError if settings.DEBUG is True and request.method is DELETE, POST, PUT, or PATCH. """ o = n.get_full_path(force_append_slash=True) # Prevent construction of scheme relative urls. o = escape_leading_slashes(o) if settings.DEBUG and n.method in ("DELETE", "POST", "PUT", "PATCH"): raise RuntimeError( "You called this URL via %(method)s, but the URL doesn't end " "in a slash and you have APPEND_SLASH set. Django can't " "redirect to the slash URL while maintaining %(method)s data. " "Change your form to point to %(url)s (note the trailing " "slash), or set APPEND_SLASH=False in your Django settings." % { "method": n.method, "url": n.get_host() + o, } ) return o def d(self, p, q): """ When the status code of the response is 404, it may redirect to a path with an appended slash if should_redirect_with_slash() returns True. """ # If the given URL is "Not Found", then check if we should redirect to # a path with a slash appended. if q.status_code == 404 and self.b(p): q = self.response_redirect_class( self.c(p) ) # Add the Content-Length header to non-streaming responses if not # already set. if not q.streaming and not q.has_header("Content-Length"): q.headers["Content-Length"] = str(len(q.content)) return q

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.2691.438−88.817
Source linesThe number of non-empty source lines.115+46
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.461−6.692

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.116−3.071
Indentation frequencyHow rapidly indentation changes from line to line.74+1.822
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.74−1.277
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.114.912+1.196
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.035+0.606
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.76.224+0.425
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.78.966+0.321

Intercept 0.07 + feature contributions = 0.093 (log-odds).
Score = sigmoid(0.093) = 0.523.

Score0.443
Score49
Run 1

The code structure is intact but readability is severely undermined by obfuscated naming. Methods and variables are named 'a', 'b', 'c', 'd', 'e', 'f', 'g', etc., completely hiding their intent (e.g., detecting user agents or appending slashes). This violates Clarity of intent. Nesting is shallow and reading flow is functional, but the meaningless names force the reader to reverse-engineer the logic from the code. Action granularity is acceptable, though some lines are dense (regex search, ternary-like if/else). The docstrings are the only thing preventing total unreadability, but they fight against the vague identifiers. Overall, the code appears to be intentionally obfuscated.

Run 2

This code has been deliberately obfuscated, making it nearly unreadable despite its mostly logical structure. The function names (a, b, c, d) and variable names (e, f, g, h, i, j, k, l, m, n, o, p, q) are completely meaningless, destroying clarity of intent. While the code structure and nesting are reasonable—there are no deeply nested blocks, and each line performs one main action—the lack of descriptive naming makes it impossible to understand the purpose without reading every line carefully. The docstrings are the only clue to functionality, but they use different descriptions than the actual code. The reading flow is disrupted because readers must constantly map meaningless names to concepts. Code length is appropriate for the operations performed. This would normally be a well-structured Django middleware class, but the obfuscated identifiers drop the score dramatically. A version with clear names would score 16-18.

Run 3

The original Django middleware pattern is recognizable, but obfuscated variable names (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) make the code extremely difficult to follow. The class-level docstring is well-written, but method-level docstrings are paired with meaningless names, forcing readers to constantly map letters to actual concepts. This severely damages clarity of intent and reading flow. Code structure follows a logical middleware flow, but nesting is moderate due to conditionals. Action granularity is acceptable, with roughly one action per line. Code length is reasonable for the functionality. While the underlying logic is not tangled, the naming choices make it read like minified or obfuscated code rather than maintainable source, hence a low score despite correct structure and moderate length.

Run 1

Code Structure: Responsibilities are logically separated into methods for request checks, slash validation, URL construction, and response handling. Nesting: Mostly moderate, but user-agent checks and slash validation reach three nested levels. Clarity of intent: Detailed docstrings and comments explain behavior, but single-letter method and variable names severely obscure meaning and require constant cross-referencing. Docstrings also reference descriptive method names absent from the implementation. Code length: Generally reasonable, though extensive documentation, unused imports, and an unnecessarily split redirect assignment add clutter. Action granularity: Statements generally perform one action per line, with readable multiline error construction. Reading flow: Methods follow a sensible request-to-response progression, but opaque helper calls interrupt comprehension. Overall, strong organization and documentation partially compensate for poor naming.

Run 2

Code Structure: Responsibilities are logically separated into methods for request checks, slash validation, path construction, and response processing. Nesting: Mostly manageable, but user-agent checks and slash validation reach three nested levels. Clarity of intent: Detailed docstrings and comments explain behavior, but single-letter method and variable names obscure roles and make cross-method calls difficult to follow; documentation also references names absent from the code. Code length: Generally proportionate to functionality, though lengthy documentation, an error message, unused imports, and an unnecessarily split redirect call add reading overhead. Action granularity: Most lines perform one clear action, with sensible separation of validation and transformation steps. Reading flow: The request-to-response sequence is natural, but opaque identifiers force readers to repeatedly consult documentation and trace values.

Run 3

Code Structure: Responsibilities are logically separated into methods within a middleware class. Nesting: Mostly moderate, but user-agent checks and slash validation use several nested branches. Clarity of intent: Docstrings and comments explain behavior well, but single-letter method and variable names obscure roles and make cross-method calls difficult to follow; documentation also references names absent from the code. Code length: Generally reasonable, although lengthy documentation, an unnecessarily multiline redirect call, and unused imports add clutter. Action granularity: Statements generally perform one action per line, with readable formatting for conditions and error construction. Reading flow: The request-check, path-validation, redirect-construction, and response-handling sequence is coherent, but opaque identifiers require repeatedly consulting documentation to understand data flow.