'Wrap and return the given socket, plus WSGI environ entries.'

def wrap(self, sock):

    try:
        s = ssl.wrap_socket(sock, do_handshake_on_connect=True, server_side=True, certfile=self.certificate, keyfile=self.private_key, ssl_version=ssl.PROTOCOL_SSLv23)
    except ssl.SSLError:
        e = sys.exc_info()[1]
        if (e.errno == ssl.SSL_ERROR_EOF):
            return (None, {})
        elif (e.errno == ssl.SSL_ERROR_SSL):
            if e.args[1].endswith('http    request'):
                raise wsgiserver.NoSSLError
            elif e.args[1].endswith('unknown    protocol'):
                return (None, {})
        raise
    return (s, self.get_environ(s))
