This could be lossy on the JSON side since the precision is up to the
reader as well. I implemented the encoding as a cast to `float` so
there will almost certainly be some loss of precision.
Since the form encoder refuses to handle nested sequences, the content
mixin explicitly handles this case instead of letting the unhandled
exception bubble up.
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)) :/
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.
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.
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".
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.