コード例 #1
0
def validate_xml(data, dtd_directory=None):

    # Run xmllint to validate file

    dtd_file = DTD_FILE
    if dtd_directory is not None:
        dtd_file = '%s/%s' % (dtd_directory, DTD_FILE)

    p = Popen('xmllint --dtdvalid %s --noout -' % dtd_file,
              stdout=PIPE,
              stderr=PIPE,
              stdin=PIPE,
              shell=True)

    p.stdin.write(data)
    p.stdin.close()

    [sys.stdout.write(x) for x in p.stdout.readlines()]

    status = p.wait()

    if posix.WIFSIGNALED(status) or posix.WEXITSTATUS(status) != 0:
        return False

    return True
コード例 #2
0
ファイル: process.py プロジェクト: rbs-pli/oil
    def Wait(self):
        # This is a list of async jobs
        while True:
            try:
                pid, status = posix.wait()
            except OSError as e:
                #log('wait() error: %s', e)
                if e.errno == errno.ECHILD:
                    return False  # nothing to wait for caller should stop
                elif e.errno == errno.EINTR:
                    # This happens when we register a handler for SIGINT, and thus never
                    # get the KeyboardInterrupt exception?  Not sure why.
                    # Try
                    # $ cat   # Now hit Ctrl-C
                    #log('Continuing')
                    continue  # try again
                else:
                    # An error we don't know about.
                    raise
            else:
                break  # no exception thrown, so no need to retry

        #log('WAIT got %s %s', pid, status)

        # TODO: change status in more cases.
        if posix.WIFSIGNALED(status):
            if posix.WTERMSIG(status) == signal.SIGINT:
                print()
        elif posix.WIFEXITED(status):
            status = posix.WEXITSTATUS(status)
            #log('exit status: %s', status)

        # This could happen via coding error.  But this may legitimately happen
        # if a grandchild outlives the child (its parent).  Then it is reparented
        # under this process, so we might receive notification of its exit, even
        # though we didn't start it.  We can't have any knowledge of such
        # processes, so print a warning.
        if pid not in self.callbacks:
            util.warn("PID %d stopped, but osh didn't start it", pid)
            return True  # caller should keep waiting

        callback = self.callbacks.pop(pid)
        callback(pid, status)
        self.last_status = status  # for wait -n

        return True  # caller should keep waiting