Commits

Eric Larson committed e948dc6

pep8 fixes

  • Participants
  • Parent commits 14737ef

Comments (0)

Files changed (1)

File setuptools/ssl_support.py

-import sys, os, socket, urllib2, atexit, re
+import os
+import re
+import atexit
+import socket
+import urllib2
+
 from pkg_resources import ResolutionError, ExtractionError, resource_filename
 
 try:
 HTTPSHandler = HTTPSConnection = object
 
 for what, where in (
-    ('HTTPSHandler', ['urllib2','urllib.request']),
+    ('HTTPSHandler', ['urllib2', 'urllib.request']),
     ('HTTPSConnection', ['httplib', 'http.client']),
 ):
     for module in where:
         except ImportError:
             pass
 
-is_available = ssl is not None and object not in (HTTPSHandler, HTTPSConnection)
-
-
-
+is_available = ssl is not None and object not in (HTTPSHandler,
+                                                  HTTPSConnection)
 
 
 try:
     from socket import create_connection
 except ImportError:
-    _GLOBAL_DEFAULT_TIMEOUT = getattr(socket, '_GLOBAL_DEFAULT_TIMEOUT', object())
-    def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
+    _GLOBAL_DEFAULT_TIMEOUT = getattr(socket,
+                                      '_GLOBAL_DEFAULT_TIMEOUT',
+                                      object())
+
+
+    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
         before attempting to connect.  If no *timeout* is supplied, the
         global default timeout setting returned by :func:`getdefaulttimeout`
         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.
-        """   
+        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):
                 sock.connect(sa)
                 return sock
 
-            except error:
+            except error:  # This is never defined...
                 err = True
                 if sock is not None:
-                    sock.close()    
+                    sock.close()
         if err:
             raise
         else:
 except ImportError:
     class CertificateError(ValueError):
         pass
-       
+
     def _dnsname_to_pat(dn):
         pats = []
         for frag in dn.split(r'.'):
                 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.
         """
                 "subjectAltName fields were found")
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 class VerifyingHTTPSHandler(HTTPSHandler):
     """Simple verifying handler: no auth, subclasses, timeouts, etc."""
 
 
 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
 
         )
         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:
             self.sock.close()
             raise
 
+
 def opener_for(ca_bundle=None):
     """Get a urlopen() replacement that uses ca_bundle for verification"""
     return urllib2.build_opener(
         VerifyingHTTPSHandler(ca_bundle or find_ca_bundle())
     ).open
 
-        
 
 _wincerts = None
 
+
 def get_win_certfile():
     global _wincerts
     if _wincerts is not None:
         return _wincerts.name
 
-    try:        
+    try:
         from wincertstore import CertFile
     except ImportError:
         return None
             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
 
 def find_ca_bundle():
     """Return an existing CA bundle path, or None"""
-    if os.name=='nt':
+    if os.name == 'nt':
         return get_win_certfile()
     else:
         for cert_path in cert_paths:
         return resource_filename('certifi', 'cacert.pem')
     except (ImportError, ResolutionError, ExtractionError):
         return None
-
-
-
-
-