MCPcopy Create free account
hub / github.com/python-websockets/websockets / factory

Method factory

src/websockets/asyncio/server.py:773–817  ·  view source on GitHub ↗

Create an asyncio protocol for managing a WebSocket connection.

()

Source from the content-addressed store, hash-verified

771 kwargs.setdefault("ssl_shutdown_timeout", close_timeout)
772
773 def factory() -> ServerConnection:
774 """
775 Create an asyncio protocol for managing a WebSocket connection.
776
777 """
778 # Create a closure to give select_subprotocol access to connection.
779 protocol_select_subprotocol: (
780 Callable[
781 [ServerProtocol, Sequence[Subprotocol]],
782 Subprotocol | None,
783 ]
784 | None
785 ) = None
786 if select_subprotocol is not None:
787
788 def protocol_select_subprotocol(
789 protocol: ServerProtocol,
790 subprotocols: Sequence[Subprotocol],
791 ) -> Subprotocol | None:
792 # mypy doesn't know that select_subprotocol is immutable.
793 assert select_subprotocol is not None
794 # Ensure this function is only used in the intended context.
795 assert protocol is connection.protocol
796 return select_subprotocol(connection, subprotocols)
797
798 # This is a protocol in the Sans-I/O implementation of websockets.
799 protocol = ServerProtocol(
800 origins=origins,
801 extensions=extensions,
802 subprotocols=subprotocols,
803 select_subprotocol=protocol_select_subprotocol,
804 max_size=max_size,
805 logger=logger,
806 )
807 # This is a connection in websockets and a protocol in asyncio.
808 connection = create_connection(
809 protocol,
810 self.server,
811 ping_interval=ping_interval,
812 ping_timeout=ping_timeout,
813 close_timeout=close_timeout,
814 max_queue=max_queue,
815 write_limit=write_limit,
816 )
817 return connection
818
819 loop = asyncio.get_running_loop()
820 if kwargs.pop("unix", False):

Callers

nothing calls this directly

Calls 1

ServerProtocolClass · 0.85

Tested by

no test coverage detected