aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/patches/python-sphobjinv-defer-ssl-import.patch
blob: 96c2c897034a4dbdff6893c52ddc78695d306cb7 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
See suggestion in https://github.com/bskinn/sphobjinv/issues/275

This prevents the module from creating an ssl context upon import, when,
during a build especially, a certificate file may not be present.  Otherwise
module import would fail.

--- a/src/sphobjinv/inventory.py
+++ b/src/sphobjinv/inventory.py
@@ -30,7 +30,6 @@ Sphinx |objects.inv| files.
 """
 
 import re
-import ssl
 import urllib.request as urlrq
 from zlib import error as zlib_error
 
@@ -218,8 +217,15 @@ class Inventory:
     #: zlib compression line for v2 |objects.inv| header
     header_zlib = "# The remainder of this file is compressed using zlib."
 
-    # Private class member for SSL context, since context creation is slow(?)
-    _sslcontext = ssl.create_default_context(cafile=certifi.where())
+    # Private class member for SSL context
+    _sslcontext_ = None
+
+    @property
+    def _sslcontext(self):
+        import ssl
+        if not self._sslcontext_:
+            self._sslcontext_ = ssl.create_default_context(cafile=certifi.where())
+        return self._sslcontext_
 
     @property
     def count(self):