summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2025-07-22 20:41:41 -0700
committernessita <124304+nessita@users.noreply.github.com>2025-07-23 20:17:55 -0300
commit69a93a88edb56ba47f624dac7a21aacc47ea474f (patch)
treef57507a4435d032493cae40e06ecb254790b67b2 /django/utils
parent55b0cc21310b76ce4018dd793ba50556eaf0af06 (diff)
Refs #36500 -- Rewrapped long docstrings and block comments via a script.
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/_os.py3
-rw-r--r--django/utils/autoreload.py5
-rw-r--r--django/utils/cache.py3
-rw-r--r--django/utils/csp.py12
-rw-r--r--django/utils/dateformat.py13
-rw-r--r--django/utils/decorators.py4
-rw-r--r--django/utils/feedgenerator.py18
-rw-r--r--django/utils/html.py10
-rw-r--r--django/utils/http.py8
-rw-r--r--django/utils/module_loading.py4
-rw-r--r--django/utils/termcolors.py6
-rw-r--r--django/utils/timesince.py3
-rw-r--r--django/utils/translation/trans_real.py15
-rw-r--r--django/utils/xmlutils.py4
14 files changed, 64 insertions, 44 deletions
diff --git a/django/utils/_os.py b/django/utils/_os.py
index e9e1bcbfaf..5cd8c566a8 100644
--- a/django/utils/_os.py
+++ b/django/utils/_os.py
@@ -22,7 +22,8 @@ def safe_join(base, *paths):
# a) The next character is the path separator (to prevent conditions like
# safe_join("/dir", "/../d"))
# b) The final path must be the same as the base path.
- # c) The base path must be the most root path (meaning either "/" or "C:\\")
+ # c) The base path must be the most root path (meaning either "/" or
+ # "C:\\")
if (
not normcase(final_path).startswith(normcase(base_path + sep))
and normcase(final_path) != normcase(base_path)
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index a620d0adb7..c6716215f5 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -468,8 +468,9 @@ class WatchmanReloader(BaseReloader):
def _subscribe(self, directory, name, expression):
root, rel_path = self._watch_root(directory)
- # Only receive notifications of files changing, filtering out other types
- # like special files: https://facebook.github.io/watchman/docs/type
+ # Only receive notifications of files changing, filtering out other
+ # types like special files:
+ # https://facebook.github.io/watchman/docs/type
only_files_expression = [
"allof",
["anyof", ["type", "f"], ["type", "l"]],
diff --git a/django/utils/cache.py b/django/utils/cache.py
index 3b014fbe51..f2cbd1d033 100644
--- a/django/utils/cache.py
+++ b/django/utils/cache.py
@@ -207,7 +207,8 @@ def get_conditional_response(request, etag=None, last_modified=None, response=No
return _not_modified(request, response)
# Step 5: Test the If-Range precondition (not supported).
- # Step 6: Return original response since there isn't a conditional response.
+ # Step 6: Return original response since there isn't a conditional
+ # response.
return response
diff --git a/django/utils/csp.py b/django/utils/csp.py
index b989a47c23..d57fc98995 100644
--- a/django/utils/csp.py
+++ b/django/utils/csp.py
@@ -9,7 +9,8 @@ class CSP(StrEnum):
Content Security Policy constants for directive values and special tokens.
These constants represent:
- 1. Standard quoted string values from the CSP spec (e.g., 'self', 'unsafe-inline')
+ 1. Standard quoted string values from the CSP spec (e.g., 'self',
+ 'unsafe-inline')
2. Special placeholder tokens (NONCE) that get replaced by the middleware
Using this enum instead of raw strings provides better type checking,
@@ -43,13 +44,15 @@ class CSP(StrEnum):
WASM_UNSAFE_EVAL = "'wasm-unsafe-eval'"
# Special placeholder that gets replaced by the middleware.
- # The value itself is arbitrary and should not be mistaken for a real nonce.
+ # The value itself is arbitrary and should not be mistaken for a real
+ # nonce.
NONCE = "<CSP_NONCE_SENTINEL>"
class LazyNonce(SimpleLazyObject):
"""
- Lazily generates a cryptographically secure nonce string, for use in CSP headers.
+ Lazily generates a cryptographically secure nonce string, for use in CSP
+ headers.
The nonce is only generated when first accessed (e.g., via string
interpolation or inside a template).
@@ -62,7 +65,8 @@ class LazyNonce(SimpleLazyObject):
<script{% if csp_nonce %} nonce="{{ csp_nonce }}"...{% endif %}>
- The `{% if %}` block will only render if the nonce has been evaluated elsewhere.
+ The `{% if %}` block will only render if the nonce has been evaluated
+ elsewhere.
"""
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index 4a158432d9..94a1e8595a 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -144,10 +144,10 @@ class TimeFormat(Formatter):
def P(self):
"""
- Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off
- if they're zero and the strings 'midnight' and 'noon' if appropriate.
- Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
- Proprietary extension.
+ Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left
+ off if they're zero and the strings 'midnight' and 'noon' if
+ appropriate. Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon',
+ '12:30 p.m.' Proprietary extension.
"""
if self.data.minute == 0 and self.data.hour == 0:
return _("midnight")
@@ -216,7 +216,10 @@ class DateFormat(TimeFormat):
return WEEKDAYS_ABBR[self.data.weekday()]
def E(self):
- "Alternative month names as required by some locales. Proprietary extension."
+ """
+ Alternative month names as required by some locales. Proprietary
+ extension.
+ """
return MONTHS_ALT[self.data.month]
def F(self):
diff --git a/django/utils/decorators.py b/django/utils/decorators.py
index fb12c7fbcd..83586dfc2c 100644
--- a/django/utils/decorators.py
+++ b/django/utils/decorators.py
@@ -150,8 +150,8 @@ def make_middleware_decorator(middleware_class):
response = middleware.process_template_response(
request, response
)
- # Defer running of process_response until after the template
- # has been rendered:
+ # Defer running of process_response until after the
+ # template has been rendered:
if hasattr(middleware, "process_response"):
def callback(response):
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index e52720a61e..a9eaffc205 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -65,9 +65,10 @@ def _guess_stylesheet_mimetype(url):
"""
mimetypedb = mimetypes.MimeTypes()
- # The official mimetype for XSLT files is technically `application/xslt+xml`
- # but as of 2024 almost no browser supports that (they all expect text/xsl).
- # On top of that, windows seems to assume that the type for xsl is text/xml.
+ # The official mimetype for XSLT files is technically
+ # `application/xslt+xml` but as of 2024 almost no browser supports that
+ # (they all expect text/xsl). On top of that, windows seems to assume that
+ # the type for xsl is text/xml.
mimetypedb.readfp(StringIO("text/xsl\txsl\ntext/xsl\txslt"))
return mimetypedb.guess_type(url)
@@ -215,8 +216,8 @@ class SyndicationFeed:
def root_attributes(self):
"""
- Return extra attributes to place on the root (i.e. feed/channel) element.
- Called from write().
+ Return extra attributes to place on the root (i.e. feed/channel)
+ element. Called from write().
"""
return {}
@@ -235,7 +236,8 @@ class SyndicationFeed:
def item_attributes(self, item):
"""
- Return extra attributes to place on each item (i.e. item/entry) element.
+ Return extra attributes to place on each item (i.e. item/entry)
+ element.
"""
return {}
@@ -295,8 +297,8 @@ class RssFeed(SyndicationFeed):
def write(self, outfile, encoding):
handler = SimplerXMLGenerator(outfile, encoding, short_empty_elements=True)
handler.startDocument()
- # Any stylesheet must come after the start of the document but before any tag.
- # https://www.w3.org/Style/styling-XML.en.html
+ # Any stylesheet must come after the start of the document but before
+ # any tag. https://www.w3.org/Style/styling-XML.en.html
self.add_stylesheets(handler)
handler.startElement("rss", self.rss_attributes())
handler.startElement("channel", self.root_attributes())
diff --git a/django/utils/html.py b/django/utils/html.py
index 56435eb7e2..d3b904a822 100644
--- a/django/utils/html.py
+++ b/django/utils/html.py
@@ -256,8 +256,8 @@ def smart_urlquote(url):
netloc = unquote_quote(netloc)
if query:
- # Separately unquoting key/value, so as to not mix querystring separators
- # included in query values. See #22267.
+ # Separately unquoting key/value, so as to not mix querystring
+ # separators included in query values. See #22267.
query_parts = [
(unquote(q[0]), unquote(q[1]))
for q in parse_qsl(query, keep_blank_values=True)
@@ -352,7 +352,8 @@ class Urlizer:
url = smart_urlquote(html.unescape(middle))
elif len(middle) <= MAX_URL_LENGTH and self.simple_url_2_re.match(middle):
unescaped_middle = html.unescape(middle)
- # RemovedInDjango70Warning: When the deprecation ends, replace with:
+ # RemovedInDjango70Warning: When the deprecation ends, replace
+ # with:
# url = smart_urlquote(f"https://{unescaped_middle}")
protocol = (
"https"
@@ -462,7 +463,8 @@ class Urlizer:
trail_start = len(rstripped)
amount_trailing_semicolons = len(middle) - len(middle.rstrip(";"))
if amp > -1 and amount_trailing_semicolons > 1:
- # Leave up to most recent semicolon as might be an entity.
+ # Leave up to most recent semicolon as might be an
+ # entity.
recent_semicolon = middle[trail_start:].index(";")
middle_semicolon_index = recent_semicolon + trail_start + 1
trail = middle[middle_semicolon_index:] + trail
diff --git a/django/utils/http.py b/django/utils/http.py
index 1c7aec7141..504f28c678 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -284,10 +284,10 @@ def _url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False):
url_info = urlsplit(url)
except ValueError: # e.g. invalid IPv6 addresses
return False
- # Forbid URLs like http:///example.com - with a scheme, but without a hostname.
- # In that URL, example.com is not the hostname but, a path component. However,
- # Chrome will still consider example.com to be the hostname, so we must not
- # allow this syntax.
+ # Forbid URLs like http:///example.com - with a scheme, but without a
+ # hostname. In that URL, example.com is not the hostname but, a path
+ # component. However, Chrome will still consider example.com to be the
+ # hostname, so we must not allow this syntax.
if not url_info.netloc and url_info.scheme:
return False
# Forbid URLs that start with control characters. Some browsers (like
diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py
index cb579e7f8c..28067e8d89 100644
--- a/django/utils/module_loading.py
+++ b/django/utils/module_loading.py
@@ -18,8 +18,8 @@ def cached_import(module_path, class_name):
def import_string(dotted_path):
"""
- Import a dotted module path and return the attribute/class designated by the
- last name in the path. Raise ImportError if the import failed.
+ Import a dotted module path and return the attribute/class designated by
+ the last name in the path. Raise ImportError if the import failed.
"""
try:
module_path, class_name = dotted_path.rsplit(".", 1)
diff --git a/django/utils/termcolors.py b/django/utils/termcolors.py
index 3d1eee6e41..aeef02f1b0 100644
--- a/django/utils/termcolors.py
+++ b/django/utils/termcolors.py
@@ -154,9 +154,9 @@ def parse_color_setting(config_string):
bg is a background color.
option is a display options.
- Specifying a named palette is the same as manually specifying the individual
- definitions for each role. Any individual definitions following the palette
- definition will augment the base palette definition.
+ Specifying a named palette is the same as manually specifying the
+ individual definitions for each role. Any individual definitions following
+ the palette definition will augment the base palette definition.
Valid roles:
'error', 'success', 'warning', 'notice', 'sql_field', 'sql_coltype',
diff --git a/django/utils/timesince.py b/django/utils/timesince.py
index a61b02d94d..e6d5b194ac 100644
--- a/django/utils/timesince.py
+++ b/django/utils/timesince.py
@@ -137,6 +137,7 @@ def timesince(d, now=None, reversed=False, time_strings=None, depth=2):
def timeuntil(d, now=None, time_strings=None, depth=2):
"""
- Like timesince, but return a string measuring the time until the given time.
+ Like timesince, but return a string measuring the time until the given
+ time.
"""
return timesince(d, now, reversed=True, time_strings=time_strings, depth=depth)
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 86fe823bf7..abc1477442 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -103,7 +103,8 @@ class TranslationCatalog:
yield from cat.keys()
def update(self, trans):
- # Merge if plural function is the same as the top catalog, else prepend.
+ # Merge if plural function is the same as the top catalog, else
+ # prepend.
if trans.plural.__code__ == self._plurals[0]:
self._catalogs[0].update(trans._catalog)
else:
@@ -154,7 +155,8 @@ class DjangoTranslation(gettext_module.GNUTranslations):
if self.domain == "django":
if localedirs is not None:
- # A module-level cache is used for caching 'django' translations
+ # A module-level cache is used for caching 'django'
+ # translations
warnings.warn(
"localedirs is ignored when domain is 'django'.", RuntimeWarning
)
@@ -253,7 +255,8 @@ class DjangoTranslation(gettext_module.GNUTranslations):
if not getattr(other, "_catalog", None):
return # NullTranslations() has no _catalog
if self._catalog is None:
- # Take plural and _info from first catalog found (generally Django's).
+ # Take plural and _info from first catalog found (generally
+ # Django's).
self.plural = other.plural
self._info = other._info.copy()
self._catalog = TranslationCatalog(other)
@@ -329,7 +332,8 @@ def get_language():
return t.to_language()
except AttributeError:
pass
- # If we don't have a real translation object, assume it's the default language.
+ # If we don't have a real translation object, assume it's the default
+ # language.
return settings.LANGUAGE_CODE
@@ -511,7 +515,8 @@ def get_supported_language_variant(lang_code, strict=False):
not strict
and (index := lang_code.rfind("-", 0, LANGUAGE_CODE_MAX_LENGTH)) > 0
):
- # There is a generic variant under the maximum length accepted length.
+ # There is a generic variant under the maximum length accepted
+ # length.
lang_code = lang_code[:index]
else:
raise LookupError(lang_code)
diff --git a/django/utils/xmlutils.py b/django/utils/xmlutils.py
index c3eb3ba6a3..5c65e580ed 100644
--- a/django/utils/xmlutils.py
+++ b/django/utils/xmlutils.py
@@ -22,8 +22,8 @@ class SimplerXMLGenerator(XMLGenerator):
def characters(self, content):
if content and re.search(r"[\x00-\x08\x0B-\x0C\x0E-\x1F]", content):
- # Fail loudly when content has control chars (unsupported in XML 1.0)
- # See https://www.w3.org/International/questions/qa-controls
+ # Fail loudly when content has control chars (unsupported in XML
+ # 1.0) See https://www.w3.org/International/questions/qa-controls
raise UnserializableContentError(
"Control characters are not supported in XML 1.0"
)