aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/ssl_support.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-01-16 14:20:39 -0500
committerJason R. Coombs <jaraco@jaraco.com>2017-01-16 14:20:39 -0500
commit827c4c365fccad37907688b3518e7d351d3bfc5b (patch)
tree8263e273ffb39dfebba4732b9b1dcab7d75d28da /setuptools/ssl_support.py
parentf64c8f72952192655584994da11cdc9d40c54d32 (diff)
downloadexternal_python_setuptools-827c4c365fccad37907688b3518e7d351d3bfc5b.tar.gz
external_python_setuptools-827c4c365fccad37907688b3518e7d351d3bfc5b.tar.bz2
external_python_setuptools-827c4c365fccad37907688b3518e7d351d3bfc5b.zip
Refactor find_ca_bundle to simplify branching logic.
Diffstat (limited to 'setuptools/ssl_support.py')
-rw-r--r--setuptools/ssl_support.py29
1 files changed, 12 insertions, 17 deletions
diff --git a/setuptools/ssl_support.py b/setuptools/ssl_support.py
index 661b6b52..2313651f 100644
--- a/setuptools/ssl_support.py
+++ b/setuptools/ssl_support.py
@@ -3,7 +3,7 @@ import socket
import atexit
import re
-from setuptools.extern.six.moves import urllib, http_client, map
+from setuptools.extern.six.moves import urllib, http_client, map, filter
import pkg_resources
from pkg_resources import ResolutionError, ExtractionError
@@ -237,21 +237,16 @@ def get_win_certfile():
def find_ca_bundle():
"""Return an existing CA bundle path, or None"""
- ca_bundle_path = None
+ extant_cert_paths = filter(os.path.isfile, cert_paths)
+ return (
+ get_win_certfile()
+ or next(extant_cert_paths, None)
+ or _certifi_where()
+ )
- if os.name == 'nt':
- ca_bundle_path = get_win_certfile()
- else:
- for cert_path in cert_paths:
- if os.path.isfile(cert_path):
- ca_bundle_path = cert_path
- break
- if ca_bundle_path is None:
- try:
- import certifi
- ca_bundle_path = certifi.where()
- except (ImportError, ResolutionError, ExtractionError):
- pass
-
- return ca_bundle_path
+def _certifi_where():
+ try:
+ return __import__('certifi').where()
+ except (ImportError, ResolutionError, ExtractionError):
+ pass