mirror of
https://github.com/sprockets/sprockets.mixins.mediatype.git
synced 2024-12-28 19:29:19 +00:00
add_transcoder: Change parameter order.
This is the first part of making the content type parameter optional
This commit is contained in:
parent
f920298c54
commit
36a916a557
3 changed files with 14 additions and 12 deletions
|
@ -52,8 +52,8 @@ types:
|
|||
# insert your handlers here
|
||||
])
|
||||
|
||||
content.add_transcoder(application, 'application/json',
|
||||
transcoders.JSONTranscoder())
|
||||
content.add_transcoder(application, transcoders.JSONTranscoder(),
|
||||
'application/json')
|
||||
|
||||
return application
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ def make_application(**settings):
|
|||
application = web.Application([web.url(r'/', SimpleHandler)], **settings)
|
||||
content.set_default_content_type(application, 'application/json',
|
||||
encoding='utf-8')
|
||||
content.add_transcoder(application, 'application/msgpack',
|
||||
transcoders.MsgPackTranscoder())
|
||||
content.add_transcoder(application, 'application/json',
|
||||
transcoders.JSONTranscoder())
|
||||
content.add_transcoder(application, transcoders.MsgPackTranscoder(),
|
||||
content_type='application/msgpack')
|
||||
content.add_transcoder(application, transcoders.JSONTranscoder(),
|
||||
content_type='application/json')
|
||||
return application
|
||||
|
||||
|
||||
|
|
|
@ -131,8 +131,9 @@ def add_binary_content_type(application, content_type, pack, unpack):
|
|||
dictionary. ``unpack(bytes) -> dict``
|
||||
|
||||
"""
|
||||
add_transcoder(application, content_type,
|
||||
handlers.BinaryContentHandler(content_type, pack, unpack))
|
||||
add_transcoder(application,
|
||||
handlers.BinaryContentHandler(content_type, pack, unpack),
|
||||
content_type)
|
||||
|
||||
|
||||
def add_text_content_type(application, content_type, default_encoding,
|
||||
|
@ -155,19 +156,20 @@ def add_text_content_type(application, content_type, default_encoding,
|
|||
parsed = headers.parse_content_type(content_type)
|
||||
parsed.parameters.pop('charset', None)
|
||||
normalized = str(parsed)
|
||||
add_transcoder(application, normalized,
|
||||
add_transcoder(application,
|
||||
handlers.TextContentHandler(normalized, dumps, loads,
|
||||
default_encoding))
|
||||
default_encoding),
|
||||
normalized)
|
||||
|
||||
|
||||
def add_transcoder(application, content_type, transcoder):
|
||||
def add_transcoder(application, transcoder, content_type):
|
||||
"""
|
||||
Register a transcoder for a specific content type.
|
||||
|
||||
:param tornado.web.Application application: the application to modify
|
||||
:param str content_type: the content type to add
|
||||
:param transcoder: object that translates between :class:`bytes` and
|
||||
:class:`object` instances
|
||||
:param str content_type: the content type to add
|
||||
|
||||
The `transcoder` instance is required to implement the following
|
||||
simple protocol:
|
||||
|
|
Loading…
Reference in a new issue