~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Doc/c-api/file.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
.. index:: object: file
9
9
 
10
 
Python's built-in file objects are implemented entirely on the :ctype:`FILE\*`
11
 
support from the C standard library.  This is an implementation detail and may
12
 
change in future releases of Python.  The ``PyFile_`` APIs are a wrapper over
13
 
the :mod:`io` module.
14
 
 
15
 
 
16
 
.. cfunction:: PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding, char *newline, int closefd)
17
 
 
18
 
   Create a new :ctype:`PyFileObject` from the file descriptor of an already
19
 
   opened file *fd*. The arguments *name*, *encoding* and *newline* can be
20
 
   *NULL* to use the defaults; *buffering* can be *-1* to use the default.
21
 
   Return *NULL* on failure.
 
10
These APIs are a minimal emulation of the Python 2 C API for built-in file
 
11
objects, which used to rely on the buffered I/O (:ctype:`FILE\*`) support
 
12
from the C standard library.  In Python 3, files and streams use the new
 
13
:mod:`io` module, which defines several layers over the low-level unbuffered
 
14
I/O of the operating system.  The functions described below are
 
15
convenience C wrappers over these new APIs, and meant mostly for internal
 
16
error reporting in the interpreter; third-party code is advised to access
 
17
the :mod:`io` APIs instead.
 
18
 
 
19
 
 
20
.. cfunction:: PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding, char *errors, char *newline, int closefd)
 
21
 
 
22
   Create a Python file object from the file descriptor of an already
 
23
   opened file *fd*.  The arguments *name*, *encoding*, *errors* and *newline*
 
24
   can be *NULL* to use the defaults; *buffering* can be *-1* to use the
 
25
   default.  Return *NULL* on failure.  For a more comprehensive description of
 
26
   the arguments, please refer to the :func:`io.open` function documentation.
22
27
 
23
28
   .. warning::
24
29
 
25
 
     Take care when you are mixing streams and descriptors! For more
26
 
     information, see `the GNU C Library docs
27
 
     <http://www.gnu.org/software/libc/manual/html_node/Stream_002fDescriptor-Precautions.html#Stream_002fDescriptor-Precautions>`_.
 
30
     Since Python streams have their own buffering layer, mixing them with
 
31
     OS-level file descriptors can produce various issues (such as unexpected
 
32
     ordering of data).
28
33
 
29
34
 
30
35
.. cfunction:: int PyObject_AsFileDescriptor(PyObject *p)