| |
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| <html><head><title>Python: module oauth2client.locked_file</title> |
| </head><body bgcolor="#f0f0f8"> |
| |
| <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| <tr bgcolor="#7799ee"> |
| <td valign=bottom> <br> |
| <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="oauth2client.html"><font color="#ffffff">oauth2client</font></a>.locked_file</strong></big></big></font></td |
| ><td align=right valign=bottom |
| ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/clean/oauth2client/locked_file.py">/home/jcgregorio/projects/clean/oauth2client/locked_file.py</a></font></td></tr></table> |
| <p><tt>Locked file interface that should work on Unix and Windows pythons.<br> |
| <br> |
| This module first tries to use fcntl locking to ensure serialized access<br> |
| to a file, then falls back on a lock file if that is unavialable.<br> |
| <br> |
| Usage:<br> |
| f = <a href="#LockedFile">LockedFile</a>('filename', 'r+b', 'rb')<br> |
| f.open_and_lock()<br> |
| if f.is_locked():<br> |
| print 'Acquired filename with r+b mode'<br> |
| f.file_handle().write('locked data')<br> |
| else:<br> |
| print 'Aquired filename with rb mode'<br> |
| f.unlock_and_close()</tt></p> |
| <p> |
| <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| <tr bgcolor="#aa55cc"> |
| <td colspan=3 valign=bottom> <br> |
| <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
| |
| <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
| <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="errno.html">errno</a><br> |
| <a href="fcntl.html">fcntl</a><br> |
| </td><td width="25%" valign=top><a href="logging.html">logging</a><br> |
| <a href="os.html">os</a><br> |
| </td><td width="25%" valign=top><a href="time.html">time</a><br> |
| </td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
| <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| <tr bgcolor="#ee77aa"> |
| <td colspan=3 valign=bottom> <br> |
| <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| |
| <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| <td width="100%"><dl> |
| <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> |
| </font></dt><dd> |
| <dl> |
| <dt><font face="helvetica, arial"><a href="oauth2client.locked_file.html#LockedFile">LockedFile</a> |
| </font></dt></dl> |
| </dd> |
| <dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>(<a href="exceptions.html#BaseException">exceptions.BaseException</a>) |
| </font></dt><dd> |
| <dl> |
| <dt><font face="helvetica, arial"><a href="oauth2client.locked_file.html#AlreadyLockedException">AlreadyLockedException</a> |
| </font></dt></dl> |
| </dd> |
| </dl> |
| <p> |
| <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| <tr bgcolor="#ffc8d8"> |
| <td colspan=3 valign=bottom> <br> |
| <font color="#000000" face="helvetica, arial"><a name="AlreadyLockedException">class <strong>AlreadyLockedException</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr> |
| |
| <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| <td colspan=2><tt>Trying to lock a file that has already been locked by the <a href="#LockedFile">LockedFile</a>.<br> </tt></td></tr> |
| <tr><td> </td> |
| <td width="100%"><dl><dt>Method resolution order:</dt> |
| <dd><a href="oauth2client.locked_file.html#AlreadyLockedException">AlreadyLockedException</a></dd> |
| <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> |
| <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd> |
| <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
| </dl> |
| <hr> |
| Data descriptors defined here:<br> |
| <dl><dt><strong>__weakref__</strong></dt> |
| <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| </dl> |
| <hr> |
| Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> |
| <dl><dt><a name="AlreadyLockedException-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__init__">__init__</a>(...) initializes x; see x.__class__.__doc__ for signature</tt></dd></dl> |
| |
| <hr> |
| Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> |
| <dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#AlreadyLockedException-__new__">__new__</a>(S, ...) -> a new <a href="__builtin__.html#object">object</a> with type S, a subtype of T</tt></dl> |
| |
| <hr> |
| Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br> |
| <dl><dt><a name="AlreadyLockedException-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br> |
| <br> |
| Use of negative indices is not supported.</tt></dd></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#AlreadyLockedException-__str__">__str__</a>() <==> str(x)</tt></dd></dl> |
| |
| <dl><dt><a name="AlreadyLockedException-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl> |
| |
| <hr> |
| Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br> |
| <dl><dt><strong>__dict__</strong></dt> |
| </dl> |
| <dl><dt><strong>args</strong></dt> |
| </dl> |
| <dl><dt><strong>message</strong></dt> |
| </dl> |
| </td></tr></table> <p> |
| <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| <tr bgcolor="#ffc8d8"> |
| <td colspan=3 valign=bottom> <br> |
| <font color="#000000" face="helvetica, arial"><a name="LockedFile">class <strong>LockedFile</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| |
| <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| <td colspan=2><tt>Represent a file that has exclusive access.<br> </tt></td></tr> |
| <tr><td> </td> |
| <td width="100%">Methods defined here:<br> |
| <dl><dt><a name="LockedFile-__init__"><strong>__init__</strong></a>(self, filename, mode, fallback_mode, use_fcntl<font color="#909090">=True</font>)</dt><dd><tt>Construct a <a href="#LockedFile">LockedFile</a>.<br> |
| <br> |
| Args:<br> |
| filename: string, The path of the file to open.<br> |
| mode: string, The mode to try to open the file with.<br> |
| fallback_mode: string, The mode to use if locking fails.<br> |
| use_fcntl: string, Whether or not fcntl-based locking should be used.</tt></dd></dl> |
| |
| <dl><dt><a name="LockedFile-file_handle"><strong>file_handle</strong></a>(self)</dt><dd><tt>Return the file_handle to the opened file.</tt></dd></dl> |
| |
| <dl><dt><a name="LockedFile-filename"><strong>filename</strong></a>(self)</dt><dd><tt>Return the filename we were constructed with.</tt></dd></dl> |
| |
| <dl><dt><a name="LockedFile-is_locked"><strong>is_locked</strong></a>(self)</dt><dd><tt>Return whether we successfully locked the file.</tt></dd></dl> |
| |
| <dl><dt><a name="LockedFile-open_and_lock"><strong>open_and_lock</strong></a>(self, timeout<font color="#909090">=0</font>, delay<font color="#909090">=0.050000000000000003</font>)</dt><dd><tt>Open the file, trying to lock it.<br> |
| <br> |
| Args:<br> |
| timeout: float, The number of seconds to try to acquire the lock.<br> |
| delay: float, The number of seconds to wait between retry attempts.<br> |
| <br> |
| Raises:<br> |
| <a href="#AlreadyLockedException">AlreadyLockedException</a>: if the lock is already acquired.<br> |
| IOError: if the open fails.</tt></dd></dl> |
| |
| <dl><dt><a name="LockedFile-unlock_and_close"><strong>unlock_and_close</strong></a>(self)</dt><dd><tt>Unlock and close a file.</tt></dd></dl> |
| |
| <hr> |
| Data descriptors defined here:<br> |
| <dl><dt><strong>__dict__</strong></dt> |
| <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| </dl> |
| <dl><dt><strong>__weakref__</strong></dt> |
| <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| </dl> |
| </td></tr></table></td></tr></table><p> |
| <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| <tr bgcolor="#55aa55"> |
| <td colspan=3 valign=bottom> <br> |
| <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| |
| <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
| <td width="100%"><strong>__author__</strong> = 'cache@google.com (David T McWherter)'<br> |
| <strong>logger</strong> = <logging.Logger instance></td></tr></table><p> |
| <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| <tr bgcolor="#7799ee"> |
| <td colspan=3 valign=bottom> <br> |
| <font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr> |
| |
| <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
| <td width="100%">cache@google.com (David T McWherter)</td></tr></table> |
| </body></html> |