Code

*** empty log message ***
[roundup.git] / roundup / backends / portalocker.py
index a062701dcd5de78b7f5b3c08852a41751fda136c..47ab263a2a2f157ddaea2860fa815e4e53e24cdd 100644 (file)
@@ -2,7 +2,7 @@
 #                  Requires python 1.5.2 or better.
 
 # ID line added by richard for Roundup file tracking
-# $Id: portalocker.py,v 1.5 2003-02-20 22:56:49 richard Exp $
+# $Id: portalocker.py,v 1.6 2003-07-03 23:43:46 richard Exp $
 
 """ Cross-platform (posix/nt) API for flock-style file locking.
 
@@ -60,6 +60,8 @@ else:
     raise RuntimeError("PortaLocker only defined for nt and posix platforms")
 
 if os.name == 'nt':
+    # eugh, but trying to suppress the warning doesn't work :(
+    FFFF0000 = 0xffff000 << 4
     def lock(file, flags):
         hfile = win32file._get_osfhandle(file.fileno())
         # LockFileEx is not supported on all Win32 platforms (Win95, Win98, WinME).
@@ -67,7 +69,7 @@ if os.name == 'nt':
         # Try LockFileEx first, as it has more functionality and handles
         # blocking locks more efficiently.
         try:
-            win32file.LockFileEx(hfile, flags, 0, 0xffff0000, __overlapped)
+            win32file.LockFileEx(hfile, flags, 0, FFFF0000, __overlapped)
         except win32file.error, e:
             import winerror
             # Propagate upwards all exceptions other than not-implemented.
@@ -82,14 +84,14 @@ if os.name == 'nt':
                 warnings.warn("PortaLocker does not support shared locking on Win9x", RuntimeWarning)
             # LockFile only supports immediate-fail locking.
             if flags & LOCK_NB:
-                win32file.LockFile(hfile, 0, 0, 0xffff0000, 0)
+                win32file.LockFile(hfile, 0, 0, FFFF0000, 0)
             else:
                 # Emulate a blocking lock with a polling loop.
                 import time
                 while 1:
                     # Attempt a lock.
                     try:
-                        win32file.LockFile(hfile, 0, 0, 0xffff0000, 0)
+                        win32file.LockFile(hfile, 0, 0, FFFF0000, 0)
                         break
                     except win32file.error, e:
                         # Propagate upwards all exceptions other than lock violation.
@@ -104,7 +106,7 @@ if os.name == 'nt':
         # UnlockFileEx is not supported on all Win32 platforms (Win95, Win98, WinME).
         # If it's not supported, win32file will raise an api_error exception.
         try:
-            win32file.UnlockFileEx(hfile, 0, 0xffff0000, __overlapped)
+            win32file.UnlockFileEx(hfile, 0, FFFF0000, __overlapped)
         except win32file.error, e:
             import winerror
             # Propagate upwards all exceptions other than not-implemented.
@@ -113,7 +115,7 @@ if os.name == 'nt':
             
             # UnlockFileEx is not supported. Use UnlockFile.
             # Care: the low/high length params are reversed compared to UnLockFileEx.
-            win32file.UnlockFile(hfile, 0, 0, 0xffff0000, 0)
+            win32file.UnlockFile(hfile, 0, 0, FFFF0000, 0)
 
 elif os.name =='posix':
     def lock(file, flags):