MCPcopy
hub / github.com/pallets/werkzeug / Authorization

Class Authorization

src/werkzeug/datastructures/auth.py:17–140  ·  view source on GitHub ↗

Represents the parts of an ``Authorization`` request header. :attr:`.Request.authorization` returns an instance if the header is set. An instance can be used with the test :class:`.Client` request methods' ``auth`` parameter to send the header in test requests. Depending on the au

Source from the content-addressed store, hash-verified

15
16
17class Authorization:
18 """Represents the parts of an ``Authorization`` request header.
19
20 :attr:`.Request.authorization` returns an instance if the header is set.
21
22 An instance can be used with the test :class:`.Client` request methods' ``auth``
23 parameter to send the header in test requests.
24
25 Depending on the auth scheme, either :attr:`parameters` or :attr:`token` will be
26 set. The ``Basic`` scheme's token is decoded into the ``username`` and ``password``
27 parameters.
28
29 For convenience, ``auth["key"]`` and ``auth.key`` both access the key in the
30 :attr:`parameters` dict, along with ``auth.get("key")`` and ``"key" in auth``.
31
32 .. versionchanged:: 2.3
33 The ``token`` parameter and attribute was added to support auth schemes that use
34 a token instead of parameters, such as ``Bearer``.
35
36 .. versionchanged:: 2.3
37 The object is no longer a ``dict``.
38
39 .. versionchanged:: 0.5
40 The object is an immutable dict.
41 """
42
43 def __init__(
44 self,
45 auth_type: str,
46 data: dict[str, str | None] | None = None,
47 token: str | None = None,
48 ) -> None:
49 self.type = auth_type
50 """The authorization scheme, like ``basic``, ``digest``, or ``bearer``."""
51
52 if data is None:
53 data = {}
54
55 self.parameters = data
56 """A dict of parameters parsed from the header. Either this or :attr:`token`
57 will have a value for a given scheme.
58 """
59
60 self.token = token
61 """A token parsed from the header. Either this or :attr:`parameters` will have a
62 value for a given scheme.
63
64 .. versionadded:: 2.3
65 """
66
67 def __getattr__(self, name: str) -> str | None:
68 return self.parameters.get(name)
69
70 def __getitem__(self, name: str) -> str | None:
71 return self.parameters.get(name)
72
73 def get(self, key: str, default: str | None = None) -> str | None:
74 return self.parameters.get(key, default)

Callers 3

test_authorization_eqMethod · 0.90
test_auth_objectFunction · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 3

test_authorization_eqMethod · 0.72
test_auth_objectFunction · 0.72
__init__Method · 0.68