Esempio n. 1
0
class Validator(object):
    checks = []

    def __init__(self):
        self.on_error = EventHook()
        self.on_warning = EventHook()

    def validate(self, url):
        config = getConfig()
        # Use the on_load event, because, if the document imports other
        # documents, we want to validate them all. (XXX Do we really?)
        config.on_load += self.validate_file
        try:
            config.load(url)
        except:
            # We should catch the errors in one or more of the validation
            # checks. (Fingers crossed.)
            pass

    def validate_file(self, url, namespace):
        try:
            content = urlopen(url)
        except ValueError as ex:
            self.on_error.fire(ex)
        else:
            for check in self.checks:
                try:
                    content.seek(0)
                except:
                    pass
                x = check(content)
                # Plumb the check events to the local events
                x.on_error += self.on_error.fire
                x.on_warning += self.on_warning.fire
                x.check()
            content.close()

    @classmethod
    def register(cls, check):
        cls.checks.append(check)
Esempio n. 2
0
class Validator(object):
    checks = []

    def __init__(self):
        self.on_error = EventHook()
        self.on_warning = EventHook()

    def validate(self, url):
        config = getConfig()
        # Use the on_load event, because, if the document imports other
        # documents, we want to validate them all. (XXX Do we really?)
        config.on_load += self.validate_file
        try:
            config.load(url)
        except:
            # We should catch the errors in one or more of the validation
            # checks. (Fingers crossed.)
            pass

    def validate_file(self, url, namespace):
        try:
            content = urlopen(url)
        except ValueError as ex:
            self.on_error.fire(ex)
        else:
            for check in self.checks:
                try:
                    content.seek(0)
                except:
                    pass
                x = check(content)
                # Plumb the check events to the local events
                x.on_error += self.on_error.fire
                x.on_warning += self.on_warning.fire
                x.check()
            content.close()

    @classmethod
    def register(cls, check):
        cls.checks.append(check)
Esempio n. 3
0
 def __init__(self):
     self.on_error = EventHook()
     self.on_warning = EventHook()
Esempio n. 4
0
 def __init__(self, document):
     self.document = document
     self.on_warning = EventHook()
     self.on_error = EventHook()
Esempio n. 5
0
 def __init__(self):
     self.on_error = EventHook()
     self.on_warning = EventHook()