Blame SOURCES/BZ-1204825-add-curl-object-opt.patch

668d1d
commit 30b1a7ba876bc798199aba99c013983cba79d72a
668d1d
Author: Michal Domonkos <mdomonko@redhat.com>
668d1d
Date:   Wed Nov 23 12:54:05 2016 +0100
668d1d
668d1d
    Add curl_obj option. BZ 1204825
668d1d
668d1d
diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
668d1d
index 074a82f..25d8d17 100644
668d1d
--- a/urlgrabber/grabber.py
668d1d
+++ b/urlgrabber/grabber.py
668d1d
@@ -69,6 +69,24 @@ GENERAL ARGUMENTS (kwargs)
668d1d
    is None progress_obj is used in compatibility mode: finished files
668d1d
    are shown but there's no in-progress display.
668d1d
 
668d1d
+  curl_obj = None
668d1d
+
668d1d
+    a pycurl.Curl instance to be used instead of the default module-level
668d1d
+    instance.
668d1d
+
668d1d
+    Note that you don't have to configure the passed instance in any way;
668d1d
+    urlgrabber will do all the necessary work.
668d1d
+
668d1d
+    This option exists primarily to allow using urlgrabber from multiple
668d1d
+    threads in your application, in which case you would want to instantiate a
668d1d
+    fresh Curl object for each thread, to avoid race conditions.  See the curl
668d1d
+    documentation on thread safety for more information:
668d1d
+    https://curl.haxx.se/libcurl/c/threadsafe.html
668d1d
+
668d1d
+    Note that connection reuse (keepalive=1) is limited to the Curl instance it
668d1d
+    was enabled on so if you're using multiple instances in your application,
668d1d
+    connections won't be shared among them.
668d1d
+
668d1d
   text = None
668d1d
   
668d1d
     specifies alternative text to be passed to the progress meter
668d1d
@@ -971,6 +989,7 @@ class URLGrabberOptions:
668d1d
         """
668d1d
         self.progress_obj = None
668d1d
         self.multi_progress_obj = None
668d1d
+        self.curl_obj = None
668d1d
         self.throttle = 1.0
668d1d
         self.bandwidth = 0
668d1d
         self.retry = None
668d1d
@@ -1622,7 +1641,10 @@ class PyCurlFileObject(object):
668d1d
                 raise err
668d1d
 
668d1d
     def _do_open(self):
668d1d
-        self.curl_obj = _curl_cache
668d1d
+        if hasattr(self.opts, 'curl_obj') and self.opts.curl_obj is not None:
668d1d
+            self.curl_obj = self.opts.curl_obj
668d1d
+        else:
668d1d
+            self.curl_obj = _curl_cache
668d1d
         self.curl_obj.reset() # reset all old settings away, just in case
668d1d
         # setup any ranges
668d1d
         self._set_opts()