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:
            on_stream_event = real_self.__wrap_error(on_stream_event)
            def handler(self, event):
                if real_self.executor is not None:
                    try:
                        real_self.executor.submit(on_stream_event, event)
                    except RuntimeError:
                        if not real_self.ignore_executor_exceptions:
                            raise
                else:
                    on_stream_event(event)
            setattr(stream_handler_type, "on_stream_event", handler)
        if on_stream_error is not None:
            on_stream_error = real_self.__wrap_error(on_stream_error)
            def handler(self, error):
                return on_stream_error(error)
            setattr(stream_handler_type, "on_stream_error", handler)
        if on_stream_closed is not None:
            on_stream_closed = real_self.__wrap_error(on_stream_closed)
            def handler(self):
                if real_self.executor is not None:
                    try:
                        real_self.executor.submit(on_stream_closed)
                    except RuntimeError:
                        if real_self.ignore_executor_exceptions:
                            raise
                else:
                    on_stream_closed()
            setattr(stream_handler_type, "on_stream_closed", handler)
        return stream_handler_type()