Open a file or create it.

def open_fd(cls, name):
        """Open a file or create it."""
        # Try to create it, if can't, try to open.
        try:
            return os.open(name, os.O_CREAT | os.O_RDWR | os.O_EXCL)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
            return os.open(name, os.O_RDWR | os.O_EXCL)