async def start_server(self, sock: anyio.abc.SocketStream, filter=None):  # pylint: disable=W0622
        """Start a server WS connection on this socket.

        Filter: an async callable that gets passed the initial Request.
        It may return an AcceptConnection message, a bool, or a string (the
        subprotocol to use).
        Returns: the Request message.
        """
        assert self._scope is None
        self._scope = True
        self._sock = sock
        self._connection = WSConnection(ConnectionType.SERVER)

        try:
            event = await self._next_event()
            if not isinstance(event, Request):
                raise ConnectionError("Failed to establish a connection",
                                      event)
            msg = None
            if filter is not None:
                msg = await filter(event)
                if not msg:
                    msg = RejectConnection()
                elif msg is True:
                    msg = None
                elif isinstance(msg, str):
                    msg = AcceptConnection(subprotocol=msg)
            if not msg:
                msg = AcceptConnection(subprotocol=event.subprotocols[0])
            data = self._connection.send(msg)
            await self._sock.send_all(data)
            if not isinstance(msg, AcceptConnection):
                raise ConnectionError("Not accepted", msg)
        finally:
            self._scope = None
async def start_server ( self , sock : anyio . abc . SocketStream , filter = None ) : assert self . _scope is None self . _scope = True self . _sock = sock self . _connection = WSConnection ( ConnectionType . SERVER ) try : event = await self . _next_event ( ) if not isinstance ( event , Request ) : raise ConnectionError ( "Failed to establish a connection" , event ) msg = None if filter is not None : msg = await filter ( event ) if not msg : msg = RejectConnection ( ) elif msg is True : msg = None elif isinstance ( msg , str ) : msg = AcceptConnection ( subprotocol = msg ) if not msg : msg = AcceptConnection ( subprotocol = event . subprotocols [ 0 ] ) data = self . _connection . send ( msg ) await self . _sock . send_all ( data ) if not isinstance ( msg , AcceptConnection ) : raise ConnectionError ( "Not accepted" , msg ) finally : self . _scope = None
Start a server WS connection on this socket.

        Filter: an async callable that gets passed the initial Request.
        It may return an AcceptConnection message, a bool, or a string (the
        subprotocol to use).
        Returns: the Request message.