Cshark
Cshark

Reputation: 111

Adding methods to an asyncio Transport

Is it possible to add new methods to a standard asyncio transport?

e.g: Adding a send method to the SSL transport that serializes a protocol buffer, constructs a frame and uses the transports own write method to do a buffered write to the underlying socket.

There are plenty of asyncio server/client examples out there, but I have not been able to find ones that implement their own transport or extends an already existing one.

Upvotes: 1

Views: 286

Answers (1)

Andrew Svetlov
Andrew Svetlov

Reputation: 17366

No. You cannot add a new method or inherit from existing asyncio transport. Consider transports as final or sealed, like sockets.

You should never want to inherit from socket but make your class that embeds the socket instance inside, right?

The same for transport. See asyncio.streams as example of building new API layer on top of transport/protocol pair.

Upvotes: 1

Related Questions