Example #1
0
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
Example #2
0
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
Example #3
0
 def test_utf8(self):
     self.assertEqual(
         earl.unpack(bytes([131, 107, 0, 6, 233, 153, 176, 233, 153, 189]),
                     encoding="utf8"), "陰陽")
Example #4
0
 def test_atom(self):
     self.assertEqual(
         earl.unpack(bytes([131, 100, 0, 5, 104, 101, 108, 108, 111])),
         "hello")
Example #5
0
 def test_nil(self):
     self.assertEqual(earl.unpack(bytes([131, 106])), [])
Example #6
0
 def test_map(self):
     self.assertEqual(
         earl.unpack(bytes([131, 116, 0, 0, 0, 1, 100, 0, 1, 97, 97, 150])),
         {'a': 150})
Example #7
0
 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])
Example #8
0
 def test_stringext(self):
     self.assertEqual(earl.unpack(bytes([131, 107, 0, 3, 1, 2, 3])),
                      bytes([1, 2, 3]))
Example #9
0
 def test_floats(self):
     self.assertEqual(
         earl.unpack(bytes([131, 70, 64, 108, 42, 225, 71, 174, 20, 123])),
         225.34)
Example #10
0
 def test_bigint(self):
     self.assertEqual(earl.unpack(bytes([131, 98, 0, 0, 214, 216])), 55000)
Example #11
0
 def test_smallint(self):
     self.assertEqual(earl.unpack(bytes([131, 97, 234])), 234)
Example #12
0
 def decode(obj):
     if six.PY3:
         return unpack(obj, encoding='utf-8', encode_binary_ext=True)
     return unpack(obj)
Example #13
0
 def _loader(data: bytes):
     return earl.unpack(data, encoding="utf-8", encode_binary_ext=True)