Skip to content

Commit 976e755

Browse files
authored
Merge pull request #50 from bluca/portalocker_1.4.0
Restore compatibility with portalocker < 1.4.0
2 parents b91d36a + 47ce9a7 commit 976e755

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

msal_extensions/cache_lock.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import errno
55
import portalocker
6+
from distutils.version import LooseVersion
67

78

89
class CrossPlatLock(object):
@@ -12,6 +13,8 @@ class CrossPlatLock(object):
1213
"""
1314
def __init__(self, lockfile_path):
1415
self._lockpath = lockfile_path
16+
# Support for passing through arguments to the open syscall was added in v1.4.0
17+
open_kwargs = {'buffering': 0} if LooseVersion(portalocker.__version__) >= LooseVersion("1.4.0") else {}
1518
self._lock = portalocker.Lock(
1619
lockfile_path,
1720
mode='wb+',
@@ -20,7 +23,7 @@ def __init__(self, lockfile_path):
2023
# More information here:
2124
# https://docs.python.org/3/library/fcntl.html#fcntl.lockf
2225
flags=portalocker.LOCK_EX | portalocker.LOCK_NB,
23-
buffering=0)
26+
**open_kwargs)
2427

2528
def __enter__(self):
2629
file_handle = self._lock.__enter__()

0 commit comments

Comments
 (0)