summaryrefslogtreecommitdiff
path: root/django/http
diff options
context:
space:
mode:
authorNatalia <124304+nessita@users.noreply.github.com>2025-06-09 09:59:11 -0300
committernessita <124304+nessita@users.noreply.github.com>2025-06-09 17:37:40 -0300
commitcf5f36bf903a2854f5e395149cee707115b83744 (patch)
tree3d6aca3c5eda1a4f58079c1ce1b76d7d4c478069 /django/http
parent8fd21b0da35697591e86f4eab0035c4360a45144 (diff)
Fixed #36446 -- Restored "q" in internal MediaType.params property.
The "q" key was removed while addressing ticket #36411. Despite `MediaType.params` is undocumented and considered internal, it was used in third-party projects (Zulip reported breakage), so this work restored the `q` key in `params`. Thanks Anders Kaseorg for the report. Regression in c075508b4de8edf9db553b409f8a8ed2f26ecead.
Diffstat (limited to 'django/http')
-rw-r--r--django/http/request.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/django/http/request.py b/django/http/request.py
index 6438f26268..c26a4954d1 100644
--- a/django/http/request.py
+++ b/django/http/request.py
@@ -694,13 +694,13 @@ class QueryDict(MultiValueDict):
class MediaType:
def __init__(self, media_type_raw_line):
- full_type, self._params = parse_header_parameters(
+ full_type, self.params = parse_header_parameters(
media_type_raw_line if media_type_raw_line else ""
)
self.main_type, _, self.sub_type = full_type.partition("/")
def __str__(self):
- params_str = "".join("; %s=%s" % (k, v) for k, v in self._params.items())
+ params_str = "".join("; %s=%s" % (k, v) for k, v in self.params.items())
return "%s%s%s" % (
self.main_type,
("/%s" % self.sub_type) if self.sub_type else "",
@@ -711,8 +711,8 @@ class MediaType:
return "<%s: %s>" % (self.__class__.__qualname__, self)
@cached_property
- def params(self):
- params = self._params.copy()
+ def range_params(self):
+ params = self.params.copy()
params.pop("q", None)
return params
@@ -735,20 +735,19 @@ class MediaType:
if this_type != other_type and this_type != "*" and other_type != "*":
return False
- if bool(self.params) == bool(other.params):
+ if bool(self.range_params) == bool(other.range_params):
# If both have params or neither have params, they must be identical.
- result = self.params == other.params
+ result = self.range_params == other.range_params
else:
# If self has params and other does not, it's a match.
# If other has params and self does not, don't match.
- result = bool(self.params or not other.params)
-
+ result = bool(self.range_params or not other.range_params)
return result
@cached_property
def quality(self):
try:
- quality = float(self._params.get("q", 1))
+ quality = float(self.params.get("q", 1))
except ValueError:
# Discard invalid values.
return 1
@@ -768,7 +767,7 @@ class MediaType:
return 0
elif self.sub_type == "*":
return 1
- elif not self.params:
+ elif not self.range_params:
return 2
return 3