from ._AutoMappedMessageProcessor import AutoMappedMessageProcessor


def auto_map(params):
    def inner_auto_map(cls):
        class NewCls(object):
            _cls_attrs = params
            _real_cls = cls

            def __init__(self, *args, **kwargs):
                self.oInstance = cls(*args, **kwargs)

            def __getattribute__(self, s):
                try:
                    x = super(NewCls, self).__getattribute__(s)
                except AttributeError:
                    pass
                else:
                    return x
                return self.oInstance.__getattribute__(s)

        return NewCls

    return inner_auto_map


def exec_map(params):
    def inner_exec_map(cls):
        class NewCls(Exception):
            _cls_attrs = params
            _real_cls = cls

            def __init__(self, *args, **kwargs):
                self.oInstance = cls(*args, **kwargs)

            def __getattribute__(self, s):
                try:
                    x = super(NewCls, self).__getattribute__(s)
                except AttributeError:
                    pass
                else:
                    return x
                return self.oInstance.__getattribute__(s)

        return NewCls

    return inner_exec_map
