aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/ssl_support.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/ssl_support.py')
-rw-r--r--setuptools/ssl_support.py55
1 files changed, 30 insertions, 25 deletions
diff --git a/setuptools/ssl_support.py b/setuptools/ssl_support.py
index efeef71d..fa5e4421 100644
--- a/setuptools/ssl_support.py
+++ b/setuptools/ssl_support.py
@@ -2,10 +2,10 @@ import os
import socket
import atexit
import re
+import functools
-from six.moves import urllib, http_client, map
+from six.moves import urllib, http_client, map, filter
-import pkg_resources
from pkg_resources import ResolutionError, ExtractionError
try:
@@ -204,47 +204,52 @@ def opener_for(ca_bundle=None):
).open
-_wincerts = None
+# from jaraco.functools
+def once(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ if not hasattr(func, 'always_returns'):
+ func.always_returns = func(*args, **kwargs)
+ return func.always_returns
+ return wrapper
+@once
def get_win_certfile():
- global _wincerts
- if _wincerts is not None:
- return _wincerts.name
-
try:
- from wincertstore import CertFile
+ import wincertstore
except ImportError:
return None
- class MyCertFile(CertFile):
- def __init__(self, stores=(), certs=()):
- CertFile.__init__(self)
- for store in stores:
- self.addstore(store)
- self.addcerts(certs)
+ class CertFile(wincertstore.CertFile):
+ def __init__(self):
+ super(CertFile, self).__init__()
atexit.register(self.close)
def close(self):
try:
- super(MyCertFile, self).close()
+ super(CertFile, self).close()
except OSError:
pass
- _wincerts = MyCertFile(stores=['CA', 'ROOT'])
+ _wincerts = CertFile()
+ _wincerts.addstore('CA')
+ _wincerts.addstore('ROOT')
return _wincerts.name
def find_ca_bundle():
"""Return an existing CA bundle path, or None"""
- if os.name == 'nt':
- return get_win_certfile()
- else:
- for cert_path in cert_paths:
- if os.path.isfile(cert_path):
- return cert_path
+ extant_cert_paths = filter(os.path.isfile, cert_paths)
+ return (
+ get_win_certfile()
+ or next(extant_cert_paths, None)
+ or _certifi_where()
+ )
+
+
+def _certifi_where():
try:
- import certifi
- return certifi.where()
+ return __import__('certifi').where()
except (ImportError, ResolutionError, ExtractionError):
- return None
+ pass