lol
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user