# -*- coding: utf-8 -*-

class RuleDoesNotExistError(Exception):
    
    def __init__(self, rulename):
        self.value = rulename

    def __str__(self):
        return 'rule "{0}" is not implemented'.format(self.value)

    def __unicode__(self):
        return str(self).decode('utf-8')
    

class RuleSet(object):

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

    def apply(self, obj):
        """
        obj: A file inside a container (cloudfiles.Object)
        """
        ret_val = False
        for rulename, arg in self.rules.iteritems():
            try:
                rule = getattr(self, rulename+'_rule')
            except AttributeError:
                raise RuleDoesNotExistError(rulename)
            else:
                ret_val &= rule(obj, arg)
            
        return ret_val


# -*- coding: utf-8 -*-

class RuleDoesNotExistError(Exception):
    
    def __init__(self, rulename):
        self.value = rulename

    def __str__(self):
        return 'rule "{0}" is not implemented.'.format(self.value)

    def __unicode__(self):
        return str(self).decode('utf-8')


class RuleSet(object):
    """
    Implements each rule that is applied to a cloudfile object.
    """

    def __init__(self, *args, **kwargs):
        """
        Accepts arguments in the form rulename=param.
        """

        self.rules = kwargs 

    def apply(self, obj):
        """
        Applies and ANDs each rule received as kwargs on object instantiation.
        obj: A file inside a container (cloudfiles.Object)
        retval: the AND of each rule applied to obj
        """
        ret_val = False
        for rulename, arg in self.rules.iteritems():
            try:
                rule = getattr(self, rulename+'_rule')
            except AttributeError:
                raise RuleDoesNotExistError(rulename)
            else:
                ret_val &= rule(obj, arg)

        return ret_val


Add better comments.