�
���cc @ s� d d l Z d d l Z d d l m Z d d l m Z e j d � Z e j e j � d e
f d � � YZ d e
f d � � YZ d d g Z
d S(
i����N( t Locki ( t Timeoutt filelockt AcquireReturnProxyc B s) e Z d Z d � Z d � Z d � Z RS( sD A context aware object that will release the lock file when exiting.c C s
| | _ d S( N( t lock( t selfR ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyt __init__ s c C s | j S( N( R ( R ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyt __enter__ s c C s | j j � d S( N( R t release( R t exc_typet exc_valuet traceback( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyt __exit__ s ( t __name__t
__module__t __doc__R R R ( ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyR s t BaseFileLockc B s� e Z d Z d d � Z e d � � Z e d � � Z e j d � � Z d � Z d � Z e d � � Z
d d d
� Z e
d � Z d � Z d
� Z d � Z RS( s+ Abstract base class for a file lock object.i����c C s4 | | _ d | _ | | _ t � | _ d | _ d S( s�
Create a new lock object.
:param lock_file: path to the file
:param timeout: default timeout when acquiring the lock. It will be used as fallback value in the acquire
method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a negative value.
A timeout of 0 means, that there is exactly one attempt to acquire the file lock.
i N( t
_lock_filet Nonet
_lock_file_fdt timeoutR t _thread_lockt
_lock_counter( R t lock_fileR ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyR s
c C s | j S( s :return: path to the lock file( R ( R ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyR 8 s c C s | j S( sU
:return: the default timeout value
.. versionadded:: 2.0.0
( t _timeout( R ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyR = s c C s t | � | _ d S( sX
Change the default timeout value.
:param value: the new value
N( t floatR ( R t value( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyR F s c C s
t � d S( sb If the file lock could be acquired, self._lock_file_fd holds the file descriptor of the lock file.N( t NotImplementedError( R ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyt _acquireO s c C s
t � d S( s6 Releases the lock and sets self._lock_file_fd to None.N( R ( R ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyt _releaseS s c C s
| j d k S( s�
:return: A boolean indicating if the lock file is holding the lock currently.
.. versionchanged:: 2.0.0
This was previously a method and is now a property.
N( R R ( R ( ( s1 /usr/lib/python2.7/site-packages/filelock/_api.pyt is_lockedW s
g�������?c C s� | d k r | j } n | j � | j d 7_ Wd QXt | � } | j } t j � } y� x� t r4| j �. | j s� t j
d | | � | j � n Wd QX| j r� t j
d | | � Pq^ d | k o� t j � | k n rt j
d | | � t | j � � q^ d } t j
| | | | � t j
| � q^ WWn= t k
ru| j � t d | j d � | _ Wd QX� n Xt d | � S( s
Try to acquire the file lock.
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
:param poll_intervall: interval of trying to acquire the lock file
:raises Timeout: if fails to acquire lock within the timeout period
:return: a context object that will unlock the file when the context is exited
.. code-block:: python
# You can use this method in the context manager (recommended)
with lock.acquire():
pass
# Or use an equivalent try-finally construct:
lock.acquire()
try:
pass
finally:
lock.release()
.. versionchanged:: 2.0.0
This method returns now a *proxy* object instead of *self*,
so that it can be used in a with statement without side effects.
i Ns# Attempting to acquire lock %s on %ss Lock %s acquired on %si s"