Standard Module posixfile

posixfile posixfile object This module implements some additional functionality over the built-in file objects. In particular, it implements file locking, control over the file flags, and an easy interface to duplicate the file object. The module defines a new file object, the posixfile object. It inherits all the standard file object methods and adds the methods described below. To instantiate a posixfile object, use the open() function in the posixfile module. The resulting object looks and feels the same as a standard file object. The posixfile module defines the following constants:
\begin{datadesc}{SEEK_SET}
offset is calculated from the start of the file
\end{datadesc}

\begin{datadesc}{SEEK_CUR}
offset is calculated from the current position in the file
\end{datadesc}

\begin{datadesc}{SEEK_END}
offset is calculated from the end of the file
\end{datadesc}
The posixfile module defines the following functions:
\begin{funcdesc}{open}{filename\, mode}
Create a new posixfile object with the ...
... interpreted the same way as the \code{open()}
builtin function.
\end{funcdesc}

\begin{funcdesc}{openfile}{fileobject}
Create a new posixfile object with the g...
...ject has the same filename and mode as the original
file object.
\end{funcdesc}
The posixfile object defines the following additional methods:
\begin{funcdesc}{lock}{fmt\, \optional{len\optional{\, start
\optional{\, whence...
...out the arguments refer to the fcntl
manual page on your system.
\end{funcdesc}

\begin{funcdesc}{flags}{fmt}
Set the specified flags for the file that the file...
...n about the flags
refer to the fcntl manual page on your system.
\end{funcdesc}

\begin{funcdesc}{dup}{}
Duplicate the file object and the underlying file point...
...riptor. The resulting object behaves as if it were newly
opened.
\end{funcdesc}

\begin{funcdesc}{dup2}{fd}
Duplicate the file object and the underlying file po...
...therwise the resulting object behaves as if it were newly opened.
\end{funcdesc}

\begin{funcdesc}{file}{}
Return the standard file object that the posixfile obj...
...s necessary for functions that insist on a
standard file object.
\end{funcdesc}
All methods return IOError when the request fails. Format characters for the lock() method have the following meaning:
\begin{tableiii}{\vert c\vert l\vert c\vert}{samp}{Format}{Meaning}{}
\lineiii{...
...{}
\lineiii{w}{request a write lock for the specified section}{}
\end{tableiii}
In addition the following modifiers can be added to the format:
\begin{tableiii}{\vert c\vert l\vert c\vert}{samp}{Modifier}{Meaning}{Notes}
\l...
...}
{}&{\hskip0.5cm or \code{None} if there is no conflict.}&{}\\
\end{tableiii}
Note: (1) The lock returned is in the format (mode, len, start, whence, pid) where mode is a character representing the type of lock ('r' or 'w'). This modifier prevents a request from being granted; it is for query purposes only. Format character for the flags() method have the following meaning:
\begin{tableiii}{\vert c\vert l\vert c\vert}{samp}{Format}{Meaning}{}
\lineiii{...
...called non-blocking flag)}{}
\lineiii{s}{synchronization flag}{}
\end{tableiii}
In addition the following modifiers can be added to the format:
\begin{tableiii}{\vert c\vert l\vert c\vert}{samp}{Modifier}{Meaning}{Notes}
\l...
... in which the characters represent the flags that
are set.}{(2)}
\end{tableiii}
Note: (1) The ! and = modifiers are mutually exclusive. (2) This string represents the flags after they may have been altered by the same call. Examples:
from posixfile import *
file = open('/tmp/test', 'w')
file.lock('w|')
file.lock('u')
file.close()