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

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