diff --git a/ox/torrent/bencode3.py b/ox/torrent/bencode3.py index eefda6f..31c4523 100644 --- a/ox/torrent/bencode3.py +++ b/ox/torrent/bencode3.py @@ -24,7 +24,7 @@ class Decoder(object): """ start = self.data.index(b':', self.idx) l = int(self.data[self.idx:start].decode(), 10) - if l <= 0: + if l < 0: raise Exception('invalid string size: %d' % l) start += 1 ret = self.data[start:start+l] @@ -139,6 +139,8 @@ def _encode(obj, buff): _encode_str(obj, buff) elif str(obj).isdigit(): _encode_int(obj, buff) + elif isinstance(obj, int): + _encode_int(obj, buff) elif isinstance(obj, list): _encode_list(obj, buff) elif hasattr(obj, 'keys') and hasattr(obj, 'values'): @@ -146,7 +148,7 @@ def _encode(obj, buff): elif str(obj) in ['True', 'False']: _encode_int(int(obj and '1' or '0'), buff) else: - raise Exception('non serializable object: %s' % obj) + raise Exception('non serializable object: %s [%s]' % (obj, type(obj))) def bencode(obj):