Commit dd5da9cf authored by Jason R. Coombs's avatar Jason R. Coombs

Resave with excess whitespace removed

parent 6cf253f0
...@@ -46,7 +46,7 @@ except ImportError: ...@@ -46,7 +46,7 @@ except ImportError:
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
source_address=None): source_address=None):
"""Connect to *address* and return the socket object. """Connect to *address* and return the socket object.
Convenience function. Connect to *address* (a 2-tuple ``(host, Convenience function. Connect to *address* (a 2-tuple ``(host,
port)``) and return the socket object. Passing the optional port)``) and return the socket object. Passing the optional
*timeout* parameter will set the timeout on the socket instance *timeout* parameter will set the timeout on the socket instance
...@@ -55,7 +55,7 @@ except ImportError: ...@@ -55,7 +55,7 @@ except ImportError:
is used. If *source_address* is set it must be a tuple of (host, port) 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. 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. An host of '' or port 0 tells the OS to use the default.
""" """
host, port = address host, port = address
err = None err = None
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
...@@ -73,7 +73,7 @@ except ImportError: ...@@ -73,7 +73,7 @@ except ImportError:
except error: except error:
err = True err = True
if sock is not None: if sock is not None:
sock.close() sock.close()
if err: if err:
raise raise
else: else:
...@@ -85,7 +85,7 @@ try: ...@@ -85,7 +85,7 @@ try:
except ImportError: except ImportError:
class CertificateError(ValueError): class CertificateError(ValueError):
pass pass
def _dnsname_to_pat(dn): def _dnsname_to_pat(dn):
pats = [] pats = []
for frag in dn.split(r'.'): for frag in dn.split(r'.'):
...@@ -98,12 +98,12 @@ except ImportError: ...@@ -98,12 +98,12 @@ except ImportError:
frag = re.escape(frag) frag = re.escape(frag)
pats.append(frag.replace(r'\*', '[^.]*')) pats.append(frag.replace(r'\*', '[^.]*'))
return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE) return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
def match_hostname(cert, hostname): def match_hostname(cert, hostname):
"""Verify that *cert* (in decoded format as returned by """Verify that *cert* (in decoded format as returned by
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules
are mostly followed, but IP addresses are not accepted for *hostname*. are mostly followed, but IP addresses are not accepted for *hostname*.
CertificateError is raised on failure. On success, the function CertificateError is raised on failure. On success, the function
returns nothing. returns nothing.
""" """
...@@ -177,7 +177,7 @@ class VerifyingHTTPSHandler(HTTPSHandler): ...@@ -177,7 +177,7 @@ class VerifyingHTTPSHandler(HTTPSHandler):
class VerifyingHTTPSConn(HTTPSConnection): class VerifyingHTTPSConn(HTTPSConnection):
"""Simple verifying connection: no auth, subclasses, timeouts, etc.""" """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) HTTPSConnection.__init__(self, host, **kw)
self.ca_bundle = ca_bundle self.ca_bundle = ca_bundle
...@@ -187,7 +187,7 @@ class VerifyingHTTPSConn(HTTPSConnection): ...@@ -187,7 +187,7 @@ class VerifyingHTTPSConn(HTTPSConnection):
) )
self.sock = ssl.wrap_socket( self.sock = ssl.wrap_socket(
sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs=self.ca_bundle sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs=self.ca_bundle
) )
try: try:
match_hostname(self.sock.getpeercert(), self.host) match_hostname(self.sock.getpeercert(), self.host)
except CertificateError: except CertificateError:
...@@ -201,7 +201,7 @@ def opener_for(ca_bundle=None): ...@@ -201,7 +201,7 @@ def opener_for(ca_bundle=None):
VerifyingHTTPSHandler(ca_bundle or find_ca_bundle()) VerifyingHTTPSHandler(ca_bundle or find_ca_bundle())
).open ).open
_wincerts = None _wincerts = None
...@@ -210,7 +210,7 @@ def get_win_certfile(): ...@@ -210,7 +210,7 @@ def get_win_certfile():
if _wincerts is not None: if _wincerts is not None:
return _wincerts.name return _wincerts.name
try: try:
from wincertstore import CertFile from wincertstore import CertFile
except ImportError: except ImportError:
return None return None
...@@ -221,7 +221,7 @@ def get_win_certfile(): ...@@ -221,7 +221,7 @@ def get_win_certfile():
for store in stores: for store in stores:
self.addstore(store) self.addstore(store)
self.addcerts(certs) self.addcerts(certs)
atexit.register(self.close) atexit.register(self.close)
_wincerts = MyCertFile(stores=['CA', 'ROOT']) _wincerts = MyCertFile(stores=['CA', 'ROOT'])
return _wincerts.name return _wincerts.name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment