debug info

This commit is contained in:
j 2016-10-26 23:38:00 +02:00
parent 616b255197
commit f69e5a0322

View file

@ -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):