From 5168459936b8f6c2bcc9689fd1fba4fffaf83e9b Mon Sep 17 00:00:00 2001 From: j Date: Mon, 29 Aug 2016 22:58:54 +0200 Subject: [PATCH] keys can be binary --- ox/torrent/bencode3.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ox/torrent/bencode3.py b/ox/torrent/bencode3.py index 49f5aab..bf7717e 100644 --- a/ox/torrent/bencode3.py +++ b/ox/torrent/bencode3.py @@ -24,6 +24,10 @@ def _decode_str(data): raise Exception('invalid string size: %d' % l) start += 1 ret = bytes(data[start:start+l]) + try: + ret = ret.decode('utf-8') + except: + pass data = data[start+l:] return ret, data @@ -49,7 +53,7 @@ def _decode_dict(data): while data[0] != ord(b'e'): k, data = _decode_str(data) v, data = _decode(data) - d[k.decode()] = v + d[k] = v return d, data[1:] def _decode(data):