'Make the socket SSL aware'

def make_ssl_aware(self, sock, protocol):

    try:
        ssl_sock = wrap_socket(sock, keyfile=self.key_file, certfile=self.cert_file, ssl_version=protocol, server_hostname=self.host, timeout=self.timeout)
    except ssl.SSLError as ssl_exc:
        msg = "SSL    connection    error    occurred    with    protocol    %s:    '%s'"
        debug((msg % (protocol, ssl_exc.__class__.__name__)))
        sock.close()
    except Exception as e:
        msg = "Unexpected    exception    occurred    with    protocol    %s:    '%s'"
        debug((msg % (protocol, e)))
        sock.close()
    else:
        debug(('Successful    connection    using    protocol    %s' % protocol))
        self.sock = ssl_sock
        with _protocols_lock:
            _protocols.remove(protocol)
            _protocols.insert(0, protocol)
        return ssl_sock
    return None
