"""quixote.errors

Exception classes used by Quixote
"""

class IgnoredException:
    """Handlers can raise this exception to bail out early; Quixote will
    ignore the exception and simply perform its usual processing.
    """
    
class AccessError:
    """Raised when a user's access to a given URL is denied.
    """

    def __init__ (self, description=None):
        if description is not None:
            self.reasons = [description]
        else:
            self.reasons = []
    
    def __len__(self):
        return len(self.reasons)
    
    def __getitem__(self, key):
        return self.reasons[ key ]
    
    def __str__ (self):
        if len(self.reasons) == 1:
            return self.reasons[0][1]
        else:
            return ("%d failure reasons: %s, etc." % 
                    (len(self.reasons), self.reasons[0]))
    
    def has_reasons(self):
        return len(self.reasons) > 0

    def add_reason(self, description):
        self.reasons.append(description)

    
