mirror of
https://github.com/sprockets/sprockets.mixins.mediatype.git
synced 2024-11-22 03:00:25 +00:00
Update documentation & examples for new packaging.
This commit is contained in:
parent
f9cda82f64
commit
74ce03a0d5
3 changed files with 15 additions and 15 deletions
12
README.rst
12
README.rst
|
@ -21,7 +21,7 @@ functions as parameters:
|
|||
|
||||
import json
|
||||
|
||||
from sprockets.mixins import mediatype
|
||||
from sprockets.mixins.mediatype import content
|
||||
from tornado import web
|
||||
|
||||
def make_application():
|
||||
|
@ -29,9 +29,9 @@ functions as parameters:
|
|||
# insert your handlers here
|
||||
])
|
||||
|
||||
mediatype.add_text_content_type(application,
|
||||
'application/json', 'utf-8',
|
||||
json.dumps, json.loads)
|
||||
content.add_text_content_type(application,
|
||||
'application/json', 'utf-8',
|
||||
json.dumps, json.loads)
|
||||
|
||||
return application
|
||||
|
||||
|
@ -40,10 +40,10 @@ instance that the mix-in uses to manipulate the request and response bodies.
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
from sprockets.mixins import mediatype
|
||||
from sprockets.mixins.mediatype import content
|
||||
from tornado import web
|
||||
|
||||
class SomeHandler(mediatype.ContentMixin, web.RequestHandler):
|
||||
class SomeHandler(content.ContentMixin, web.RequestHandler):
|
||||
def get(self):
|
||||
self.send_response({'data': 'value'})
|
||||
self.finish()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
API Documentation
|
||||
=================
|
||||
.. currentmodule:: sprockets.mixins.mediatype
|
||||
.. currentmodule:: sprockets.mixins.mediatype.content
|
||||
|
||||
Content Type Handling
|
||||
---------------------
|
||||
|
|
16
examples.py
16
examples.py
|
@ -2,12 +2,12 @@ import json
|
|||
import logging
|
||||
import signal
|
||||
|
||||
from sprockets.mixins import mediatype
|
||||
from sprockets.mixins.mediatype import content
|
||||
from tornado import ioloop, web
|
||||
import msgpack
|
||||
|
||||
|
||||
class SimpleHandler(mediatype.ContentMixin, web.RequestHandler):
|
||||
class SimpleHandler(content.ContentMixin, web.RequestHandler):
|
||||
|
||||
def post(self):
|
||||
body = self.get_request_body()
|
||||
|
@ -18,12 +18,12 @@ class SimpleHandler(mediatype.ContentMixin, web.RequestHandler):
|
|||
|
||||
def make_application(**settings):
|
||||
application = web.Application([web.url(r'/', SimpleHandler)], **settings)
|
||||
mediatype.set_default_content_type(application, 'application/json',
|
||||
encoding='utf-8')
|
||||
mediatype.add_binary_content_type(application, 'application/msgpack',
|
||||
msgpack.packb, msgpack.unpackb)
|
||||
mediatype.add_text_content_type(application, 'application/json', 'utf-8',
|
||||
json.dumps, json.loads)
|
||||
content.set_default_content_type(application, 'application/json',
|
||||
encoding='utf-8')
|
||||
content.add_binary_content_type(application, 'application/msgpack',
|
||||
msgpack.packb, msgpack.unpackb)
|
||||
content.add_text_content_type(application, 'application/json', 'utf-8',
|
||||
json.dumps, json.loads)
|
||||
return application
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue