Commit 1fee48f1 authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 0.5~ds0

parent 9012188f
......@@ -10,3 +10,15 @@
* Now actually returning the file descriptor from the `Lock` class
0.4:
* Fixing a few bugs, added coveralls support, switched to py.test and added 100% test coverage.
- Fixing exception thrown when fail_when_locked is true
- Fixing exception "Lock object has no attribute '_release_lock'" when
fail_when_locked is true due to the call to Lock._release_lock() which fails
because _release_lock is not defined.
0.5:
* Python 3 support
......@@ -2,6 +2,22 @@
portalocker - Cross-platform locking library
############################################
.. image:: https://travis-ci.org/WoLpH/portalocker.png?branch=master
:alt: Test Status
:target: https://travis-ci.org/WoLpH/portalocker
.. image:: https://coveralls.io/repos/WoLpH/portalocker/badge.png?branch=master
:alt: Coverage Status
:target: https://coveralls.io/r/WoLpH/portalocker?branch=master
.. image:: https://landscape.io/github/WoLpH/portalocker/master/landscape.png
:target: https://landscape.io/github/WoLpH/portalocker/master
:alt: Code Health
.. image:: https://requires.io/github/WoLpH/portalocker/requirements.png?branch=master
:target: https://requires.io/github/WoLpH/portalocker/requirements/?branch=master
:alt: Requirements Status
Overview
--------
......
from portalocker import lock, unlock, LOCK_EX, LOCK_SH, LOCK_NB, LockException
from utils import Lock, AlreadyLocked
from .portalocker import lock, unlock, LOCK_EX, LOCK_SH, LOCK_NB, LockException
from .utils import Lock, AlreadyLocked
__all__ = [
'lock',
......
......@@ -84,11 +84,11 @@ else: # pragma: no cover
raise RuntimeError('PortaLocker only defined for nt and posix platforms')
def nt_lock(file, flags): # pragma: no cover
hfile = win32file._get_osfhandle(file.fileno())
def nt_lock(file_, flags): # pragma: no cover
hfile = win32file._get_osfhandle(file_.fileno())
try:
win32file.LockFileEx(hfile, flags, 0, -0x10000, __overlapped)
except pywintypes.error, exc_value:
except pywintypes.error as exc_value:
# error: (33, 'LockFileEx', 'The process cannot access the file
# because another process has locked a portion of the file.')
if exc_value[0] == 33:
......@@ -99,11 +99,11 @@ def nt_lock(file, flags): # pragma: no cover
raise
def nt_unlock(file): # pragma: no cover
hfile = win32file._get_osfhandle(file.fileno())
def nt_unlock(file_): # pragma: no cover
hfile = win32file._get_osfhandle(file_.fileno())
try:
win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
except pywintypes.error, exc_value:
except pywintypes.error as exc_value:
if exc_value[0] == 158:
# error: (158, 'UnlockFileEx', 'The segment is already '
# 'unlocked.')
......@@ -116,17 +116,17 @@ def nt_unlock(file): # pragma: no cover
raise
def posix_lock(file, flags):
def posix_lock(file_, flags):
try:
fcntl.flock(file.fileno(), flags)
except IOError, exc_value:
fcntl.flock(file_.fileno(), flags)
except IOError as exc_value:
# The exception code varies on different systems so we'll catch
# every IO error
raise LockException(*exc_value)
raise LockException(exc_value)
def posix_unlock(file):
fcntl.flock(file.fileno(), fcntl.LOCK_UN)
def posix_unlock(file_):
fcntl.flock(file_.fileno(), fcntl.LOCK_UN)
if os.name == 'nt': # pragma: no cover
lock = nt_lock
......@@ -136,19 +136,3 @@ elif os.name == 'posix':
unlock = posix_unlock
else: # pragma: no cover
raise RuntimeError('Your os %r is unsupported.' % os.name)
if __name__ == '__main__': # pragma: no cover
from time import time, strftime, localtime
import sys
import portalocker
log = open('log.txt', 'a+')
portalocker.lock(log, portalocker.LOCK_EX)
timestamp = strftime('%m/%d/%Y %H:%M:%S\n', localtime(time()))
log.write(timestamp)
print 'Wrote lines. Hit enter to release lock.'
dummy = sys.stdin.readline()
log.close()
from __future__ import with_statement
import time
from . import portalocker
......@@ -55,6 +55,8 @@ class Lock(object):
'''Acquire the locked filehandle'''
if timeout is None:
timeout = self.timeout
if timeout is None:
timeout = 0
if check_interval is None:
check_interval = self.check_interval
......@@ -72,7 +74,7 @@ class Lock(object):
try:
# Try to lock
fh = self._get_lock(fh)
except portalocker.LockException, exception:
except portalocker.LockException as exception:
# Try till the timeout is 0
while timeout > 0:
# Wait a bit
......@@ -85,7 +87,7 @@ class Lock(object):
# We already tried to the get the lock
# If fail_when_locked is true, then stop trying
if fail_when_locked:
raise AlreadyLocked(*exception)
raise AlreadyLocked(exception)
else: # pragma: no cover
# We've got the lock
......@@ -97,7 +99,7 @@ class Lock(object):
else:
# We got a timeout... reraising
raise portalocker.LockException(*exception)
raise portalocker.LockException(exception)
# Prepare the filehandle (truncate if needed)
fh = self._prepare_fh(fh)
......@@ -137,6 +139,6 @@ class Lock(object):
self.fh = self.acquire()
return self.fh
def __exit__(self, type, value, tb):
def __exit__(self, type_, value, tb):
if self.fh:
self.fh.close()
......@@ -4,7 +4,7 @@ import sys
author = 'Rick van Hattem'
email = 'Rick.van.Hattem@Fawo.nl'
version = '0.4'
version = '0.5'
desc = '''Wraps the portalocker recipe for easy usage'''
extra = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment