def push_back(stream, data):
stream_type = type(stream)
class PushbackStream(stream_type):
async def receive_some(self, max_bytes=None):
if max_bytes and max_bytes < len(data):
ret = data[:max_bytes]
del data[:max_bytes]
return ret
self.__class__ = stream_type
return data
stream.__class__ = PushbackStream
Got the job done.