]> granicus.if.org Git - python/commitdiff
Merged revisions 76896 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 19 Dec 2009 21:03:36 +0000 (21:03 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 19 Dec 2009 21:03:36 +0000 (21:03 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76896 | antoine.pitrou | 2009-12-19 22:01:10 +0100 (sam., 19 déc. 2009) | 3 lines

  Issue #7545: improve documentation of the `buffering` argument in io.open().
........

Doc/library/io.rst
Lib/io.py

index a72d3ed05c3f33b1c1fc25270537397de604b3ad..a8a4068c7f38be821c14e53c5fcba8a4dfc90bc2 100644 (file)
@@ -94,10 +94,20 @@ Module Interface
    strings, the bytes having been first decoded using a platform-dependent
    encoding or using the specified *encoding* if given.
 
-   *buffering* is an optional integer used to set the buffering policy.  By
-   default full buffering is on.  Pass 0 to switch buffering off (only allowed
-   in binary mode), 1 to set line buffering, and an integer > 1 to indicate the
-   size of the buffer.
+   *buffering* is an optional integer used to set the buffering policy.
+   Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
+   line buffering (only usable in text mode), and an integer > 1 to indicate
+   the size of a fixed-size chunk buffer.  When no *buffering* argument is
+   given, the default buffering policy works as follows:
+
+   * Binary files are buffered in fixed-size chunks; the size of the buffer
+     is chosen using a heuristic trying to determine the underlying device's
+     "block size" and falling back on :attr:`DEFAULT_BUFFER_SIZE`.
+     On many systems, the buffer will typically be 4096 or 8192 bytes long.
+
+   * "Interactive" text files (files for which :meth:`isatty` returns True)
+     use line buffering.  Other text files use the policy described above
+     for binary files.
 
    *encoding* is the name of the encoding used to decode or encode the file.
    This should only be used in text mode.  The default encoding is platform
index 03c867638f4170602578f335acc7ae58a9f56920..70f2abaf57e2b8926aba8ad0d4e65f96c9133f02 100644 (file)
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -124,10 +124,20 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
     returned as strings, the bytes having been first decoded using a
     platform-dependent encoding or using the specified encoding if given.
 
-    buffering is an optional integer used to set the buffering policy. By
-    default full buffering is on. Pass 0 to switch buffering off (only
-    allowed in binary mode), 1 to set line buffering, and an integer > 1
-    for full buffering.
+    buffering is an optional integer used to set the buffering policy.
+    Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
+    line buffering (only usable in text mode), and an integer > 1 to indicate
+    the size of a fixed-size chunk buffer.  When no buffering argument is
+    given, the default buffering policy works as follows:
+
+    * Binary files are buffered in fixed-size chunks; the size of the buffer
+      is chosen using a heuristic trying to determine the underlying device's
+      "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
+      On many systems, the buffer will typically be 4096 or 8192 bytes long.
+
+    * "Interactive" text files (files for which isatty() returns True)
+      use line buffering.  Other text files use the policy described above
+      for binary files.
 
     encoding is the name of the encoding used to decode or encode the
     file. This should only be used in text mode. The default encoding is