diff --git a/kademlia/protocol.py b/kademlia/protocol.py index 038246c..c7fa9d3 100644 --- a/kademlia/protocol.py +++ b/kademlia/protocol.py @@ -1,4 +1,5 @@ import random +import asyncio from logging import getLogger from rpcudp.protocol import RPCProtocol diff --git a/kademlia/tests/test_node.py b/kademlia/tests/test_node.py index 60ca14b..fb797ee 100644 --- a/kademlia/tests/test_node.py +++ b/kademlia/tests/test_node.py @@ -1,7 +1,7 @@ +import unittest import random import hashlib -from twisted.trial import unittest from kademlia.node import Node, NodeHeap from kademlia.tests.utils import mknode @@ -9,15 +9,15 @@ from kademlia.tests.utils import mknode class NodeTest(unittest.TestCase): def test_longID(self): - rid = hashlib.sha1(str(random.getrandbits(255))).digest() + rid = hashlib.sha1(str(random.getrandbits(255)).encode()).digest() n = Node(rid) - self.assertEqual(n.long_id, long(rid.encode('hex'), 16)) + self.assertEqual(n.long_id, int(rid.hex(), 16)) def test_distanceCalculation(self): - ridone = hashlib.sha1(str(random.getrandbits(255))) - ridtwo = hashlib.sha1(str(random.getrandbits(255))) + ridone = hashlib.sha1(str(random.getrandbits(255)).encode()) + ridtwo = hashlib.sha1(str(random.getrandbits(255)).encode()) - shouldbe = long(ridone.hexdigest(), 16) ^ long(ridtwo.hexdigest(), 16) + shouldbe = int(ridone.hexdigest(), 16) ^ int(ridtwo.hexdigest(), 16) none = Node(ridone.digest()) ntwo = Node(ridtwo.digest()) self.assertEqual(none.distanceTo(ntwo), shouldbe) diff --git a/kademlia/tests/test_routing.py b/kademlia/tests/test_routing.py index 460302a..8c77b53 100644 --- a/kademlia/tests/test_routing.py +++ b/kademlia/tests/test_routing.py @@ -1,4 +1,4 @@ -from twisted.trial import unittest +import unittest from kademlia.routing import KBucket from kademlia.tests.utils import mknode, FakeProtocol diff --git a/kademlia/tests/test_utils.py b/kademlia/tests/test_utils.py index d667657..073d0c3 100644 --- a/kademlia/tests/test_utils.py +++ b/kademlia/tests/test_utils.py @@ -1,16 +1,15 @@ import hashlib - -from twisted.trial import unittest +import unittest from kademlia.utils import digest, sharedPrefix, OrderedSet class UtilsTest(unittest.TestCase): def test_digest(self): - d = hashlib.sha1('1').digest() + d = hashlib.sha1(b'1').digest() self.assertEqual(d, digest(1)) - d = hashlib.sha1('another').digest() + d = hashlib.sha1(b'another').digest() self.assertEqual(d, digest('another')) def test_sharedPrefix(self): diff --git a/kademlia/tests/utils.py b/kademlia/tests/utils.py index 1c4da17..d6f4d07 100644 --- a/kademlia/tests/utils.py +++ b/kademlia/tests/utils.py @@ -15,7 +15,7 @@ def mknode(id=None, ip=None, port=None, intid=None): """ if intid is not None: id = pack('>l', intid) - id = id or hashlib.sha1(str(random.getrandbits(255))).digest() + id = id or hashlib.sha1(str(random.getrandbits(255)).encode()).digest() return Node(id, ip, port)