mirror of
https://github.com/sprockets/sprockets.mixins.mediatype.git
synced 2024-12-28 11:24:12 +00:00
Address flake8 complaints
This commit is contained in:
parent
fd3f8b3008
commit
a28633aef5
2 changed files with 17 additions and 18 deletions
|
@ -50,8 +50,8 @@ class JSONTranscoder(handlers.TextContentHandler):
|
|||
|
||||
def __init__(self, content_type='application/json',
|
||||
default_encoding='utf-8'):
|
||||
super().__init__(content_type, self.dumps,
|
||||
self.loads, default_encoding)
|
||||
super().__init__(content_type, self.dumps, self.loads,
|
||||
default_encoding)
|
||||
self.dump_options = {
|
||||
'default': self.dump_object,
|
||||
'separators': (',', ':'),
|
||||
|
@ -137,8 +137,7 @@ class MsgPackTranscoder(handlers.BinaryContentHandler):
|
|||
raise RuntimeError('Cannot import MsgPackTranscoder, '
|
||||
'umsgpack is not available')
|
||||
|
||||
super().__init__(content_type, self.packb,
|
||||
self.unpackb)
|
||||
super().__init__(content_type, self.packb, self.unpackb)
|
||||
|
||||
def packb(self, data):
|
||||
"""Pack `data` into a :class:`bytes` instance."""
|
||||
|
|
28
tests.py
28
tests.py
|
@ -36,27 +36,27 @@ class Context:
|
|||
def pack_string(obj):
|
||||
"""Optimally pack a string according to msgpack format"""
|
||||
payload = str(obj).encode('ASCII')
|
||||
l = len(payload)
|
||||
if l < (2 ** 5):
|
||||
prefix = struct.pack('B', 0b10100000 | l)
|
||||
elif l < (2 ** 8):
|
||||
prefix = struct.pack('BB', 0xD9, l)
|
||||
elif l < (2 ** 16):
|
||||
prefix = struct.pack('>BH', 0xDA, l)
|
||||
pl = len(payload)
|
||||
if pl < (2 ** 5):
|
||||
prefix = struct.pack('B', 0b10100000 | pl)
|
||||
elif pl < (2 ** 8):
|
||||
prefix = struct.pack('BB', 0xD9, pl)
|
||||
elif pl < (2 ** 16):
|
||||
prefix = struct.pack('>BH', 0xDA, pl)
|
||||
else:
|
||||
prefix = struct.pack('>BI', 0xDB, l)
|
||||
prefix = struct.pack('>BI', 0xDB, pl)
|
||||
return prefix + payload
|
||||
|
||||
|
||||
def pack_bytes(payload):
|
||||
"""Optimally pack a byte string according to msgpack format"""
|
||||
l = len(payload)
|
||||
if l < (2 ** 8):
|
||||
prefix = struct.pack('BB', 0xC4, l)
|
||||
elif l < (2 ** 16):
|
||||
prefix = struct.pack('>BH', 0xC5, l)
|
||||
pl = len(payload)
|
||||
if pl < (2 ** 8):
|
||||
prefix = struct.pack('BB', 0xC4, pl)
|
||||
elif pl < (2 ** 16):
|
||||
prefix = struct.pack('>BH', 0xC5, pl)
|
||||
else:
|
||||
prefix = struct.pack('>BI', 0xC6, l)
|
||||
prefix = struct.pack('>BI', 0xC6, pl)
|
||||
return prefix + payload
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue