Skip to content

Commit

Permalink
Refactor the Multipart parsing into a Sans-IO layer
Browse files Browse the repository at this point in the history
This allows it to be used in async (ASGI) frameworks. It also
hopefully makes the code a little clearer to follow.

This removes the ``Content-Transfer-Encoding`` support as RFC7578
states it is deprecated and

    Currently, no deployed implementations that send such bodies have
    been discovered.

This requires the dataclasses backport, which I think is ok as
dataclasses are in the stdlib, and 3.6 has less than a year till EoL.

The API is based on that successfully used by h11.
  • Loading branch information
pgjones committed Jan 24, 2021
1 parent 553576c commit 41c10d5
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 445 deletions.
2 changes: 0 additions & 2 deletions docs/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,3 @@ environments for unittesting you might want to use the
.. autoclass:: FormDataParser

.. autofunction:: parse_form_data

.. autofunction:: parse_multipart_headers
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from setuptools import setup

# Metadata goes in setup.cfg. These are here for GitHub's dependency graph.
setup(name="Werkzeug", extras_require={"watchdog": ["watchdog"]})
setup(
name="Werkzeug",
install_requires=["dataclasses; python_version < '3.7'"],
extras_require={"watchdog": ["watchdog"]},
)
2 changes: 1 addition & 1 deletion src/werkzeug/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _to_str(x, charset=_default_encoding, errors="strict", allow_none_charset=Fa
if x is None or isinstance(x, str):
return x

if not isinstance(x, bytes):
if not isinstance(x, (bytes, bytearray)):
return str(x)

if charset is None:
Expand Down
Loading

0 comments on commit 41c10d5

Please sign in to comment.