lol
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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))
|
||||
|
||||
|
||||
@@ -251,12 +251,20 @@ class MultipartDecoder:
|
||||
else:
|
||||
data_start = 0
|
||||
|
||||
if self.buffer.find(b"--" + self.boundary) == -1:
|
||||
boundary = b"--" + self.boundary
|
||||
|
||||
if self.buffer.find(boundary) == -1:
|
||||
# No complete boundary in the buffer, but there may be
|
||||
# a partial boundary at the end. As the boundary
|
||||
# starts with either a nl or cr find the earliest and
|
||||
# return up to that as data.
|
||||
data_end = del_index = self.last_newline(data[data_start:]) + data_start
|
||||
# If amount of data after last newline is far from
|
||||
# possible length of partial boundary, we should
|
||||
# assume that there is no partial boundary in the buffer
|
||||
# and return all pending data.
|
||||
if (len(data) - data_end) > len(b"\n" + boundary):
|
||||
data_end = del_index = len(data)
|
||||
more_data = True
|
||||
else:
|
||||
match = self.boundary_re.search(data)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import typing as t
|
||||
import warnings
|
||||
from datetime import datetime
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
@@ -59,95 +58,13 @@ class Request:
|
||||
:param headers: The headers received with the request.
|
||||
:param remote_addr: The address of the client sending the request.
|
||||
|
||||
.. versionchanged:: 3.0
|
||||
The ``charset``, ``url_charset``, and ``encoding_errors`` attributes
|
||||
were removed.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
"""
|
||||
|
||||
_charset: str
|
||||
|
||||
@property
|
||||
def charset(self) -> str:
|
||||
"""The charset used to decode body, form, and cookie data. Defaults to UTF-8.
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0. Request data must always be UTF-8.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'charset' attribute is deprecated and will not be used in Werkzeug"
|
||||
" 2.4. Interpreting bytes as text in body, form, and cookie data will"
|
||||
" always use UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self._charset
|
||||
|
||||
@charset.setter
|
||||
def charset(self, value: str) -> None:
|
||||
warnings.warn(
|
||||
"The 'charset' attribute is deprecated and will not be used in Werkzeug"
|
||||
" 2.4. Interpreting bytes as text in body, form, and cookie data will"
|
||||
" always use UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._charset = value
|
||||
|
||||
_encoding_errors: str
|
||||
|
||||
@property
|
||||
def encoding_errors(self) -> str:
|
||||
"""How errors when decoding bytes are handled. Defaults to "replace".
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'encoding_errors' attribute is deprecated and will not be used in"
|
||||
" Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self._encoding_errors
|
||||
|
||||
@encoding_errors.setter
|
||||
def encoding_errors(self, value: str) -> None:
|
||||
warnings.warn(
|
||||
"The 'encoding_errors' attribute is deprecated and will not be used in"
|
||||
" Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._encoding_errors = value
|
||||
|
||||
_url_charset: str
|
||||
|
||||
@property
|
||||
def url_charset(self) -> str:
|
||||
"""The charset to use when decoding percent-encoded bytes in :attr:`args`.
|
||||
Defaults to the value of :attr:`charset`, which defaults to UTF-8.
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0. Percent-encoded bytes must always be UTF-8.
|
||||
|
||||
.. versionadded:: 0.6
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'url_charset' attribute is deprecated and will not be used in"
|
||||
" Werkzeug 3.0. Percent-encoded bytes must always be UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self._url_charset
|
||||
|
||||
@url_charset.setter
|
||||
def url_charset(self, value: str) -> None:
|
||||
warnings.warn(
|
||||
"The 'url_charset' attribute is deprecated and will not be used in"
|
||||
" Werkzeug 3.0. Percent-encoded bytes must always be UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._url_charset = value
|
||||
|
||||
#: the class to use for `args` and `form`. The default is an
|
||||
#: :class:`~werkzeug.datastructures.ImmutableMultiDict` which supports
|
||||
#: multiple values per key. alternatively it makes sense to use an
|
||||
@@ -209,40 +126,6 @@ class Request:
|
||||
headers: Headers,
|
||||
remote_addr: str | None,
|
||||
) -> None:
|
||||
if not isinstance(type(self).charset, property):
|
||||
warnings.warn(
|
||||
"The 'charset' attribute is deprecated and will not be used in Werkzeug"
|
||||
" 2.4. Interpreting bytes as text in body, form, and cookie data will"
|
||||
" always use UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._charset = self.charset
|
||||
else:
|
||||
self._charset = "utf-8"
|
||||
|
||||
if not isinstance(type(self).encoding_errors, property):
|
||||
warnings.warn(
|
||||
"The 'encoding_errors' attribute is deprecated and will not be used in"
|
||||
" Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._encoding_errors = self.encoding_errors
|
||||
else:
|
||||
self._encoding_errors = "replace"
|
||||
|
||||
if not isinstance(type(self).url_charset, property):
|
||||
warnings.warn(
|
||||
"The 'url_charset' attribute is deprecated and will not be used in"
|
||||
" Werkzeug 3.0. Percent-encoded bytes must always be UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._url_charset = self.url_charset
|
||||
else:
|
||||
self._url_charset = self._charset
|
||||
|
||||
#: The method the request was made with, such as ``GET``.
|
||||
self.method = method.upper()
|
||||
#: The URL scheme of the protocol the request used, such as
|
||||
@@ -291,7 +174,6 @@ class Request:
|
||||
parse_qsl(
|
||||
self.query_string.decode(),
|
||||
keep_blank_values=True,
|
||||
encoding=self._url_charset,
|
||||
errors="werkzeug.url_quote",
|
||||
)
|
||||
)
|
||||
@@ -360,13 +242,8 @@ class Request:
|
||||
"""A :class:`dict` with the contents of all cookies transmitted with
|
||||
the request."""
|
||||
wsgi_combined_cookie = ";".join(self.headers.getlist("Cookie"))
|
||||
charset = self._charset if self._charset != "utf-8" else None
|
||||
errors = self._encoding_errors if self._encoding_errors != "replace" else None
|
||||
return parse_cookie( # type: ignore
|
||||
wsgi_combined_cookie,
|
||||
charset=charset,
|
||||
errors=errors,
|
||||
cls=self.dict_storage_class,
|
||||
wsgi_combined_cookie, cls=self.dict_storage_class
|
||||
)
|
||||
|
||||
# Common Descriptors
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import typing as t
|
||||
import warnings
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from datetime import timezone
|
||||
@@ -81,36 +80,12 @@ class Response:
|
||||
:param content_type: The full content type of the response.
|
||||
Overrides building the value from ``mimetype``.
|
||||
|
||||
.. versionchanged:: 3.0
|
||||
The ``charset`` attribute was removed.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
"""
|
||||
|
||||
_charset: str
|
||||
|
||||
@property
|
||||
def charset(self) -> str:
|
||||
"""The charset used to encode body and cookie data. Defaults to UTF-8.
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0. Response data must always be UTF-8.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'charset' attribute is deprecated and will not be used in Werkzeug"
|
||||
" 2.4. Text in body and cookie data will always use UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self._charset
|
||||
|
||||
@charset.setter
|
||||
def charset(self, value: str) -> None:
|
||||
warnings.warn(
|
||||
"The 'charset' attribute is deprecated and will not be used in Werkzeug"
|
||||
" 2.4. Text in body and cookie data will always use UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._charset = value
|
||||
|
||||
#: the default status if none is provided.
|
||||
default_status = 200
|
||||
|
||||
@@ -139,17 +114,6 @@ class Response:
|
||||
mimetype: str | None = None,
|
||||
content_type: str | None = None,
|
||||
) -> None:
|
||||
if not isinstance(type(self).charset, property):
|
||||
warnings.warn(
|
||||
"The 'charset' attribute is deprecated and will not be used in Werkzeug"
|
||||
" 2.4. Text in body and cookie data will always use UTF-8.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._charset = self.charset
|
||||
else:
|
||||
self._charset = "utf-8"
|
||||
|
||||
if isinstance(headers, Headers):
|
||||
self.headers = headers
|
||||
elif not headers:
|
||||
@@ -161,7 +125,7 @@ class Response:
|
||||
if mimetype is None and "content-type" not in self.headers:
|
||||
mimetype = self.default_mimetype
|
||||
if mimetype is not None:
|
||||
mimetype = get_content_type(mimetype, self._charset)
|
||||
mimetype = get_content_type(mimetype, "utf-8")
|
||||
content_type = mimetype
|
||||
if content_type is not None:
|
||||
self.headers["Content-Type"] = content_type
|
||||
@@ -255,7 +219,6 @@ class Response:
|
||||
:param samesite: Limit the scope of the cookie to only be
|
||||
attached to requests that are "same-site".
|
||||
"""
|
||||
charset = self._charset if self._charset != "utf-8" else None
|
||||
self.headers.add(
|
||||
"Set-Cookie",
|
||||
dump_cookie(
|
||||
@@ -267,7 +230,6 @@ class Response:
|
||||
domain=domain,
|
||||
secure=secure,
|
||||
httponly=httponly,
|
||||
charset=charset,
|
||||
max_size=self.max_cookie_size,
|
||||
samesite=samesite,
|
||||
),
|
||||
@@ -332,7 +294,7 @@ class Response:
|
||||
|
||||
@mimetype.setter
|
||||
def mimetype(self, value: str) -> None:
|
||||
self.headers["Content-Type"] = get_content_type(value, self._charset)
|
||||
self.headers["Content-Type"] = get_content_type(value, "utf-8")
|
||||
|
||||
@property
|
||||
def mimetype_params(self) -> dict[str, str]:
|
||||
|
||||
Reference in New Issue
Block a user