@@ -2,4 +2,4 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class DrfMsgpackConfig(AppConfig):
|
||||
name = 'drf_msgpack'
|
||||
name = "drf_msgpack"
|
||||
|
||||
@@ -5,10 +5,10 @@ from rest_framework.exceptions import ParseError
|
||||
|
||||
|
||||
class MessagePackParser(BaseParser):
|
||||
media_type = 'application/msgpack'
|
||||
media_type = "application/msgpack"
|
||||
|
||||
def parse(self, stream, media_type=None, parser_context=None):
|
||||
try:
|
||||
return msgpack.unpackb(stream.read(), raw=False)
|
||||
except Exception as exc:
|
||||
raise ParseError('MessagePack parse error - %s' % str(exc))
|
||||
raise ParseError("MessagePack parse error - %s" % str(exc))
|
||||
|
||||
@@ -4,12 +4,12 @@ from rest_framework.renderers import BaseRenderer
|
||||
|
||||
|
||||
class MessagePackRenderer(BaseRenderer):
|
||||
media_type = 'application/msgpack'
|
||||
format = 'msgpack'
|
||||
render_style = 'binary'
|
||||
media_type = "application/msgpack"
|
||||
format = "msgpack"
|
||||
render_style = "binary"
|
||||
charset = None
|
||||
|
||||
def render(self, data, media_type=None, renderer_context=None):
|
||||
if data is None:
|
||||
return b''
|
||||
return b""
|
||||
return msgpack.packb(data, use_bin_type=True)
|
||||
|
||||
Reference in New Issue
Block a user