summaryrefslogtreecommitdiff
path: root/setuptools/ssl_support.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/ssl_support.py')
-rw-r--r--setuptools/ssl_support.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/setuptools/ssl_support.py b/setuptools/ssl_support.py
index 2e615db3..32c8ee3c 100644
--- a/setuptools/ssl_support.py
+++ b/setuptools/ssl_support.py
@@ -1,5 +1,6 @@
-import sys, os, socket, urllib2, atexit
-from pkg_resources import ResolutionError, ExtractionError, resource_filename
+import sys, os, socket, urllib2, atexit, re
+import pkg_resources
+from pkg_resources import ResolutionError, ExtractionError
try:
import ssl
@@ -46,7 +47,7 @@ except ImportError:
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
"""Connect to *address* and return the socket object.
-
+
Convenience function. Connect to *address* (a 2-tuple ``(host,
port)``) and return the socket object. Passing the optional
*timeout* parameter will set the timeout on the socket instance
@@ -55,7 +56,7 @@ except ImportError:
is used. If *source_address* is set it must be a tuple of (host, port)
for the socket to bind as a source address before making the connection.
An host of '' or port 0 tells the OS to use the default.
- """
+ """
host, port = address
err = None
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
@@ -73,7 +74,7 @@ except ImportError:
except error:
err = True
if sock is not None:
- sock.close()
+ sock.close()
if err:
raise
else:
@@ -85,7 +86,7 @@ try:
except ImportError:
class CertificateError(ValueError):
pass
-
+
def _dnsname_to_pat(dn):
pats = []
for frag in dn.split(r'.'):
@@ -98,12 +99,12 @@ except ImportError:
frag = re.escape(frag)
pats.append(frag.replace(r'\*', '[^.]*'))
return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
-
+
def match_hostname(cert, hostname):
"""Verify that *cert* (in decoded format as returned by
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules
are mostly followed, but IP addresses are not accepted for *hostname*.
-
+
CertificateError is raised on failure. On success, the function
returns nothing.
"""
@@ -177,7 +178,7 @@ class VerifyingHTTPSHandler(HTTPSHandler):
class VerifyingHTTPSConn(HTTPSConnection):
"""Simple verifying connection: no auth, subclasses, timeouts, etc."""
- def __init__(self, host, ca_bundle, **kw):
+ def __init__(self, host, ca_bundle, **kw):
HTTPSConnection.__init__(self, host, **kw)
self.ca_bundle = ca_bundle
@@ -187,7 +188,7 @@ class VerifyingHTTPSConn(HTTPSConnection):
)
self.sock = ssl.wrap_socket(
sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs=self.ca_bundle
- )
+ )
try:
match_hostname(self.sock.getpeercert(), self.host)
except CertificateError:
@@ -201,7 +202,7 @@ def opener_for(ca_bundle=None):
VerifyingHTTPSHandler(ca_bundle or find_ca_bundle())
).open
-
+
_wincerts = None
@@ -210,7 +211,7 @@ def get_win_certfile():
if _wincerts is not None:
return _wincerts.name
- try:
+ try:
from wincertstore import CertFile
except ImportError:
return None
@@ -221,7 +222,7 @@ def get_win_certfile():
for store in stores:
self.addstore(store)
self.addcerts(certs)
- atexit.register(self.close)
+ atexit.register(self.close)
_wincerts = MyCertFile(stores=['CA', 'ROOT'])
return _wincerts.name