Represents the parts of a ``WWW-Authenticate`` response header. Set :attr:`.Response.www_authenticate` to an instance of list of instances to set values for this header in the response. Modifying this instance will modify the header value. Depending on the auth scheme, either :attr
| 141 | |
| 142 | |
| 143 | class WWWAuthenticate: |
| 144 | """Represents the parts of a ``WWW-Authenticate`` response header. |
| 145 | |
| 146 | Set :attr:`.Response.www_authenticate` to an instance of list of instances to set |
| 147 | values for this header in the response. Modifying this instance will modify the |
| 148 | header value. |
| 149 | |
| 150 | Depending on the auth scheme, either :attr:`parameters` or :attr:`token` should be |
| 151 | set. The ``Basic`` scheme will encode ``username`` and ``password`` parameters to a |
| 152 | token. |
| 153 | |
| 154 | For convenience, ``auth["key"]`` and ``auth.key`` both act on the :attr:`parameters` |
| 155 | dict, and can be used to get, set, or delete parameters. ``auth.get("key")`` and |
| 156 | ``"key" in auth`` are also provided. |
| 157 | |
| 158 | .. versionchanged:: 2.3 |
| 159 | The ``token`` parameter and attribute was added to support auth schemes that use |
| 160 | a token instead of parameters, such as ``Bearer``. |
| 161 | |
| 162 | .. versionchanged:: 2.3 |
| 163 | The object is no longer a ``dict``. |
| 164 | |
| 165 | .. versionchanged:: 2.3 |
| 166 | The ``on_update`` parameter was removed. |
| 167 | """ |
| 168 | |
| 169 | def __init__( |
| 170 | self, |
| 171 | auth_type: str, |
| 172 | values: dict[str, str | None] | None = None, |
| 173 | token: str | None = None, |
| 174 | ): |
| 175 | self._type = auth_type.lower() |
| 176 | self._parameters: dict[str, str | None] = CallbackDict( |
| 177 | values, lambda _: self._trigger_on_update() |
| 178 | ) |
| 179 | self._token = token |
| 180 | self._on_update: cabc.Callable[[WWWAuthenticate], None] | None = None |
| 181 | |
| 182 | def _trigger_on_update(self) -> None: |
| 183 | if self._on_update is not None: |
| 184 | self._on_update(self) |
| 185 | |
| 186 | @property |
| 187 | def type(self) -> str: |
| 188 | """The authorization scheme, like ``basic``, ``digest``, or ``bearer``.""" |
| 189 | return self._type |
| 190 | |
| 191 | @type.setter |
| 192 | def type(self, value: str) -> None: |
| 193 | self._type = value |
| 194 | self._trigger_on_update() |
| 195 | |
| 196 | @property |
| 197 | def parameters(self) -> dict[str, str | None]: |
| 198 | """A dict of parameters for the header. Only one of this or :attr:`token` should |
| 199 | have a value for a given scheme. |
| 200 | """ |
no outgoing calls