From eec4699fbfe48d574fe17ad143ad627f085968b5 Mon Sep 17 00:00:00 2001
From: "Antoine R. Dumont (@ardumont)" <antoine.romain.dumont@gmail.com>
Date: Thu, 24 May 2018 11:20:29 +0200
Subject: [PATCH] swh.core.api.SWHRemoteAPI: Permit to set a timeout option

Related T1061
---
 swh/core/api.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/swh/core/api.py b/swh/core/api.py
index 01f11059..2fc2d2df 100644
--- a/swh/core/api.py
+++ b/swh/core/api.py
@@ -24,17 +24,20 @@ class SWHRemoteAPI:
 
     """
 
-    def __init__(self, api_exception, url):
+    def __init__(self, api_exception, url, timeout=None):
         super().__init__()
         self.api_exception = api_exception
         base_url = url if url.endswith('/') else url + '/'
         self.url = base_url
         self.session = requests.Session()
+        self.timeout = timeout
 
     def _url(self, endpoint):
         return '%s%s' % (self.url, endpoint)
 
     def raw_post(self, endpoint, data, **opts):
+        if self.timeout and 'timeout' not in opts:
+            opts['timeout'] = self.timeout
         try:
             return self.session.post(
                 self._url(endpoint),
@@ -45,6 +48,8 @@ class SWHRemoteAPI:
             raise self.api_exception(e)
 
     def raw_get(self, endpoint, params=None, **opts):
+        if self.timeout and 'timeout' not in opts:
+            opts['timeout'] = self.timeout
         try:
             return self.session.get(
                 self._url(endpoint),
-- 
GitLab