|
1 | 1 | import functools |
2 | 2 | import inspect |
| 3 | +import json |
3 | 4 | import logging |
4 | 5 | import os |
5 | 6 | import sys |
@@ -379,25 +380,86 @@ def use_x_sendfile(self, value: bool) -> None: |
379 | 380 | ) |
380 | 381 | self.config["USE_X_SENDFILE"] = value |
381 | 382 |
|
382 | | - #: The JSON encoder class to use. Defaults to |
383 | | - #: :class:`~flask.json.JSONEncoder`. |
384 | | - #: |
385 | | - #: .. deprecated:: 2.2 |
386 | | - #: Will be removed in Flask 2.3. Customize |
387 | | - #: :attr:`json_provider_class` instead. |
388 | | - #: |
389 | | - #: .. versionadded:: 0.10 |
390 | | - json_encoder: None = None |
| 383 | + _json_encoder: t.Union[t.Type[json.JSONEncoder], None] = None |
| 384 | + _json_decoder: t.Union[t.Type[json.JSONDecoder], None] = None |
391 | 385 |
|
392 | | - #: The JSON decoder class to use. Defaults to |
393 | | - #: :class:`~flask.json.JSONDecoder`. |
394 | | - #: |
395 | | - #: .. deprecated:: 2.2 |
396 | | - #: Will be removed in Flask 2.3. Customize |
397 | | - #: :attr:`json_provider_class` instead. |
398 | | - #: |
399 | | - #: .. versionadded:: 0.10 |
400 | | - json_decoder: None = None |
| 386 | + @property # type: ignore[override] |
| 387 | + def json_encoder(self) -> t.Type[json.JSONEncoder]: # type: ignore[override] |
| 388 | + """The JSON encoder class to use. Defaults to |
| 389 | + :class:`~flask.json.JSONEncoder`. |
| 390 | +
|
| 391 | + .. deprecated:: 2.2 |
| 392 | + Will be removed in Flask 2.3. Customize |
| 393 | + :attr:`json_provider_class` instead. |
| 394 | +
|
| 395 | + .. versionadded:: 0.10 |
| 396 | + """ |
| 397 | + import warnings |
| 398 | + |
| 399 | + warnings.warn( |
| 400 | + "'app.json_encoder' is deprecated and will be removed in Flask 2.3." |
| 401 | + " Customize 'app.json_provider_class' or 'app.json' instead.", |
| 402 | + DeprecationWarning, |
| 403 | + stacklevel=2, |
| 404 | + ) |
| 405 | + |
| 406 | + if self._json_encoder is None: |
| 407 | + from . import json |
| 408 | + |
| 409 | + return json.JSONEncoder |
| 410 | + |
| 411 | + return self._json_encoder |
| 412 | + |
| 413 | + @json_encoder.setter |
| 414 | + def json_encoder(self, value: t.Type[json.JSONEncoder]) -> None: |
| 415 | + import warnings |
| 416 | + |
| 417 | + warnings.warn( |
| 418 | + "'app.json_encoder' is deprecated and will be removed in Flask 2.3." |
| 419 | + " Customize 'app.json_provider_class' or 'app.json' instead.", |
| 420 | + DeprecationWarning, |
| 421 | + stacklevel=2, |
| 422 | + ) |
| 423 | + self._json_encoder = value |
| 424 | + |
| 425 | + @property # type: ignore[override] |
| 426 | + def json_decoder(self) -> t.Type[json.JSONDecoder]: # type: ignore[override] |
| 427 | + """The JSON decoder class to use. Defaults to |
| 428 | + :class:`~flask.json.JSONDecoder`. |
| 429 | +
|
| 430 | + .. deprecated:: 2.2 |
| 431 | + Will be removed in Flask 2.3. Customize |
| 432 | + :attr:`json_provider_class` instead. |
| 433 | +
|
| 434 | + .. versionadded:: 0.10 |
| 435 | + """ |
| 436 | + import warnings |
| 437 | + |
| 438 | + warnings.warn( |
| 439 | + "'app.json_decoder' is deprecated and will be removed in Flask 2.3." |
| 440 | + " Customize 'app.json_provider_class' or 'app.json' instead.", |
| 441 | + DeprecationWarning, |
| 442 | + stacklevel=2, |
| 443 | + ) |
| 444 | + |
| 445 | + if self._json_decoder is None: |
| 446 | + from . import json |
| 447 | + |
| 448 | + return json.JSONDecoder |
| 449 | + |
| 450 | + return self._json_decoder |
| 451 | + |
| 452 | + @json_decoder.setter |
| 453 | + def json_decoder(self, value: t.Type[json.JSONDecoder]) -> None: |
| 454 | + import warnings |
| 455 | + |
| 456 | + warnings.warn( |
| 457 | + "'app.json_decoder' is deprecated and will be removed in Flask 2.3." |
| 458 | + " Customize 'app.json_provider_class' or 'app.json' instead.", |
| 459 | + DeprecationWarning, |
| 460 | + stacklevel=2, |
| 461 | + ) |
| 462 | + self._json_decoder = value |
401 | 463 |
|
402 | 464 | json_provider_class: t.Type[JSONProvider] = DefaultJSONProvider |
403 | 465 | """A subclass of :class:`~flask.json.provider.JSONProvider`. An |
|
0 commit comments