Under Linux I can create files in Python with os.open and a specific permission this way:
open_flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC
open_mode = 0o660
temp_umask = 0o002
original_umask = os.umask(temp_umask) # Sets the umask and stores the old umask
fd = os.open(self._lock_file, open_flags, open_mode)
This way I get a file with 0o660 - rw-rw----.
This doesn't work for Windows:
fd = os.open("foobar",(os.O_RDWR|os.O_CREAT|os.O_TRUNC),0o660)
print(f'{os.stat("foobar")}')
print(f'{oct(S_IMODE(os.stat("foobar").st_mode))}')
This creates a file with 0o666. I know that file permissions under windows work very different from Linux and that there is no such thing as a umask.
So, my question would be: How can I create with os.open a file which is non executable and has the lowest possible rights for just read + write? How can the octal permission be interpreted for Windows?