Module Expr Str Assign NameStore Str Import alias Import alias Import alias Import alias ImportFrom alias Assign NameStore Call AttributeLoad NameLoad attr NameLoad ClassDef bases NameLoad body Expr Str decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list FunctionDef arguments args NameParam defaults body If Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Raise Call NameLoad BinOpMod Str NameLoad decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Pass decorator_list FunctionDef arguments args NameParam defaults body Expr Str Pass decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str If AttributeLoad NameLoad attr body Raise Call NameLoad BinOpMod Str AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Expr Call NameLoad AttributeLoad NameLoad attr TryExcept body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad name NameStore body If CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Return Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr While NameLoad body TryExcept body Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr NameLoad BinOpBitOr BinOpBitOr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Break handlers ExceptHandler type NameLoad name NameStore body If CompareNotEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Raise If CompareGtE BinOpSub Call AttributeLoad NameLoad attr NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Return Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return BinOpMod Str NameLoad decorator_list decorator_list TryExcept body Import alias ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str If AttributeLoad NameLoad attr body Raise Call NameLoad BinOpMod Str AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Expr Call NameLoad AttributeLoad NameLoad attr TryExcept body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad name NameStore body If CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Return While NameLoad body TryExcept body Expr Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Return handlers ExceptHandler type NameLoad name NameStore body If CompareEq NameLoad Num body Raise NameLoad If CompareNotEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Raise NameLoad If CompareGtE BinOpSub Call AttributeLoad NameLoad attr NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Return Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list decorator_list handlers ExceptHandler type NameLoad body Assign NameStore NameLoad TryExcept body Import alias Import alias Import alias ClassDef bases NameLoad body Expr Str Assign NameStore Num Assign NameStore Num FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str If AttributeLoad NameLoad attr body Raise Call NameLoad BinOpMod Str AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Expr Call NameLoad AttributeLoad NameLoad attr TryExcept body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad name NameStore body If CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Return While NameLoad body TryExcept body Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr NameLoad BinOpBitOr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Num Num Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Return handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body If CompareEq NameLoad Num body Raise NameLoad If CompareNotEq SubscriptLoad NameLoad Index Num AttributeLoad NameLoad attr body Raise If CompareGtE BinOpSub Call AttributeLoad NameLoad attr NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Return Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If AttributeLoad NameLoad attr body TryExcept body Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr NameLoad Num Num Call AttributeLoad NameLoad attr handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body If CompareNotEq SubscriptLoad NameLoad Index Num AttributeLoad NameLoad attr body Raise Assign AttributeStore NameLoad attr NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list decorator_list handlers ExceptHandler type NameLoad body Assign NameStore NameLoad ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad body Expr Str Assign NameStore NameLoad If BoolOpAnd UnaryOpNot NameLoad NameLoad body If NameLoad body Assign NameStore Call NameLoad NameLoad NameLoad NameLoad If NameLoad body Assign NameStore Call NameLoad NameLoad NameLoad NameLoad If UnaryOpNot NameLoad body Assign NameStore Call NameLoad NameLoad NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list Call AttributeLoad NameLoad attr Num FunctionDef arguments args NameParam defaults body Expr Str Return AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num Num body Expr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list decorator_list
N/A N/A Locked file interface that should work on Unix and Windows pythons.

This module first tries to use fcntl locking to ensure serialized access
to a file, then falls back on a lock file if that is unavialable.

