mirror of
https://github.com/sprockets/sprockets.mixins.mediatype.git
synced 2024-11-22 03:00:25 +00:00
Clean up a few documents.
This commit is contained in:
parent
ed357d878f
commit
f920298c54
2 changed files with 31 additions and 6 deletions
27
README.rst
27
README.rst
|
@ -12,8 +12,8 @@ This mix-in adds two methods to a ``tornado.web.RequestHandler`` instance:
|
|||
- ``send_response(object)``: serializes the response into the content type
|
||||
requested by the ``Accept`` header.
|
||||
|
||||
Support for a content types is enabled by calling either the
|
||||
``add_binary_content_type`` or ``add_text_content_type`` function with the
|
||||
Support for a content types is enabled by calling ``add_binary_content_type``,
|
||||
``add_text_content_type`` or the ``add_transcoder`` functions with the
|
||||
``tornado.web.Application`` instance, the content type, encoding and decoding
|
||||
functions as parameters:
|
||||
|
||||
|
@ -37,6 +37,29 @@ functions as parameters:
|
|||
|
||||
The *add content type* functions will add a attribute to the ``Application``
|
||||
instance that the mix-in uses to manipulate the request and response bodies.
|
||||
The *add_transcoder* function is similar except that it takes an object
|
||||
that implements transcoding methods instead of simple functions. The
|
||||
``transcoders`` module includes ready-to-use transcoders for a few content
|
||||
types:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from sprockets.mixins.mediatype import content, transcoders
|
||||
from tornado import web
|
||||
|
||||
def make_application():
|
||||
application = web.Application([
|
||||
# insert your handlers here
|
||||
])
|
||||
|
||||
content.add_transcoder(application, 'application/json',
|
||||
transcoders.JSONTranscoder())
|
||||
|
||||
return application
|
||||
|
||||
In either case, the ``ContentMixin`` uses the registered content type
|
||||
information to provide transparent content type negotiation for your
|
||||
request handlers.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class BinaryWrapper(bytes):
|
|||
Since :class:`bytes` is a synonym for :class:`str` in Python 2,
|
||||
you cannot distinguish between something that should be binary
|
||||
and something that should be encoded as a string. This is a
|
||||
problem in formats such as `msgpack`_ where binary data and
|
||||
problem in formats `such as msgpack`_ where binary data and
|
||||
strings are encoded differently. The :class:`MsgPackTranscoder`
|
||||
accomodates this by trying to UTF-8 encode a :class:`str` instance
|
||||
and falling back to binary encoding if the transcode fails.
|
||||
|
@ -36,7 +36,7 @@ class BinaryWrapper(bytes):
|
|||
this class. The transcoder will then treat it as a binary payload
|
||||
instead of trying to detect whether it is a string or not.
|
||||
|
||||
.. _msgpack: http://msgpack.org
|
||||
.. _such as msgpack: http://msgpack.org
|
||||
|
||||
"""
|
||||
pass
|
||||
|
@ -154,10 +154,10 @@ class MsgPackTranscoder(handlers.BinaryContentHandler):
|
|||
is passed directly to the ``BinaryContentHandler`` initializer.
|
||||
|
||||
This transcoder uses the `umsgpack`_ library to encode and decode
|
||||
objects according to the `msgpack`_ format.
|
||||
objects according to the `msgpack format`_.
|
||||
|
||||
.. _umsgpack: https://github.com/vsergeev/u-msgpack-python
|
||||
.. _msgpack: http://msgpack.org/index.html
|
||||
.. _msgpack format: http://msgpack.org/index.html
|
||||
|
||||
"""
|
||||
if sys.version_info[0] < 3:
|
||||
|
@ -255,6 +255,8 @@ class MsgPackTranscoder(handlers.BinaryContentHandler):
|
|||
.. _map family: https://github.com/msgpack/msgpack/blob/
|
||||
0b8f5ac67cdd130f4d4d4fe6afb839b989fdb86a/spec.md
|
||||
#mapping-format-family
|
||||
.. _bin family: https://github.com/msgpack/msgpack/blob/
|
||||
0b8f5ac67cdd130f4d4d4fe6afb839b989fdb86a/spec.md#bin-format-family
|
||||
|
||||
"""
|
||||
if datum is None:
|
||||
|
|
Loading…
Reference in a new issue