def clearUnMasked(func):
"""Decorator which clears the umask for a method.
The umask is a permissions mask that gets applied
whenever new files or folders are created. For I/O methods
that have a permissions parameter, it is important that the
umask is cleared prior to execution, otherwise the default
umask may alter the resulting permissions
:type func: function
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
# set umask to zero, store old umask
oldMask = os.umask(0)
try:
# execute method payload
return func(*args, **kwargs)
finally:
# set mask back to previous value
os.umask(oldMask)
return wrapper
评论列表
文章目录