async def etf_decoder(raw_data): data = earl.unpack(raw_data) # Earl makes all keys and values bytes object. # We convert them into UTF-8 if isinstance(data, dict): data = await decode_dict(data) return data
def decode_etf(data: bytes): res = earl.unpack(data) if isinstance(res, bytes): return data.decode() if isinstance(res, dict): return _etf_decode_dict(res) return res
def test_utf8(self): self.assertEqual( earl.unpack(bytes([131, 107, 0, 6, 233, 153, 176, 233, 153, 189]), encoding="utf8"), "陰陽")
def test_atom(self): self.assertEqual( earl.unpack(bytes([131, 100, 0, 5, 104, 101, 108, 108, 111])), "hello")
def test_nil(self): self.assertEqual(earl.unpack(bytes([131, 106])), [])
def test_map(self): self.assertEqual( earl.unpack(bytes([131, 116, 0, 0, 0, 1, 100, 0, 1, 97, 97, 150])), {'a': 150})
def test_list(self): self.assertEqual( earl.unpack(bytes([131, 108, 0, 0, 0, 3, 97, 1, 97, 2, 97, 3, 106])), [1, 2, 3])
def test_stringext(self): self.assertEqual(earl.unpack(bytes([131, 107, 0, 3, 1, 2, 3])), bytes([1, 2, 3]))
def test_floats(self): self.assertEqual( earl.unpack(bytes([131, 70, 64, 108, 42, 225, 71, 174, 20, 123])), 225.34)
def test_bigint(self): self.assertEqual(earl.unpack(bytes([131, 98, 0, 0, 214, 216])), 55000)
def test_smallint(self): self.assertEqual(earl.unpack(bytes([131, 97, 234])), 234)
def decode(obj): if six.PY3: return unpack(obj, encoding='utf-8', encode_binary_ext=True) return unpack(obj)
def _loader(data: bytes): return earl.unpack(data, encoding="utf-8", encode_binary_ext=True)