an argument is not always needed to be passed to open a file

This commit is contained in:
Daniel Wallace 2019-01-21 13:24:24 -06:00
parent 8a89cb2c4b
commit 6148c50781
No known key found for this signature in database
GPG key ID: 23676C5831BE870E

View file

@ -416,11 +416,13 @@ def flopen(*args, **kwargs):
'''
Shortcut for fopen with lock and context manager.
'''
with fopen(*args, **kwargs) as f_handle:
filename = args.pop(0)
vars = 'wa'
with fopen(filename, *args, **kwargs) as f_handle:
try:
if is_fcntl_available(check_sunos=True):
lock_type = fcntl.LOCK_SH
if 'w' in args[1] or 'a' in args[1]:
if args and any([var in args[0] for var in vars]):
lock_type = fcntl.LOCK_EX
fcntl.flock(f_handle.fileno(), lock_type)
yield f_handle