rest25/library/posixfile.rst => rest262/library/posixfile.rst
n1-.. % Manual text and implementation by Jaap Vermeulen
2- 
3- 
4:mod:`posixfile` --- File-like objects with locking support
5===========================================================
6
7.. module:: posixfile
8   :platform: Unix
9   :synopsis: A file-like object with support for locking.
n7+   :deprecated:
10.. moduleauthor:: Jaap Vermeulen
11.. sectionauthor:: Jaap Vermeulen
12
13
14.. index:: pair: POSIX; file object
15
16.. deprecated:: 1.5
n17-   .. index:: single: lockf() (in module fcntl)
18- 
19   The locking operation that this module provides is done better and more portably
20   by the :func:`fcntl.lockf` call.
21
22.. index:: single: fcntl() (in module fcntl)
23
24This module implements some additional functionality over the built-in file
25objects.  In particular, it implements file locking, control over the file
26flags, and an easy interface to duplicate the file object. The module defines a
27new file object, the posixfile object.  It has all the standard file object
28methods and adds the methods described below.  This module only works for
29certain flavors of Unix, since it uses :func:`fcntl.fcntl` for file locking.
n30- 
31-.. % 
32
33To instantiate a posixfile object, use the :func:`open` function in the
34:mod:`posixfile` module.  The resulting object looks and feels roughly the same
35as a standard file object.
36
37The :mod:`posixfile` module defines the following constants:
38
39
64.. function:: fileopen(fileobject)
65
66   Create a new posixfile object with the given standard file object. The resulting
67   object has the same filename and mode as the original file object.
68
69The posixfile object defines the following additional methods:
70
71
n72-.. function:: lock(fmt, [len[, start[, whence]]])
n66+.. method:: posixfile.lock(fmt, [len[, start[, whence]]])
73
74   Lock the specified section of the file that the file object is referring to.
75   The format is explained below in a table.  The *len* argument specifies the
76   length of the section that should be locked. The default is ``0``. *start*
77   specifies the starting offset of the section, where the default is ``0``.  The
78   *whence* argument specifies where the offset is relative to. It accepts one of
79   the constants :const:`SEEK_SET`, :const:`SEEK_CUR` or :const:`SEEK_END`.  The
80   default is :const:`SEEK_SET`.  For more information about the arguments refer to
81   the :manpage:`fcntl(2)` manual page on your system.
82
83
n84-.. function:: flags([flags])
n78+.. method:: posixfile.flags([flags])
85
86   Set the specified flags for the file that the file object is referring to.  The
87   new flags are ORed with the old flags, unless specified otherwise.  The format
88   is explained below in a table.  Without the *flags* argument a string indicating
89   the current flags is returned (this is the same as the ``?`` modifier).  For
90   more information about the flags refer to the :manpage:`fcntl(2)` manual page on
91   your system.
92
93
n94-.. function:: dup()
n88+.. method:: posixfile.dup()
95
96   Duplicate the file object and the underlying file pointer and file descriptor.
97   The resulting object behaves as if it were newly opened.
98
99
n100-.. function:: dup2(fd)
n94+.. method:: posixfile.dup2(fd)
101
102   Duplicate the file object and the underlying file pointer and file descriptor.
103   The new object will have the given file descriptor. Otherwise the resulting
104   object behaves as if it were newly opened.
105
106
t107-.. function:: file()
t101+.. method:: posixfile.file()
108
109   Return the standard file object that the posixfile object is based on.  This is
110   sometimes necessary for functions that insist on a standard file object.
111
112All methods raise :exc:`IOError` when the request fails.
113
114Format characters for the :meth:`lock` method have the following meaning:
115
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op