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