22# Requires python 1.5.2 or better.
33
44# ID line added by richard for Roundup file tracking
5- # $Id: portalocker.py,v 1.8 2004-02-11 23:55:09 richard Exp $
5+ # $Id: portalocker.py,v 1.9 2006-09-09 05:42:45 richard Exp $
66
77"""Cross-platform (posix/nt) API for flock-style file locking.
88
6666 FFFF0000 = - 65536
6767 def lock (file , flags ):
6868 hfile = win32file ._get_osfhandle (file .fileno ())
69- # LockFileEx is not supported on all Win32 platforms (Win95, Win98, WinME).
69+ # LockFileEx is not supported on all Win32 platforms (Win95, Win98,
70+ # WinME).
7071 # If it's not supported, win32file will raise an exception.
7172 # Try LockFileEx first, as it has more functionality and handles
7273 # blocking locks more efficiently.
@@ -80,10 +81,12 @@ def lock(file, flags):
8081
8182 # LockFileEx is not supported. Use LockFile.
8283 # LockFile does not support shared locking -- always exclusive.
83- # Care: the low/high length params are reversed compared to LockFileEx.
84+ # Care: the low/high length params are reversed compared to
85+ # LockFileEx.
8486 if not flags & LOCK_EX :
8587 import warnings
86- warnings .warn ("PortaLocker does not support shared locking on Win9x" , RuntimeWarning )
88+ warnings .warn ("PortaLocker does not support shared "
89+ "locking on Win9x" , RuntimeWarning )
8790 # LockFile only supports immediate-fail locking.
8891 if flags & LOCK_NB :
8992 win32file .LockFile (hfile , 0 , 0 , FFFF0000 , 0 )
@@ -96,7 +99,8 @@ def lock(file, flags):
9699 win32file .LockFile (hfile , 0 , 0 , FFFF0000 , 0 )
97100 break
98101 except win32file .error , e :
99- # Propagate upwards all exceptions other than lock violation.
102+ # Propagate upwards all exceptions other than lock
103+ # violation.
100104 if e [0 ] != winerror .ERROR_LOCK_VIOLATION :
101105 raise e
102106 # Sleep and poll again.
@@ -105,7 +109,8 @@ def lock(file, flags):
105109
106110 def unlock (file ):
107111 hfile = win32file ._get_osfhandle (file .fileno ())
108- # UnlockFileEx is not supported on all Win32 platforms (Win95, Win98, WinME).
112+ # UnlockFileEx is not supported on all Win32 platforms (Win95, Win98,
113+ # WinME).
109114 # If it's not supported, win32file will raise an api_error exception.
110115 try :
111116 win32file .UnlockFileEx (hfile , 0 , FFFF0000 , __overlapped )
@@ -116,7 +121,8 @@ def unlock(file):
116121 raise e
117122
118123 # UnlockFileEx is not supported. Use UnlockFile.
119- # Care: the low/high length params are reversed compared to UnLockFileEx.
124+ # Care: the low/high length params are reversed compared to
125+ # UnLockFileEx.
120126 win32file .UnlockFile (hfile , 0 , 0 , FFFF0000 , 0 )
121127
122128elif os .name == 'posix' :
0 commit comments