|
Line 0
Link Here
|
|
|
1 |
diff --git a/lockfile/__init__.py b/lockfile/__init__.py |
| 2 |
index 7bb7b35..668b426 100644 |
| 3 |
--- a/lockfile/__init__.py |
| 4 |
+++ b/lockfile/__init__.py |
| 5 |
@@ -1,4 +1,3 @@ |
| 6 |
- |
| 7 |
""" |
| 8 |
lockfile.py - Platform-independent advisory file locks. |
| 9 |
|
| 10 |
@@ -50,6 +49,8 @@ Exceptions: |
| 11 |
NotMyLock - File was locked but not by the current thread/process |
| 12 |
""" |
| 13 |
|
| 14 |
+from __future__ import absolute_import |
| 15 |
+ |
| 16 |
import sys |
| 17 |
import socket |
| 18 |
import os |
| 19 |
@@ -257,7 +258,7 @@ def LinkFileLock(*args, **kwds): |
| 20 |
Do not use in new code. Instead, import LinkLockFile from the |
| 21 |
lockfile.linklockfile module. |
| 22 |
""" |
| 23 |
- import linklockfile |
| 24 |
+ from . import linklockfile |
| 25 |
return _fl_helper(linklockfile.LinkLockFile, "lockfile.linklockfile", |
| 26 |
*args, **kwds) |
| 27 |
|
| 28 |
@@ -267,7 +268,7 @@ def MkdirFileLock(*args, **kwds): |
| 29 |
Do not use in new code. Instead, import MkdirLockFile from the |
| 30 |
lockfile.mkdirlockfile module. |
| 31 |
""" |
| 32 |
- import mkdirlockfile |
| 33 |
+ from . import mkdirlockfile |
| 34 |
return _fl_helper(mkdirlockfile.MkdirLockFile, "lockfile.mkdirlockfile", |
| 35 |
*args, **kwds) |
| 36 |
|
| 37 |
@@ -277,7 +278,7 @@ def SQLiteFileLock(*args, **kwds): |
| 38 |
Do not use in new code. Instead, import SQLiteLockFile from the |
| 39 |
lockfile.mkdirlockfile module. |
| 40 |
""" |
| 41 |
- import sqlitelockfile |
| 42 |
+ from . import sqlitelockfile |
| 43 |
return _fl_helper(sqlitelockfile.SQLiteLockFile, "lockfile.sqlitelockfile", |
| 44 |
*args, **kwds) |
| 45 |
|
| 46 |
@@ -306,10 +307,10 @@ def locked(path, timeout=None): |
| 47 |
return decor |
| 48 |
|
| 49 |
if hasattr(os, "link"): |
| 50 |
- import linklockfile as _llf |
| 51 |
+ from . import linklockfile as _llf |
| 52 |
LockFile = _llf.LinkLockFile |
| 53 |
else: |
| 54 |
- import mkdirlockfile as _mlf |
| 55 |
+ from . import mkdirlockfile as _mlf |
| 56 |
LockFile = _mlf.MkdirLockFile |
| 57 |
|
| 58 |
FileLock = LockFile |
| 59 |
diff --git a/lockfile/pidlockfile.py b/lockfile/pidlockfile.py |
| 60 |
index 3fc8f63..a965ba8 100644 |
| 61 |
--- a/lockfile/pidlockfile.py |
| 62 |
+++ b/lockfile/pidlockfile.py |
| 63 |
@@ -78,7 +78,7 @@ class PIDLockFile(LockBase): |
| 64 |
while True: |
| 65 |
try: |
| 66 |
write_pid_to_pidfile(self.path) |
| 67 |
- except OSError, exc: |
| 68 |
+ except OSError as exc: |
| 69 |
if exc.errno == errno.EEXIST: |
| 70 |
# The lock creation failed. Maybe sleep a bit. |
| 71 |
if timeout is not None and time.time() > end_time: |
| 72 |
@@ -159,7 +159,7 @@ def write_pid_to_pidfile(pidfile_path): |
| 73 |
|
| 74 |
""" |
| 75 |
open_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY) |
| 76 |
- open_mode = 0644 |
| 77 |
+ open_mode = 0o644 |
| 78 |
pidfile_fd = os.open(pidfile_path, open_flags, open_mode) |
| 79 |
pidfile = os.fdopen(pidfile_fd, 'w') |
| 80 |
|
| 81 |
@@ -186,7 +186,7 @@ def remove_existing_pidfile(pidfile_path): |
| 82 |
""" |
| 83 |
try: |
| 84 |
os.remove(pidfile_path) |
| 85 |
- except OSError, exc: |
| 86 |
+ except OSError as exc: |
| 87 |
if exc.errno == errno.ENOENT: |
| 88 |
pass |
| 89 |
else: |
| 90 |
diff --git a/lockfile/sqlitelockfile.py b/lockfile/sqlitelockfile.py |
| 91 |
index ec75490..d596229 100644 |
| 92 |
--- a/lockfile/sqlitelockfile.py |
| 93 |
+++ b/lockfile/sqlitelockfile.py |
| 94 |
@@ -3,6 +3,11 @@ from __future__ import absolute_import, division |
| 95 |
import time |
| 96 |
import os |
| 97 |
|
| 98 |
+try: |
| 99 |
+ unicode |
| 100 |
+except NameError: |
| 101 |
+ unicode = str |
| 102 |
+ |
| 103 |
from . import LockBase, NotLocked, NotMyLock, LockTimeout, AlreadyLocked |
| 104 |
|
| 105 |
class SQLiteLockFile(LockBase): |