From e3e0ae53c92cbe7edea1335403ee50997370cf0d Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Mon, 26 Jun 2017 11:46:37 +0200 Subject: [PATCH 1/3] In _process_incoming_message data and addr are not defined if self.sock.recvfrom raise an exception. fix #4 This fix will cause a socket.error to be raised, the real error, instead of an UnboundLocalError --- btdht/dht.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/btdht/dht.pyx b/btdht/dht.pyx index 5e16a93..9c641a0 100644 --- a/btdht/dht.pyx +++ b/btdht/dht.pyx @@ -976,7 +976,10 @@ cdef class DHT_BASE: # 1: premission denied # 10013: same as 1 but on windows if e.errno not in [11, 1, 10035, 10013]: - self.debug(0, "send:%r : (%r, %r)" % (e, data, addr)) + try: + self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr)) + except UnboundLocalError: + self.debug(0, "recv:%r" % (e,)) raise except MissingT: pass From a27c7f5a49d60d0f5ec000910f6202aa02c72221 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Mon, 26 Jun 2017 11:52:10 +0200 Subject: [PATCH 2/3] In python3 iterator g.next() method is renamed to g.__next__(). using next(g) works in python 2 and 3. fix #3 --- btdht/utils.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/btdht/utils.pyx b/btdht/utils.pyx index 7339f4f..cf99690 100644 --- a/btdht/utils.pyx +++ b/btdht/utils.pyx @@ -843,13 +843,13 @@ class Scheduler(object): iterator = function() self._names[iterator] = name self._iterators[name] = iterator - typ = iterator.next() + typ = next(iterator) if typ == 0: if user == True: raise ValueError("Only queue based threads can be put in the user loop") self._time_based[iterator] = 0 elif typ == 1: - queue = iterator.next() + queue = next(iterator) if user == True: self._user_queue[iterator] = queue self._user_queue_sockets.append(queue.sock) @@ -1062,7 +1062,7 @@ class Scheduler(object): try: for iterator, t in six.iteritems(self._time_based): if now >= t: - to_set.append((iterator, iterator.next())) + to_set.append((iterator, next(iterator))) for iterator, t in to_set: self._time_based[iterator] = t except RuntimeError: @@ -1073,7 +1073,7 @@ class Scheduler(object): for sock in sockets: try: iterator = self._queue_base_socket_map[sock] - iterator.next() + next(iterator) except KeyError: pass except StopIteration as error: @@ -1107,7 +1107,7 @@ class Scheduler(object): for sock in sockets: try: iterator = self._queue_base_socket_map[sock] - iterator.next() + next(iterator) except KeyError: pass except StopIteration as error: From 3c15bcedec9cc6a051cbe90fe0807215a9877ef0 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sat, 3 Mar 2018 10:33:59 +0100 Subject: [PATCH 3/3] Update to version 0.3.2 * Fix raise of a UnboundLocalError instead of a socket.error in _process_incoming_message * Fix call to next method on iterator: In python3 iterator g.next() method is renamed to g.__next__() using next(g) works in python 2 and 3 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b882bdd..730d658 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ except ImportError: has_cython = False -VERSION = "0.3.1" +VERSION = "0.3.2" if __name__ == "__main__": c_extensions = [