def _establish_client_connection(self, event: h11.InformationalResponse) -> AcceptConnection:
    accept = None
    connection_tokens = None
    accepts: List[str] = []
    subprotocol = None
    upgrade = b''
    headers: Headers = []
    for (name, value) in event.headers:
        name = name.lower()
        if (name == b'connection'):
            connection_tokens = split_comma_header(value)
            continue
        elif (name == b'sec-websocket-extensions'):
            accepts = split_comma_header(value)
            continue
        elif (name == b'sec-websocket-accept'):
            accept = value
            continue
        elif (name == b'sec-websocket-protocol'):
            subprotocol = value
            continue
        elif (name == b'upgrade'):
            upgrade = value
            continue
        headers.append((name, value))
    if ((connection_tokens is None) or (not any(((token.lower() == 'upgrade') for token in connection_tokens)))):
        raise RemoteProtocolError("Missing header, 'Connection: Upgrade'", event_hint=RejectConnection())
    if (upgrade.lower() != b'websocket'):
        raise RemoteProtocolError("Missing header, 'Upgrade: WebSocket'", event_hint=RejectConnection())
    accept_token = generate_accept_token(self._nonce)
    if (accept != accept_token):
        raise RemoteProtocolError('Bad accept token', event_hint=RejectConnection())
    if (subprotocol is not None):
        subprotocol = subprotocol.decode('ascii')
        if (subprotocol not in self._initiating_request.subprotocols):
            raise RemoteProtocolError('unrecognized subprotocol {}'.format(subprotocol), event_hint=RejectConnection())
    extensions = client_extensions_handshake(accepts, self._initiating_request.extensions)
    self._connection = Connection((ConnectionType.CLIENT if self.client else ConnectionType.SERVER), extensions, self._h11_connection.trailing_data[0])
    self._state = ConnectionState.OPEN
    return AcceptConnection(extensions=extensions, extra_headers=headers, subprotocol=subprotocol)
def _establish_client_connection(self, event: h11.InformationalResponse) -> AcceptConnection:
    accept = None
    connection_tokens = None
    accepts: List[str] = []
    subprotocol = None
    upgrade = b
    headers: Headers = []
    for (name, value) in event.headers:
        name = name.lower()
        if (name == b'connection'):
            connection_tokens = split_comma_header(value)
            continue
        elif (name == b'sec-websocket-extensions'):
            accepts = split_comma_header(value)
            continue
        elif (name == b'sec-websocket-accept'):
            accept = value
            continue
        elif (name == b'sec-websocket-protocol'):
            subprotocol = value
            continue
        elif (name == b'upgrade'):
            upgrade = value
            continue
        headers.append((name, value))
    if ((connection_tokens is None) or (not any(((token.lower() == 'upgrade') for token in connection_tokens)))):
        raise RemoteProtocolError("Missing header, 'Connection: Upgrade'", event_hint=RejectConnection())
    if (upgrade.lower() != b'websocket'):
        raise RemoteProtocolError("Missing header, 'Upgrade: WebSocket'", event_hint=RejectConnection())
    accept_token = generate_accept_token(self._nonce)
    if (accept != accept_token):
        raise RemoteProtocolError('Bad accept token', event_hint=RejectConnection())
    if (subprotocol is not None):
        subprotocol = subprotocol.decode('ascii')
        if (subprotocol not in self._initiating_request.subprotocols):
            raise RemoteProtocolError('unrecognized subprotocol {}'.format(subprotocol), event_hint=RejectConnection())
    extensions = client_extensions_handshake(accepts, self._initiating_request.extensions)
    self._connection = Connection((ConnectionType.CLIENT if self.client else ConnectionType.SERVER), extensions, self._h11_connection.trailing_data[0])
    self._state = ConnectionState.OPEN
    return AcceptConnection(extensions=extensions, extra_headers=headers, subprotocol=subprotocol)