From d97cbdee4cd72b291199bb000a4439099f75ef53 Mon Sep 17 00:00:00 2001
From: inso <insomniak.fr@gmaiL.com>
Date: Fri, 3 Feb 2017 18:47:49 +0100
Subject: [PATCH] Compatibility with new conn_handler method

---
 src/sakia/data/connectors/bma.py  | 10 +++++-----
 src/sakia/data/connectors/node.py | 12 ++++++------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/sakia/data/connectors/bma.py b/src/sakia/data/connectors/bma.py
index 9410d26a..20dc6bef 100644
--- a/src/sakia/data/connectors/bma.py
+++ b/src/sakia/data/connectors/bma.py
@@ -186,8 +186,8 @@ class BmaConnector:
                         endpoint = random.choice(endpoints)
                         self._logger.debug(
                             "Requesting {0} on endpoint {1}".format(str(request.__name__), str(endpoint)))
-                        futures.append(request(
-                            endpoint.conn_handler(session, proxy=self._user_parameters.proxy()),
+                        futures.append(request(next(
+                            endpoint.conn_handler(session, proxy=self._user_parameters.proxy())),
                             **req_args))
                 except StopIteration:
                     # When no more node is available, we go out of the while loop
@@ -234,7 +234,7 @@ class BmaConnector:
             try:
                 self._logger.debug("Requesting {0} on endpoint {1}".format(str(request.__name__), str(endpoint)))
                 async with aiohttp.ClientSession() as session:
-                    json_data = await request(endpoint.conn_handler(session), **req_args)
+                    json_data = await request(next(endpoint.conn_handler(session), **req_args))
                     return json_data
             except errors.DuniterError as e:
                 if e.ucode == errors.HTTP_LIMITATION:
@@ -283,8 +283,8 @@ class BmaConnector:
             with aiohttp.ClientSession() as session:
                 for endpoint in endpoints:
                     self._logger.debug("Trying to connect to : " + str(endpoint))
-                    reply = asyncio.ensure_future(request(endpoint.conn_handler(session,
-                                                                                proxy=self._user_parameters.proxy()),
+                    reply = asyncio.ensure_future(request(next(endpoint.conn_handler(session,
+                                                                                proxy=self._user_parameters.proxy())),
                                                           **req_args))
                     replies.append(reply)
 
diff --git a/src/sakia/data/connectors/node.py b/src/sakia/data/connectors/node.py
index f1172358..6916a425 100644
--- a/src/sakia/data/connectors/node.py
+++ b/src/sakia/data/connectors/node.py
@@ -95,7 +95,7 @@ class NodeConnector(QObject):
 
     async def safe_request(self, endpoint, request, proxy, req_args={}):
         try:
-            conn_handler = endpoint.conn_handler(self.session, proxy=proxy)
+            conn_handler = next(endpoint.conn_handler(self.session, proxy=proxy))
             data = await request(conn_handler, **req_args)
             return data
         except (ClientError, gaierror, TimeoutError, ConnectionRefusedError, DisconnectedError, ValueError) as e:
@@ -155,7 +155,7 @@ class NodeConnector(QObject):
         for endpoint in [e for e in self.node.endpoints if isinstance(e, BMAEndpoint)]:
             if not self._connected['block']:
                 try:
-                    conn_handler = endpoint.conn_handler(self.session, proxy=self._user_parameters.proxy())
+                    conn_handler = next(endpoint.conn_handler(self.session, proxy=self._user_parameters.proxy()))
                     ws_connection = bma.ws.block(conn_handler)
                     async with ws_connection as ws:
                         self._connected['block'] = True
@@ -222,8 +222,8 @@ class NodeConnector(QObject):
         self.node.state = Node.ONLINE
         if not self.node.current_buid or self.node.current_buid.sha_hash != block_data['hash']:
             for endpoint in [e for e in self.node.endpoints if isinstance(e, BMAEndpoint)]:
-                conn_handler = endpoint.conn_handler(self.session,
-                                                     proxy=self._user_parameters.proxy())
+                conn_handler = next(endpoint.conn_handler(self.session,
+                                                     proxy=self._user_parameters.proxy()))
                 self._logger.debug("Requesting {0}".format(conn_handler))
                 try:
                     previous_block = await self.safe_request(endpoint, bma.blockchain.block,
@@ -285,8 +285,8 @@ class NodeConnector(QObject):
         for endpoint in [e for e in self.node.endpoints if isinstance(e, BMAEndpoint)]:
             if not self._connected['peer']:
                 try:
-                    conn_handler = endpoint.conn_handler(self.session,
-                                                         proxy=self._user_parameters.proxy())
+                    conn_handler = next(endpoint.conn_handler(self.session,
+                                                         proxy=self._user_parameters.proxy()))
                     ws_connection = bma.ws.peer(conn_handler)
                     async with ws_connection as ws:
                         self._connected['peer'] = True
-- 
GitLab