port dht.encoding ~> py3

This commit is contained in:
Victor Shyba 2018-07-17 21:38:54 -03:00 committed by Jack Robison
parent 78c560a3be
commit 9967857a57
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -1,6 +1,8 @@
from __future__ import print_function
from .error import DecodeError
import sys
if sys.version_info > (3,):
long = int
class Encoding(object):
""" Interface for RPC message encoders/decoders
@ -63,8 +65,7 @@ class Bencode(Encoding):
elif isinstance(data, dict):
encodedDictItems = ''
keys = data.keys()
keys.sort()
for key in keys:
for key in sorted(keys):
encodedDictItems += self.encode(key) # TODO: keys should always be bytestrings
encodedDictItems += self.encode(data[key])
return 'd%se' % encodedDictItems