Usage:
    f = LockedFile('filename', 'r+b', 'rb')
    f.open_and_lock()
    if f.is_locked():
      print 'Acquired filename with r+b mode'
      f.file_handle().write('locked data')
    else:
      print 'Aquired filename with rb mode'
    f.unlock_and_close()
 N/A __author__ cache@google.com (David T McWherter) N/A errno N/A logging N/A os N/A time oauth2client util N/A logger N/A N/A logging getLogger __name__ CredentialsFileSymbolicLinkError N/A Exception N/A N/A Credentials files must not be symbolic links. N/A AlreadyLockedException N/A Exception N/A N/A Trying to lock a file that has already been locked by the LockedFile. N/A N/A validate_file N/A N/A filename N/A N/A N/A N/A N/A N/A os path islink filename N/A N/A N/A CredentialsFileSymbolicLinkError N/A File: %s is a symbolic link. filename N/A _Opener N/A object N/A N/A Base class for different locking primitives. __init__ N/A N/A self filename mode fallback_mode N/A N/A N/A Create an Opener.

    Args:
      filename: string, The pathname of the file.
      mode: string, The preferred mode to access the file with.
      fallback_mode: string, The mode to use if locking fails.
     N/A N/A self _locked False N/A N/A self _filename filename N/A N/A self _mode mode N/A N/A self _fallback_mode fallback_mode N/A N/A self _fh None N/A is_locked N/A N/A self N/A N/A N/A Was the file locked. N/A N/A self _locked N/A file_handle N/A N/A self N/A N/A N/A The file handle to the file. Valid only after opened. N/A N/A self _fh N/A filename N/A N/A self N/A N/A N/A The filename that is being locked. N/A N/A self _filename N/A open_and_lock N/A N/A self timeout delay N/A N/A N/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.
     N/A N/A unlock_and_close N/A N/A self N/A N/A N/A Unlock and close the file. N/A N/A N/A _PosixOpener N/A _Opener N/A N/A Lock files using Posix advisory lock files. open_and_lock N/A N/A self timeout delay N/A N/A N/A Open the file and lock it.

    Tries to create a .lock file next to the file we're trying to open.

    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.
     N/A N/A self _locked N/A N/A N/A AlreadyLockedException N/A File %s is already locked N/A self _filename N/A N/A self _locked False N/A N/A validate_file N/A self _filename N/A N/A N/A N/A self _fh N/A open N/A self _filename N/A self _mode N/A N/A N/A IOError N/A e N/A N/A N/A N/A e errno N/A errno EACCES N/A N/A N/A self _fh N/A open N/A self _filename N/A self _fallback_mode N/A N/A lock_filename N/A N/A self _posix_lockfile N/A self _filename N/A start_time N/A N/A time time N/A True N/A N/A N/A N/A N/A self _lock_fd N/A N/A os open lock_filename N/A N/A N/A os O_CREAT N/A os O_EXCL N/A os O_RDWR N/A N/A self _locked True N/A N/A N/A N/A OSError N/A e N/A N/A N/A N/A e errno N/A errno EEXIST N/A N/A N/A N/A N/A N/A N/A time time start_time timeout N/A N/A N/A N/A logger warn N/A Could not acquire lock %s in %s seconds N/A lock_filename timeout N/A N/A self _fh N/A N/A N/A N/A N/A self _fh close N/A N/A self _fh N/A open N/A self _filename N/A self _fallback_mode N/A N/A N/A N/A time sleep delay N/A unlock_and_close N/A N/A self N/A N/A N/A Unlock a file by removing the .lock file, and close the handle. N/A N/A self _locked N/A N/A lock_filename N/A N/A self _posix_lockfile N/A self _filename N/A N/A N/A os close N/A self _lock_fd N/A N/A N/A os unlink lock_filename N/A N/A self _locked False N/A N/A self _lock_fd None N/A N/A self _fh N/A N/A N/A N/A N/A self _fh close N/A _posix_lockfile N/A N/A self filename N/A N/A N/A The name of the lock file to use for posix locking. N/A N/A %s.lock filename N/A N/A N/A N/A N/A fcntl _FcntlOpener N/A _Opener N/A N/A Open, lock, and unlock a file using fcntl.lockf. open_and_lock N/A N/A self timeout delay N/A N/A N/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.
       N/A N/A self _locked N/A N/A N/A AlreadyLockedException N/A File %s is already locked N/A self _filename N/A start_time N/A N/A time time N/A N/A validate_file N/A self _filename N/A N/A N/A N/A self _fh N/A open N/A self _filename N/A self _mode N/A N/A N/A IOError N/A e N/A N/A N/A N/A e errno N/A errno EACCES N/A N/A N/A self _fh N/A open N/A self _filename N/A self _fallback_mode N/A N/A True N/A N/A N/A N/A N/A N/A fcntl lockf N/A N/A N/A self _fh fileno N/A fcntl LOCK_EX N/A N/A self _locked True N/A N/A N/A N/A IOError N/A e N/A N/A N/A timeout 0 N/A N/A e N/A N/A N/A e errno N/A errno EACCES N/A N/A e N/A N/A N/A N/A N/A time time start_time timeout N/A N/A N/A N/A logger warn N/A Could not lock %s in %s seconds N/A N/A self _filename timeout N/A N/A self _fh N/A N/A N/A N/A N/A self _fh close N/A N/A self _fh N/A open N/A self _filename N/A self _fallback_mode N/A N/A N/A N/A time sleep delay N/A unlock_and_close N/A N/A self N/A N/A N/A Close and unlock the file using the fcntl.lockf primitive. N/A N/A self _locked N/A N/A N/A N/A fcntl lockf N/A N/A N/A self _fh fileno N/A fcntl LOCK_UN N/A N/A self _locked False N/A N/A self _fh N/A N/A N/A N/A N/A self _fh close N/A N/A N/A N/A N/A ImportError N/A N/A _FcntlOpener None N/A N/A N/A pywintypes N/A win32con N/A win32file _Win32Opener N/A _Opener N/A N/A Open, lock, and unlock a file using windows primitives. N/A FILE_IN_USE_ERROR 33 N/A FILE_ALREADY_UNLOCKED_ERROR 158 open_and_lock N/A N/A self timeout delay N/A N/A N/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.
       N/A N/A self _locked N/A N/A N/A AlreadyLockedException N/A File %s is already locked N/A self _filename N/A start_time N/A N/A time time N/A N/A validate_file N/A self _filename N/A N/A N/A N/A self _fh N/A open N/A self _filename N/A self _mode N/A N/A N/A IOError N/A e N/A N/A N/A N/A e errno N/A errno EACCES N/A N/A N/A self _fh N/A open N/A self _filename N/A self _fallback_mode N/A N/A True N/A N/A N/A N/A hfile N/A N/A win32file _get_osfhandle N/A N/A N/A self _fh fileno N/A N/A N/A win32file LockFileEx hfile N/A N/A win32con LOCKFILE_FAIL_IMMEDIATELY N/A win32con LOCKFILE_EXCLUSIVE_LOCK 0 -65536 N/A N/A pywintypes OVERLAPPED N/A N/A self _locked True N/A N/A N/A N/A N/A pywintypes error N/A e N/A N/A N/A timeout 0 N/A N/A e N/A N/A N/A e N/A 0 N/A _Win32Opener FILE_IN_USE_ERROR N/A N/A N/A N/A N/A N/A N/A time time start_time timeout N/A N/A N/A N/A logger warn N/A Could not lock %s in %s seconds N/A N/A self _filename timeout N/A N/A self _fh N/A N/A N/A N/A N/A self _fh close N/A N/A self _fh N/A open N/A self _filename N/A self _fallback_mode N/A N/A N/A N/A time sleep delay N/A unlock_and_close N/A N/A self N/A N/A N/A Close and unlock the file using the win32 primitive. N/A N/A self _locked N/A N/A N/A N/A hfile N/A N/A win32file _get_osfhandle N/A N/A N/A self _fh fileno N/A N/A N/A win32file UnlockFileEx hfile 0 -65536 N/A N/A pywintypes OVERLAPPED N/A N/A N/A N/A pywintypes error N/A e N/A N/A N/A N/A e N/A 0 N/A _Win32Opener FILE_ALREADY_UNLOCKED_ERROR N/A N/A N/A N/A self _locked False N/A N/A self _fh N/A N/A N/A N/A N/A self _fh close N/A N/A N/A N/A N/A ImportError N/A N/A _Win32Opener None LockedFile N/A object N/A N/A Represent a file that has exclusive access. __init__ N/A N/A self filename mode fallback_mode use_native_locking N/A True N/A N/A Construct a LockedFile.

    Args:
      filename: string, The path of the file to open.
      mode: string, The mode to try to open the file with.
      fallback_mode: string, The mode to use if locking fails.
      use_native_locking: bool, Whether or not fcntl/win32 locking is used.
     N/A opener None N/A N/A N/A opener use_native_locking N/A N/A _Win32Opener N/A N/A opener N/A _Win32Opener filename mode fallback_mode N/A _FcntlOpener N/A N/A opener N/A _FcntlOpener filename mode fallback_mode N/A N/A opener N/A N/A opener N/A _PosixOpener filename mode fallback_mode N/A N/A self _opener opener N/A N/A N/A util positional 4 filename N/A N/A self N/A N/A N/A Return the filename we were constructed with. N/A N/A N/A self _opener _filename N/A file_handle N/A N/A self N/A N/A N/A Return the file_handle to the opened file. N/A N/A N/A N/A self _opener file_handle N/A is_locked N/A N/A self N/A N/A N/A Return whether we successfully locked the file. N/A N/A N/A N/A self _opener is_locked N/A open_and_lock N/A N/A self timeout delay N/A 0 0.05 N/A N/A Open the file, trying to lock it.

    Args:
      timeout: float, The number of seconds to try to acquire the lock.
      delay: float, The number of seconds to wait between retry attempts.

    Raises:
      AlreadyLockedException: if the lock is already acquired.
      IOError: if the open fails.
     N/A N/A N/A N/A self _opener open_and_lock timeout delay N/A unlock_and_close N/A N/A self N/A N/A N/A Unlock and close a file. N/A N/A N/A N/A self _opener unlock_and_close N/A N/A