def arg_string()

in pygenie/jobs/utils.py [0:0]


def arg_string(func):
    """
    Decorator for accepting a string arg into a method and setting the attribute.
    The object's attribute name is specified via the method's arg name when the
    method is defined.
    """

    @_remove_wrapper_from_args
    def wrapper(*args, **kwargs):
        """Set arg to object's attribute as a string."""

        assert len(args) == 2, 'incorrect arguments to {}()'.format(func.__name__)
        attr_name = getargspec(func).args[1]
        self = args[0]
        value = args[1]

        assert is_str(value), \
            '{}() argument value should be a string'.format(func.__name__)

        setattr(self, attr_name, convert_to_unicode(value))

        return func(*args, **kwargs) or self

    return decorator(wrapper, func)