def __create_stream_handler()

in awsiot/greengrasscoreipc/clientv2.py [0:0]


    def __create_stream_handler(real_self, operation, on_stream_event, on_stream_error, on_stream_closed):
        stream_handler_type = type(operation + 'Handler', (getattr(client, operation + "StreamHandler"),), {})
        if on_stream_event is not None:
            def handler(self, event):
                if real_self.executor is not None:
                    real_self.executor.submit(on_stream_event, event)
                else:
                    on_stream_event(event)
            setattr(stream_handler_type, "on_stream_event", handler)
        if on_stream_error is not None:
            def handler(self, error):
                return on_stream_error(error)
            setattr(stream_handler_type, "on_stream_error", handler)
        if on_stream_closed is not None:
            def handler(self):
                if real_self.executor is not None:
                    real_self.executor.submit(on_stream_closed)
                else:
                    on_stream_closed()
            setattr(stream_handler_type, "on_stream_closed", handler)
        return stream_handler_type()