import urllib

class GeneralError(Exception):
    def __init__(self, message, (lineno, filename)):
        self.message = message
        self.lineno = lineno
        self.filename = urllib.url2pathname(filename)

    def __str__(self):
        return "%s[%d]: %s" % (self.filename, self.lineno, self.message)

class UnknownElement(GeneralError):
    def __init__(self, parent, element, file_info):
        message = "unknown element '%s' in '%s'" % (element, parent)
        GeneralError.__init__(self, message, file_info)
        self.parent = parent
        self.element = element
        
class MissingAttribute(GeneralError):
    def __init__(self, element, attr, file_info):
        message = "missing required attribute '%s' for '%s'" % (attr, element)
        GeneralError.__init__(self, message, file_info)
        self.element = element
        self.attribute = attr

