This commit is contained in:
2025-05-22 21:22:15 +02:00
parent 3d57f842f9
commit 97cb9c8703
156 changed files with 1205 additions and 6603 deletions

View File

@@ -2,7 +2,6 @@ from __future__ import annotations
import re
import typing as t
import warnings
from datetime import datetime
from .._internal import _dt_as_utc
@@ -123,8 +122,6 @@ def _cookie_unslash_replace(m: t.Match[bytes]) -> bytes:
def parse_cookie(
cookie: str | None = None,
charset: str | None = None,
errors: str | None = None,
cls: type[ds.MultiDict] | None = None,
) -> ds.MultiDict[str, str]:
"""Parse a cookie from a string.
@@ -138,42 +135,14 @@ def parse_cookie(
:param cls: A dict-like class to store the parsed cookies in.
Defaults to :class:`MultiDict`.
.. versionchanged:: 2.3
Passing bytes, and the ``charset`` and ``errors`` parameters, are deprecated and
will be removed in Werkzeug 3.0.
.. versionchanged:: 3.0
Passing bytes, and the ``charset`` and ``errors`` parameters, were removed.
.. versionadded:: 2.2
"""
if cls is None:
cls = ds.MultiDict
if isinstance(cookie, bytes):
warnings.warn(
"The 'cookie' parameter must be a string. Passing bytes is deprecated and"
" will not be supported in Werkzeug 3.0.",
DeprecationWarning,
stacklevel=2,
)
cookie = cookie.decode()
if charset is not None:
warnings.warn(
"The 'charset' parameter is deprecated and will be removed in Werkzeug 3.0",
DeprecationWarning,
stacklevel=2,
)
else:
charset = "utf-8"
if errors is not None:
warnings.warn(
"The 'errors' parameter is deprecated and will be removed in Werkzeug 3.0",
DeprecationWarning,
stacklevel=2,
)
else:
errors = "replace"
if not cookie:
return cls()
@@ -191,7 +160,7 @@ def parse_cookie(
# Work with bytes here, since a UTF-8 character could be multiple bytes.
cv = _cookie_unslash_re.sub(
_cookie_unslash_replace, cv[1:-1].encode()
).decode(charset, errors)
).decode(errors="replace")
out.append((ck, cv))