def __init__(self, folder, file_lock_time_wait=0.1):
self.folder = folder
self.key_filter_in = lambda key: key
self.key_filter_out = lambda key: key
self.file_lock_time_wait = file_lock_time_wait
# How long we should wait before retrying to lock a file held by another process
# We still need a mutex for each file as portalocker only blocks other processes
self.file_locks = defaultdict(thread.allocate_lock)
# Make sure we use valid filenames.
if sys.platform == "win32":
import base64
def key_filter_in_windows(key):
"""
Windows doesn't allow \ / : * ? "< > | in filenames.
To go around this encode the keys with base32.
"""
return to_native(base64.b32encode(to_bytes(key)))
def key_filter_out_windows(key):
"""
We need to decode the keys so regex based removal works.
"""
return to_native(base64.b32decode(to_bytes(key)))
self.key_filter_in = key_filter_in_windows
self.key_filter_out = key_filter_out_windows
评论列表
文章目录