Browse Source

use strings (us-ascii) for dict keys to make things more manageable..

main
John-Mark Gurney 2 years ago
parent
commit
eb26d1d04f
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      bencode.py

+ 4
- 3
bencode.py View File

@@ -70,9 +70,10 @@ def decode_list(x, f):

def decode_dict(x, f):
r, f = {}, f+1
lastkey = b''
lastkey = ''
while x[f] != b'e'[0]:
k, f = decode_string(x, f)
k = k.decode('us-ascii')
if lastkey >= k:
raise ValueError
lastkey = k
@@ -199,8 +200,8 @@ def test_bdecode():
except ValueError:
pass
assert bdecode(b'de') == {}
assert bdecode(b'd3:agei25e4:eyes4:bluee') == {b'age': 25, b'eyes': b'blue'}
assert bdecode(b'd8:spam.mp3d6:author5:Alice6:lengthi100000eee') == {b'spam.mp3': {b'author': b'Alice', b'length': 100000}}
assert bdecode(b'd3:agei25e4:eyes4:bluee') == {'age': 25, 'eyes': b'blue'}
assert bdecode(b'd8:spam.mp3d6:author5:Alice6:lengthi100000eee') == {'spam.mp3': {'author': b'Alice', 'length': 100000}}
try:
bdecode(b'd3:fooe')
assert 0


Loading…
Cancel
Save