def openfile(path, mode="r", *args, **kw):
    if "x" not in mode or sys.version_info > (3, 0):
        return open(path, mode, *args, **kw)
    # http://stackoverflow.com/a/10979569/10840
    # O_EXCL is only supported on NFS when using NFSv3 or later on kernel 2.6 or later.
    flags = os.O_CREAT | os.O_EXCL | os.O_WRONLY
    try:
        handle = os.open(path, flags)
    except OSError as err:
        if err.errno == errno.EEXIST:
            raise FileExists(path)
        raise
    return os.fdopen(handle, mode.replace("x", "w"), *args, **kw)
Open file
dataset/ETHPy150Open dimagi/commcare-hq/corehq/blobs/fsdb.py/openfile