debug info
This commit is contained in:
parent
616b255197
commit
f69e5a0322
1 changed files with 4 additions and 2 deletions
|
@ -24,7 +24,7 @@ class Decoder(object):
|
||||||
"""
|
"""
|
||||||
start = self.data.index(b':', self.idx)
|
start = self.data.index(b':', self.idx)
|
||||||
l = int(self.data[self.idx:start].decode(), 10)
|
l = int(self.data[self.idx:start].decode(), 10)
|
||||||
if l <= 0:
|
if l < 0:
|
||||||
raise Exception('invalid string size: %d' % l)
|
raise Exception('invalid string size: %d' % l)
|
||||||
start += 1
|
start += 1
|
||||||
ret = self.data[start:start+l]
|
ret = self.data[start:start+l]
|
||||||
|
@ -139,6 +139,8 @@ def _encode(obj, buff):
|
||||||
_encode_str(obj, buff)
|
_encode_str(obj, buff)
|
||||||
elif str(obj).isdigit():
|
elif str(obj).isdigit():
|
||||||
_encode_int(obj, buff)
|
_encode_int(obj, buff)
|
||||||
|
elif isinstance(obj, int):
|
||||||
|
_encode_int(obj, buff)
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
_encode_list(obj, buff)
|
_encode_list(obj, buff)
|
||||||
elif hasattr(obj, 'keys') and hasattr(obj, 'values'):
|
elif hasattr(obj, 'keys') and hasattr(obj, 'values'):
|
||||||
|
@ -146,7 +148,7 @@ def _encode(obj, buff):
|
||||||
elif str(obj) in ['True', 'False']:
|
elif str(obj) in ['True', 'False']:
|
||||||
_encode_int(int(obj and '1' or '0'), buff)
|
_encode_int(int(obj and '1' or '0'), buff)
|
||||||
else:
|
else:
|
||||||
raise Exception('non serializable object: %s' % obj)
|
raise Exception('non serializable object: %s [%s]' % (obj, type(obj)))
|
||||||
|
|
||||||
|
|
||||||
def bencode(obj):
|
def bencode(obj):
|
||||||
|
|
Loading…
Reference in a new issue