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.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/setuptools/ssl_support.py b/setuptools/ssl_support.py
index cc7db067..657197cf 100644
--- a/setuptools/ssl_support.py
+++ b/setuptools/ssl_support.py
@@ -3,9 +3,10 @@ import socket
import atexit
import re
+from setuptools.extern.six.moves import urllib, http_client, map
+
import pkg_resources
from pkg_resources import ResolutionError, ExtractionError
-from setuptools.compat import urllib2
try:
import ssl
@@ -24,20 +25,15 @@ cert_paths = """
/usr/local/share/certs/ca-root.crt
/etc/ssl/cert.pem
/System/Library/OpenSSL/certs/cert.pem
+/usr/local/share/certs/ca-root-nss.crt
""".strip().split()
-HTTPSHandler = HTTPSConnection = object
-
-for what, where in (
- ('HTTPSHandler', ['urllib2','urllib.request']),
- ('HTTPSConnection', ['httplib', 'http.client']),
-):
- for module in where:
- try:
- exec("from %s import %s" % (module, what))
- except ImportError:
- pass
+try:
+ HTTPSHandler = urllib.request.HTTPSHandler
+ HTTPSConnection = http_client.HTTPSConnection
+except AttributeError:
+ HTTPSHandler = HTTPSConnection = object
is_available = ssl is not None and object not in (HTTPSHandler, HTTPSConnection)
@@ -198,7 +194,7 @@ class VerifyingHTTPSConn(HTTPSConnection):
def opener_for(ca_bundle=None):
"""Get a urlopen() replacement that uses ca_bundle for verification"""
- return urllib2.build_opener(
+ return urllib.request.build_opener(
VerifyingHTTPSHandler(ca_bundle or find_ca_bundle())
).open
@@ -223,6 +219,12 @@ def get_win_certfile():
self.addcerts(certs)
atexit.register(self.close)
+ def close(self):
+ try:
+ super(MyCertFile, self).close()
+ except OSError:
+ pass
+
_wincerts = MyCertFile(stores=['CA', 'ROOT'])
return _wincerts.name