
                         R    d dl Z d dlZd dlZd dlmZ  G d dej
                        Zy)    N)locked_filec                       e Zd ZdZd Zd Zy)_FcntlOpenerz0Open, lock, and unlock a file using fcntl.lockf.c                 X   | j                   r.t        j                  dj                  | j                              t        j
                         }t        j                  | j                         	 t        | j                  | j                        | _	        	 	 t        j                   | j                  j#                         t        j$                         d| _         y# t        $ r`}|j                  t        j                  t        j                  fv r*t        | j                  | j                        | _	        Y d}~yY d}~d}~ww xY w# t        $ r}|dk(  r |j                  t        j                  k7  r t        j
                         |z
  |k\  r{t        j&                  j)                  d| j                  |       | j                  r| j                  j+                          t        | j                  | j                        | _	        Y d}~yt        j,                  |       Y d}~nd}~ww xY w)a  Open the file and lock it.

        Args:
            timeout: float, How long to try to lock for.
            delay: float, How long to wait between retries

        Raises:
            AlreadyLockedException: if the lock is already acquired.
            IOError: if the open fails.
            CredentialsFileSymbolicLinkError: if the file is a symbolic
                                              link.
        zFile {0} is already lockedNTr   zCould not lock %s in %s seconds)_lockedr   AlreadyLockedExceptionformat	_filenametimevalidate_fileopen_mode_fhIOErrorerrnoEPERMEACCES_fallback_modefcntllockffilenoLOCK_EXloggerwarnclosesleep)selftimeoutdelay
start_timees        5lib/third_party/oauth2client/contrib/_fcntl_opener.pyopen_and_lockz_FcntlOpener.open_and_lock   s    <<44,33DNNCE EYY[
!!$..1	DNNDJJ7DH "DHHOO-u}}=#  	 ww5;;550C0CD 6	  "a<77ell*IIK*,8&&++,M,0NNGExx(#DNND4G4GHDH

5!!" s9   /%C AE 	E#AD>>E	H'B4H"H""H'c                     | j                   r<t        j                  | j                  j	                         t        j
                         d| _         | j                  r| j                  j                          yy)z:Close and unlock the file using the fcntl.lockf primitive.FN)r   r   r   r   r   LOCK_UNr   )r   s    r"   unlock_and_closez_FcntlOpener.unlock_and_closeK   sG    <<KK)5==988HHNN     N)__name__
__module____qualname____doc__r#   r&    r'   r"   r   r      s    :0"dr'   r   )r   r   r   oauth2client.contribr   _Openerr   r,   r'   r"   <module>r/      s%       ,;;&& ;r'   