Commit graph

37 commits

Author SHA1 Message Date
Dave Shawley
675ffbdf98
Change form encoder to default to stringify.
This matches what urlencode would do and is will remove surprises where
a value is supported by the other transcoders but not the form encoder.
2021-10-15 07:18:01 -04:00
Dave Shawley
198e73b6ef
Implement form encoding of sequence values.
This is off by default to match the `doseq` parameter of
urllib.parse.urlencode.
2021-10-14 07:54:32 -04:00
Dave Shawley
1fe22df719
Gracefully handle transcoder encoding failures.
Since the form encoder refuses to handle nested sequences, the content
mixin explicitly handles this case instead of letting the unhandled
exception bubble up.
2021-10-14 07:12:08 -04:00
Dave Shawley
25ec09972c
Add uuid support to FormUrlEncodedTranscoder. 2021-10-14 07:12:07 -04:00
Dave Shawley
4fd3864c04
Rejected serialization of non-pair sequences.
This required a bit of change in _encode to detect non-pair sequences
that are also not strings or byte strings.
2021-10-14 07:12:07 -04:00
Dave Shawley
e99d41a8b4
Refuse to serialize None, True, False.
If someone explicitly removes the literal mappings, then refuse to
serialize None, True, and False instead of guessing.  Note that I
explicitly included True and False in the branch logic since bool is a
subclass of int but str(True) != str(int(True)) :/
2021-10-14 07:12:07 -04:00
Dave Shawley
3aa08b7435
Implement serialization of primitive values.
This isn't covered by the serialization specification but is accounted
for in the deserialization side.
2021-10-14 07:12:07 -04:00
Dave Shawley
716bff0d7f
Add application/x-www-formurlencoded transcoder.
I ended up not using urllib.parse functions since they do not implement
the specification.  The only difference is that the specification
requires that "~" is encoded.

NB - this commit is incomplete since it does not handle calling the
transcoder on simple objects.  mypy will quite correctly fail.
2021-10-14 07:12:01 -04:00
Dave Shawley
2047fe8d16
Increase test coverage to 100% 2021-10-04 07:30:42 -04:00
Dave Shawley
9ff5ca3781
Fail gracefully when transcoder is missing.
If there is no transcoder for the default content type, sending a
response would fail with a "500 Internal Server Error" due to an
*unhandled* KeyError.  This commit catches the KeyError and produces
an explicit "500 Internal Server Error" with an appropriate error
message being logged.
2021-10-03 15:52:48 -04:00
Dave Shawley
d605acb5b7
Deprecate not configuring a default content type. 2021-10-03 15:52:48 -04:00
Dave Shawley
4dd46eda5b
Return 406 Not Acceptable appropriately.
If there is no default content type and nothing matches in the Accept
header, previous versions would fail with an Internal Server Error
because of an unhandled exception.  Instead we should be returning
a "406 Not Acceptable".
2021-10-03 15:52:47 -04:00
Dave Shawley
de43997df5
Reformat using yapf.
https://github.com/sprockets/sprockets.mixins.mediatype/issues/35
2021-09-19 09:58:08 -04:00
Dave Shawley
c6551e8024
Stop using the tornado reloader in tests.
This causes some interesting warnings.
2021-09-12 18:34:16 -04:00
Dave Shawley
21c6cb73fe Invalid content-type --> 400 Bad Request.
ietfparse raises a `ValueError` from `parse_content_type` which was
uncaught and resulted in an internal server error.
2020-10-29 13:50:33 -04:00
Andrew Rabert
723ed25edb Add test to ensure context suffix is handled with ietfparse<1.5.1 behavior 2018-11-30 11:58:39 -05:00
Andrew Rabert
a28633aef5 Address flake8 complaints 2018-11-28 11:50:43 -05:00
Andrew Rabert
fd3f8b3008 Python 3 updates
- Simplify super()
- Remove object inheritance
- Simplify package namespacing
- Remove BinaryWrapper
- Remove python 2 code paths
2018-11-28 11:50:40 -05:00
Dave Shawley
18e134b6f2 Deprecate ContentSettings.from_application. 2016-04-05 07:47:41 -04:00
Dave Shawley
68fe438894 content: Add install and get_settings functions. 2016-04-05 07:46:57 -04:00
Dave Shawley
a1cc214bbe ContentMixin: Set the Vary header.
This lets any transparent caches that our responses will vary based on
the Accept header.  Without this, caches will assume that a cached
response can be used even if the Accept header differs.
2016-03-13 09:34:32 -04:00
Dave Shawley
206e43ee7d ContentMixin: Raise 400 when body decode fails. 2016-02-22 09:58:58 -05:00
Dave Shawley
ed357d878f Strip charset parameter from text content types. 2016-01-31 12:14:20 -05:00
Dave Shawley
995c715405 Normalize registered content types.
MIME content type strings are normalized by lower-casing the content
type parameters and then sorting them.  Each parameter is preceded by a
space.
2016-01-31 12:11:11 -05:00
Dave Shawley
98e3719a8b MsgPackTranscoder: Add BinaryWrapper override. 2016-01-18 07:58:30 -05:00
Dave Shawley
3a65dea053 MsgPackTranscoder: Handle binary data values. 2016-01-18 07:58:11 -05:00
Dave Shawley
ba3d7cfc84 MsgPackTranscoder: Add support for UUID and datetimes. 2016-01-18 07:58:11 -05:00
Dave Shawley
7d2237745e Add s.m.mediatype.transcoders.MsgPackTranscoder. 2016-01-18 07:58:07 -05:00
Dave Shawley
8a44e527b1 Add explicit tests for handlers.add_*
Adding JSON and msgpack transcoders in the examples will obliviate
testing of the add_binary_content_type and add_text_content_type
functions.
2016-01-16 09:56:38 -05:00
Dave Shawley
3eecbad5c5 content.ContentSettings: Fix AttributeError in __setitem__.
Code coverage FTW!
2016-01-16 09:56:38 -05:00
Dave Shawley
61713f9f15 JSONTranscoder: Add support for datetime, UUID, and binary types. 2016-01-16 09:56:38 -05:00
Dave Shawley
f47a9b2aba tests: Correct msgpack-related test.
This would fail if you inspected the response body :/
2015-11-02 14:25:36 -05:00
Amber Heilman
212dcb7876 default to the set content type default in settings 2015-09-14 11:13:07 -04:00
Dave Shawley
f766a24e26 Add request body negotiation. 2015-08-26 14:50:48 -04:00
Dave Shawley
7305cad7e7 Add response type negotiation. 2015-08-19 18:29:11 -04:00
Dave Shawley
c67d1af19d Implement basic content handling framework. 2015-08-19 17:53:46 -04:00
Dan Tracy
f73a5e07ce Initial commit 2015-06-09 09:28:29 -04:00