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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,15 +3,11 @@ from __future__ import annotations
|
||||
import base64
|
||||
import binascii
|
||||
import typing as t
|
||||
import warnings
|
||||
from functools import wraps
|
||||
|
||||
from ..http import dump_header
|
||||
from ..http import parse_dict_header
|
||||
from ..http import parse_set_header
|
||||
from ..http import quote_header_value
|
||||
from .structures import CallbackDict
|
||||
from .structures import HeaderSet
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
import typing_extensions as te
|
||||
@@ -46,7 +42,7 @@ class Authorization:
|
||||
def __init__(
|
||||
self,
|
||||
auth_type: str,
|
||||
data: dict[str, str] | None = None,
|
||||
data: dict[str, str | None] | None = None,
|
||||
token: str | None = None,
|
||||
) -> None:
|
||||
self.type = auth_type
|
||||
@@ -143,31 +139,6 @@ class Authorization:
|
||||
return f"<{type(self).__name__} {self.to_header()}>"
|
||||
|
||||
|
||||
def auth_property(name: str, doc: str | None = None) -> property:
|
||||
"""A static helper function for Authentication subclasses to add
|
||||
extra authentication system properties onto a class::
|
||||
|
||||
class FooAuthenticate(WWWAuthenticate):
|
||||
special_realm = auth_property('special_realm')
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0.
|
||||
"""
|
||||
warnings.warn(
|
||||
"'auth_property' is deprecated and will be removed in Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
def _set_value(self, value): # type: ignore[no-untyped-def]
|
||||
if value is None:
|
||||
self.pop(name, None)
|
||||
else:
|
||||
self[name] = str(value)
|
||||
|
||||
return property(lambda x: x.get(name), _set_value, doc=doc)
|
||||
|
||||
|
||||
class WWWAuthenticate:
|
||||
"""Represents the parts of a ``WWW-Authenticate`` response header.
|
||||
|
||||
@@ -196,21 +167,12 @@ class WWWAuthenticate:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
auth_type: str | None = None,
|
||||
values: dict[str, str] | None = None,
|
||||
auth_type: str,
|
||||
values: dict[str, str | None] | None = None,
|
||||
token: str | None = None,
|
||||
):
|
||||
if auth_type is None:
|
||||
warnings.warn(
|
||||
"An auth type must be given as the first parameter. Assuming 'basic' is"
|
||||
" deprecated and will be removed in Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
auth_type = "basic"
|
||||
|
||||
self._type = auth_type.lower()
|
||||
self._parameters: dict[str, str] = CallbackDict( # type: ignore[misc]
|
||||
self._parameters: dict[str, str | None] = CallbackDict( # type: ignore[misc]
|
||||
values, lambda _: self._trigger_on_update()
|
||||
)
|
||||
self._token = token
|
||||
@@ -231,7 +193,7 @@ class WWWAuthenticate:
|
||||
self._trigger_on_update()
|
||||
|
||||
@property
|
||||
def parameters(self) -> dict[str, str]:
|
||||
def parameters(self) -> dict[str, str | None]:
|
||||
"""A dict of parameters for the header. Only one of this or :attr:`token` should
|
||||
have a value for a given scheme.
|
||||
"""
|
||||
@@ -261,62 +223,6 @@ class WWWAuthenticate:
|
||||
self._token = value
|
||||
self._trigger_on_update()
|
||||
|
||||
def set_basic(self, realm: str = "authentication required") -> None:
|
||||
"""Clear any existing data and set a ``Basic`` challenge.
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0. Create and assign an instance instead.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'set_basic' method is deprecated and will be removed in Werkzeug 3.0."
|
||||
" Create and assign an instance instead."
|
||||
)
|
||||
self._type = "basic"
|
||||
dict.clear(self.parameters) # type: ignore[arg-type]
|
||||
dict.update(
|
||||
self.parameters, # type: ignore[arg-type]
|
||||
{"realm": realm}, # type: ignore[dict-item]
|
||||
)
|
||||
self._token = None
|
||||
self._trigger_on_update()
|
||||
|
||||
def set_digest(
|
||||
self,
|
||||
realm: str,
|
||||
nonce: str,
|
||||
qop: t.Sequence[str] = ("auth",),
|
||||
opaque: str | None = None,
|
||||
algorithm: str | None = None,
|
||||
stale: bool = False,
|
||||
) -> None:
|
||||
"""Clear any existing data and set a ``Digest`` challenge.
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0. Create and assign an instance instead.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'set_digest' method is deprecated and will be removed in Werkzeug 3.0."
|
||||
" Create and assign an instance instead."
|
||||
)
|
||||
self._type = "digest"
|
||||
dict.clear(self.parameters) # type: ignore[arg-type]
|
||||
parameters = {
|
||||
"realm": realm,
|
||||
"nonce": nonce,
|
||||
"qop": ", ".join(qop),
|
||||
"stale": "TRUE" if stale else "FALSE",
|
||||
}
|
||||
|
||||
if opaque is not None:
|
||||
parameters["opaque"] = opaque
|
||||
|
||||
if algorithm is not None:
|
||||
parameters["algorithm"] = algorithm
|
||||
|
||||
dict.update(self.parameters, parameters) # type: ignore[arg-type]
|
||||
self._token = None
|
||||
self._trigger_on_update()
|
||||
|
||||
def __getitem__(self, key: str) -> str | None:
|
||||
return self.parameters.get(key)
|
||||
|
||||
@@ -410,101 +316,3 @@ class WWWAuthenticate:
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{type(self).__name__} {self.to_header()}>"
|
||||
|
||||
@property
|
||||
def qop(self) -> set[str]:
|
||||
"""The ``qop`` parameter as a set.
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0. It will become the same as other
|
||||
parameters, returning a string.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'qop' property is deprecated and will be removed in Werkzeug 3.0."
|
||||
" It will become the same as other parameters, returning a string.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
def on_update(value: HeaderSet) -> None:
|
||||
if not value:
|
||||
if "qop" in self:
|
||||
del self["qop"]
|
||||
|
||||
return
|
||||
|
||||
self.parameters["qop"] = value.to_header()
|
||||
|
||||
return parse_set_header(self.parameters.get("qop"), on_update)
|
||||
|
||||
@property
|
||||
def stale(self) -> bool | None:
|
||||
"""The ``stale`` parameter as a boolean.
|
||||
|
||||
.. deprecated:: 2.3
|
||||
Will be removed in Werkzeug 3.0. It will become the same as other
|
||||
parameters, returning a string.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'stale' property is deprecated and will be removed in Werkzeug 3.0."
|
||||
" It will become the same as other parameters, returning a string.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
if "stale" in self.parameters:
|
||||
return self.parameters["stale"].lower() == "true"
|
||||
|
||||
return None
|
||||
|
||||
@stale.setter
|
||||
def stale(self, value: bool | str | None) -> None:
|
||||
if value is None:
|
||||
if "stale" in self.parameters:
|
||||
del self.parameters["stale"]
|
||||
|
||||
return
|
||||
|
||||
if isinstance(value, bool):
|
||||
warnings.warn(
|
||||
"Setting the 'stale' property to a boolean is deprecated and will be"
|
||||
" removed in Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self.parameters["stale"] = "TRUE" if value else "FALSE"
|
||||
else:
|
||||
self.parameters["stale"] = value
|
||||
|
||||
auth_property = staticmethod(auth_property)
|
||||
|
||||
|
||||
def _deprecated_dict_method(f): # type: ignore[no-untyped-def]
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs): # type: ignore[no-untyped-def]
|
||||
warnings.warn(
|
||||
"Treating 'Authorization' and 'WWWAuthenticate' as a dict is deprecated and"
|
||||
" will be removed in Werkzeug 3.0. Use the 'parameters' attribute instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
for name in (
|
||||
"__iter__",
|
||||
"clear",
|
||||
"copy",
|
||||
"items",
|
||||
"keys",
|
||||
"pop",
|
||||
"popitem",
|
||||
"setdefault",
|
||||
"update",
|
||||
"values",
|
||||
):
|
||||
f = _deprecated_dict_method(getattr(dict, name))
|
||||
setattr(Authorization, name, f)
|
||||
setattr(WWWAuthenticate, name, f)
|
||||
|
||||
@@ -2,7 +2,6 @@ from __future__ import annotations
|
||||
|
||||
import re
|
||||
import typing as t
|
||||
import warnings
|
||||
|
||||
from .._internal import _missing
|
||||
from ..exceptions import BadRequestKeyError
|
||||
@@ -82,7 +81,7 @@ class Headers:
|
||||
|
||||
__hash__ = None
|
||||
|
||||
def get(self, key, default=None, type=None, as_bytes=None):
|
||||
def get(self, key, default=None, type=None):
|
||||
"""Return the default value if the requested data doesn't exist.
|
||||
If `type` is provided and is a callable it should convert the value,
|
||||
return it or raise a :exc:`ValueError` if that is not possible. In
|
||||
@@ -101,27 +100,16 @@ class Headers:
|
||||
:class:`Headers`. If a :exc:`ValueError` is raised
|
||||
by this callable the default value is returned.
|
||||
|
||||
.. versionchanged:: 2.3
|
||||
The ``as_bytes`` parameter is deprecated and will be removed
|
||||
in Werkzeug 3.0.
|
||||
.. versionchanged:: 3.0
|
||||
The ``as_bytes`` parameter was removed.
|
||||
|
||||
.. versionchanged:: 0.9
|
||||
The ``as_bytes`` parameter was added.
|
||||
"""
|
||||
if as_bytes is not None:
|
||||
warnings.warn(
|
||||
"The 'as_bytes' parameter is deprecated and will be"
|
||||
" removed in Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
try:
|
||||
rv = self.__getitem__(key, _get_mode=True)
|
||||
except KeyError:
|
||||
return default
|
||||
if as_bytes:
|
||||
rv = rv.encode("latin1")
|
||||
if type is None:
|
||||
return rv
|
||||
try:
|
||||
@@ -129,7 +117,7 @@ class Headers:
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
def getlist(self, key, type=None, as_bytes=None):
|
||||
def getlist(self, key, type=None):
|
||||
"""Return the list of items for a given key. If that key is not in the
|
||||
:class:`Headers`, the return value will be an empty list. Just like
|
||||
:meth:`get`, :meth:`getlist` accepts a `type` parameter. All items will
|
||||
@@ -141,27 +129,16 @@ class Headers:
|
||||
by this callable the value will be removed from the list.
|
||||
:return: a :class:`list` of all the values for the key.
|
||||
|
||||
.. versionchanged:: 2.3
|
||||
The ``as_bytes`` parameter is deprecated and will be removed
|
||||
in Werkzeug 3.0.
|
||||
.. versionchanged:: 3.0
|
||||
The ``as_bytes`` parameter was removed.
|
||||
|
||||
.. versionchanged:: 0.9
|
||||
The ``as_bytes`` parameter was added.
|
||||
"""
|
||||
if as_bytes is not None:
|
||||
warnings.warn(
|
||||
"The 'as_bytes' parameter is deprecated and will be"
|
||||
" removed in Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
ikey = key.lower()
|
||||
result = []
|
||||
for k, v in self:
|
||||
if k.lower() == ikey:
|
||||
if as_bytes:
|
||||
v = v.encode("latin1")
|
||||
if type is not None:
|
||||
try:
|
||||
v = type(v)
|
||||
@@ -293,7 +270,6 @@ class Headers:
|
||||
"""
|
||||
if kw:
|
||||
_value = _options_header_vkw(_value, kw)
|
||||
_key = _str_header_key(_key)
|
||||
_value = _str_header_value(_value)
|
||||
self._list.append((_key, _value))
|
||||
|
||||
@@ -326,7 +302,6 @@ class Headers:
|
||||
"""
|
||||
if kw:
|
||||
_value = _options_header_vkw(_value, kw)
|
||||
_key = _str_header_key(_key)
|
||||
_value = _str_header_value(_value)
|
||||
if not self._list:
|
||||
self._list.append((_key, _value))
|
||||
@@ -399,7 +374,7 @@ class Headers:
|
||||
if isinstance(key, (slice, int)):
|
||||
if isinstance(key, int):
|
||||
value = [value]
|
||||
value = [(_str_header_key(k), _str_header_value(v)) for (k, v) in value]
|
||||
value = [(k, _str_header_value(v)) for (k, v) in value]
|
||||
if isinstance(key, int):
|
||||
self._list[key] = value[0]
|
||||
else:
|
||||
@@ -476,36 +451,10 @@ def _options_header_vkw(value: str, kw: dict[str, t.Any]):
|
||||
)
|
||||
|
||||
|
||||
def _str_header_key(key: t.Any) -> str:
|
||||
if not isinstance(key, str):
|
||||
warnings.warn(
|
||||
"Header keys must be strings. Passing other types is deprecated and will"
|
||||
" not be supported in Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
if isinstance(key, bytes):
|
||||
key = key.decode("latin-1")
|
||||
else:
|
||||
key = str(key)
|
||||
|
||||
return key
|
||||
|
||||
|
||||
_newline_re = re.compile(r"[\r\n]")
|
||||
|
||||
|
||||
def _str_header_value(value: t.Any) -> str:
|
||||
if isinstance(value, bytes):
|
||||
warnings.warn(
|
||||
"Passing bytes as a header value is deprecated and will not be supported in"
|
||||
" Werkzeug 3.0.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
value = value.decode("latin-1")
|
||||
|
||||
if not isinstance(value, str):
|
||||
value = str(value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user