-
-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mediatypes): reimplement (and unvendor) mimeparse (#2348)
* feat: WiP reimplement mimeparse * feat(mediatypes): add some skeletons for mediatype parsing * chore: fix up after master merge * feat(mimeparse): wip doodles * feat(mediatypes): implement computation of best quality * feat(mediatypes): remove vendored mimeparse * docs: add a newsfragment for one of the issues * refactor: remove debug `print()`s * feat(mediatypes): add specialized mediatype/range errors, coverage * docs(newsfragments): add a newsfragment for #1367 * test(mediatypes): add more tests * feat(mediatypes): improve docstring, simplify behaviour * refactor(mediatypes): use a stricter type annotation * chore: remove an unused import * chore: fix docstring style violation D205 * chore(docs): apply review suggestion to `docs/ext/rfc.py` Co-authored-by: Federico Caselli <cfederico87@gmail.com> * docs(newsfragments): apply review suggestion for `docs/_newsfragments/864.breakingchange.rst` Co-authored-by: Federico Caselli <cfederico87@gmail.com> * refactor(mediatypes): address some review comments * perf(mediatypes): short-circuit if q is absent as per review comment * docs: explain how to mitigate a potentially breaking change * docs: add a note that we continue to maintain python-mimeparse * refactor(mediatypes): convert _MediaType and _MediaRange to dataclasses * fix(mediatypes): only use dataclass(slots=True) where supported (>=py310) * refactor(mediatypes): a yet another attempt to make dataclasses work with __slots__ --------- Co-authored-by: Federico Caselli <cfederico87@gmail.com>
- Loading branch information
Showing
23 changed files
with
560 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The new implementation of :ref:`media type utilities <mediatype_util>` | ||
(Falcon was using the ``python-mimeparse`` library before) now always favors | ||
the exact media type match, if one is available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Falcon is no longer vendoring the | ||
`python-mimeparse <https://github.com/falconry/python-mimeparse>`__ library; | ||
the relevant functionality has instead been reimplemented in the framework | ||
itself, fixing a handful of long-standing bugs in the new implementation. | ||
|
||
If you use standalone | ||
`python-mimeparse <https://github.com/falconry/python-mimeparse>`__ in your | ||
project, do not worry! We will continue to maintain it as a separate package | ||
under the Falconry umbrella (we took over about 3 years ago). | ||
|
||
The following new behaviors are considered breaking changes: | ||
|
||
* Previously, the iterable passed to | ||
:meth:`req.client_prefers <falcon.Request.client_prefers>` had to be sorted in | ||
the order of increasing desirability. | ||
:func:`~falcon.mediatypes.best_match`, and by proxy | ||
:meth:`~falcon.Request.client_prefers`, now consider the provided media types | ||
to be sorted in the (more intuitive, we hope) order of decreasing | ||
desirability. | ||
|
||
* Unlike ``python-mimeparse``, the new | ||
:ref:`media type utilities <mediatype_util>` consider media types with | ||
different values for the same parameters as non-matching. | ||
|
||
One theoretically possible scenario where this change can affect you is only | ||
installing a :ref:`media <media>` handler for a content type with parameters; | ||
it then may not match media types with conflicting values (that used to match | ||
before Falcon 4.0). | ||
If this turns out to be the case, also | ||
:ref:`install the same handler <custom_media_handlers>` for the generic | ||
``type/subtype`` without parameters. | ||
|
||
The new functions, | ||
:func:`falcon.mediatypes.quality` and :func:`falcon.mediatypes.best_match`, | ||
otherwise have the same signature as the corresponding methods from | ||
``python-mimeparse``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.