@@ -42,8 +42,8 @@ class BaseLock(object): |
42 | 42 | """Base class for file locking |
43 | 43 | """ |
44 | 44 |
|
45 | | - def __init__(self, fd): |
46 | | - self.fd = fd |
| 45 | + def __init__(self, fileobj): |
| 46 | + self.fileobj = fileobj |
47 | 47 | self.locked = False |
48 | 48 |
|
49 | 49 | def acquire(self): |
@@ -69,39 +69,39 @@ class UnixFileLock(BaseLock): |
69 | 69 | """Simple file locking for Unix using fcntl |
70 | 70 | """ |
71 | 71 |
|
72 | | - def __init__(self, fd, mode=None): |
73 | | - super(UnixFileLock, self).__init__(fd) |
| 72 | + def __init__(self, fileobj, mode=None): |
| 73 | + super(UnixFileLock, self).__init__(fileobj) |
74 | 74 |
|
75 | 75 | if mode is None: |
76 | 76 | mode = fcntl.LOCK_EX |
77 | 77 | self.mode = mode |
78 | 78 |
|
79 | 79 | def acquire(self): |
80 | 80 | try: |
81 | | - fcntl.flock(self.fd, self.mode) |
| 81 | + fcntl.flock(self.fileobj, self.mode) |
82 | 82 | self.locked = True |
83 | 83 | except IOError as e: |
84 | 84 | if e.errno != errno.ENOLCK: |
85 | 85 | raise e |
86 | 86 |
|
87 | 87 | def release(self): |
88 | | - fcntl.flock(self.fd, fcntl.LOCK_UN) |
| 88 | + fcntl.flock(self.fileobj, fcntl.LOCK_UN) |
89 | 89 | self.locked = False |
90 | 90 |
|
91 | 91 |
|
92 | 92 | class WindowsFileLock(BaseLock): |
93 | 93 | """Simple file locking for Windows using msvcrt |
94 | 94 | """ |
95 | 95 |
|
96 | | - def __init__(self, fd, mode=None): |
97 | | - super(WindowsFileLock, self).__init__(fd) |
| 96 | + def __init__(self, fileobj, mode=None): |
| 97 | + super(WindowsFileLock, self).__init__(fileobj) |
98 | 98 |
|
99 | 99 | def acquire(self): |
100 | | - msvcrt.locking(self.fd, msvcrt.LK_NBLCK, 1) |
| 100 | + msvcrt.locking(self.fileobj.fileno(), msvcrt.LK_NBLCK, 1) |
101 | 101 | self.locked = True |
102 | 102 |
|
103 | 103 | def release(self): |
104 | | - msvcrt.locking(self.fd, msvcrt.LK_UNLCK, 1) |
| 104 | + msvcrt.locking(self.fileobj.fileno(), msvcrt.LK_UNLCK, 1) |
105 | 105 | self.locked = False |
106 | 106 |
|
107 | 107 |
|
|