#15543: glossary entry for and 'universal newlines', and links to it.
Patch by Chris Jerdonek.
diff --git a/Doc/library/bz2.rst b/Doc/library/bz2.rst
index 79058fb..6793c44 100644
--- a/Doc/library/bz2.rst
+++ b/Doc/library/bz2.rst
@@ -42,6 +42,9 @@
Handling of compressed files is offered by the :class:`BZ2File` class.
+.. index::
+ single: universal newlines; bz2.BZ2File class
+
.. class:: BZ2File(filename[, mode[, buffering[, compresslevel]]])
Open a bz2 file. Mode can be either ``'r'`` or ``'w'``, for reading (default)
@@ -50,7 +53,7 @@
unbuffered, and larger numbers specify the buffer size; the default is
``0``. If *compresslevel* is given, it must be a number between ``1`` and
``9``; the default is ``9``. Add a ``'U'`` to mode to open the file for input
- with universal newline support. Any line ending in the input file will be
+ in :term:`universal newlines` mode. Any line ending in the input file will be
seen as a ``'\n'`` in Python. Also, a file so opened gains the attribute
:attr:`newlines`; the value for this attribute is one of ``None`` (no newline
read yet), ``'\r'``, ``'\n'``, ``'\r\n'`` or a tuple containing all the
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 30ac614..4383cd4 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -859,13 +859,17 @@
binary mode, on systems that differentiate between binary and text files; on
systems that don't have this distinction, adding the ``'b'`` has no effect.
+ .. index::
+ single: universal newlines; open() built-in function
+
In addition to the standard :c:func:`fopen` values *mode* may be ``'U'`` or
- ``'rU'``. Python is usually built with universal newline support; supplying
+ ``'rU'``. Python is usually built with :term:`universal newlines` support;
+ supplying
``'U'`` opens the file as a text file, but lines may be terminated by any of the
following: the Unix end-of-line convention ``'\n'``, the Macintosh convention
``'\r'``, or the Windows convention ``'\r\n'``. All of these external
representations are seen as ``'\n'`` by the Python program. If Python is built
- without universal newline support a *mode* with ``'U'`` is the same as normal
+ without universal newlines support a *mode* with ``'U'`` is the same as normal
text mode. Note that file objects so opened also have an attribute called
:attr:`newlines` which has a value of ``None`` (if no newlines have yet been
seen), ``'\n'``, ``'\r'``, ``'\r\n'``, or a tuple containing all the newline
diff --git a/Doc/library/io.rst b/Doc/library/io.rst
index e1fa155..bb7c34f 100644
--- a/Doc/library/io.rst
+++ b/Doc/library/io.rst
@@ -92,7 +92,7 @@
``'b'`` binary mode
``'t'`` text mode (default)
``'+'`` open a disk file for updating (reading and writing)
- ``'U'`` universal newline mode (for backwards compatibility; should
+ ``'U'`` universal newlines mode (for backwards compatibility; should
not be used in new code)
========= ===============================================================
@@ -141,14 +141,18 @@
used. Any other error handling name that has been registered with
:func:`codecs.register_error` is also valid.
- *newline* controls how universal newlines works (it only applies to text
+ .. index::
+ single: universal newlines; open() (in module io)
+
+ *newline* controls how :term:`universal newlines` works (it only applies
+ to text
mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It
works as follows:
* On input, if *newline* is ``None``, universal newlines mode is enabled.
Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these
are translated into ``'\n'`` before being returned to the caller. If it is
- ``''``, universal newline mode is enabled, but line endings are returned to
+ ``''``, universal newlines mode is enabled, but line endings are returned to
the caller untranslated. If it has any of the other legal values, input
lines are only terminated by the given string, and the line ending is
returned to the caller untranslated.
@@ -754,13 +758,17 @@
sequences) can be used. Any other error handling name that has been
registered with :func:`codecs.register_error` is also valid.
+ .. index::
+ single: universal newlines; io.TextIOWrapper class
+
*newline* controls how line endings are handled. It can be ``None``,
``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows:
- * On input, if *newline* is ``None``, universal newlines mode is enabled.
+ * On input, if *newline* is ``None``, :term:`universal newlines` mode is
+ enabled.
Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these
are translated into ``'\n'`` before being returned to the caller. If it is
- ``''``, universal newline mode is enabled, but line endings are returned to
+ ``''``, universal newlines mode is enabled, but line endings are returned to
the caller untranslated. If it has any of the other legal values, input
lines are only terminated by the given string, and the line ending is
returned to the caller untranslated.
@@ -817,10 +825,13 @@
output.close()
+.. index::
+ single: universal newlines; io.IncrementalNewlineDecoder class
+
.. class:: IncrementalNewlineDecoder
- A helper codec that decodes newlines for universal newlines mode. It
- inherits :class:`codecs.IncrementalDecoder`.
+ A helper codec that decodes newlines for :term:`universal newlines` mode.
+ It inherits :class:`codecs.IncrementalDecoder`.
Advanced topics
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index abe3052..4dfed58 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -1181,10 +1181,13 @@
``' 1 2 3 '.split(None, 1)`` returns ``['1', '2 3 ']``.
+.. index::
+ single: universal newlines; str.splitlines method
+
.. method:: str.splitlines([keepends])
Return a list of the lines in the string, breaking at line boundaries.
- This method uses the universal newlines approach to splitting lines.
+ This method uses the :term:`universal newlines` approach to splitting lines.
Line breaks are not included in the resulting list unless *keepends* is
given and true.
@@ -2558,16 +2561,19 @@
form ``<...>``. This is a read-only attribute and may not be present on all
file-like objects.
+ .. index::
+ single: universal newlines; file.newlines attribute
+
.. attribute:: file.newlines
- If Python was built with universal newlines enabled (the default) this
+ If Python was built with :term:`universal newlines` enabled (the default) this
read-only attribute exists, and for files opened in universal newline read
mode it keeps track of the types of newlines encountered while reading the
file. The values it can take are ``'\r'``, ``'\n'``, ``'\r\n'``, ``None``
(unknown, no newlines read yet) or a tuple containing all the newline types
seen, to indicate that multiple newline conventions were encountered. For
- files not opened in universal newline read mode the value of this attribute
+ files not opened in universal newlines read mode the value of this attribute
will be ``None``.
diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst
index 1f73159..9f82323 100644
--- a/Doc/library/subprocess.rst
+++ b/Doc/library/subprocess.rst
@@ -220,9 +220,12 @@
the stderr data from the child process should be captured into the same file
handle as for stdout.
+ .. index::
+ single: universal newlines; subprocess module
+
When *stdout* or *stderr* are pipes and *universal_newlines* is
- :const:`True` then all line endings will be converted to ``'\n'`` as
- described for the universal newlines `'U'`` mode argument to :func:`open`.
+ ``True`` then all line endings will be converted to ``'\n'`` as described
+ for the :term:`universal newlines` `'U'`` mode argument to :func:`open`.
If *shell* is :const:`True`, the specified command will be executed through
the shell. This can be useful if you are using Python primarily for the
@@ -382,8 +385,9 @@
.. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly
- If *universal_newlines* is :const:`True`, the file objects stdout and stderr are
- opened as text files, but lines may be terminated by any of ``'\n'``, the Unix
+ If *universal_newlines* is ``True``, the file objects *stdout* and *stderr* are
+ opened as text files in :term:`universal newlines` mode. Lines may be
+ terminated by any of ``'\n'``, the Unix
end-of-line convention, ``'\r'``, the old Macintosh convention or ``'\r\n'``, the
Windows convention. All of these external representations are seen as ``'\n'``
by the Python program.
diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst
index 2d52f95..1cb3faf 100644
--- a/Doc/library/urllib.rst
+++ b/Doc/library/urllib.rst
@@ -34,7 +34,7 @@
Open a network object denoted by a URL for reading. If the URL does not have a
scheme identifier, or if it has :file:`file:` as its scheme identifier, this
- opens a local file (without universal newlines); otherwise it opens a socket to
+ opens a local file (without :term:`universal newlines`); otherwise it opens a socket to
a server somewhere on the network. If the connection cannot be made the
:exc:`IOError` exception is raised. If all went well, a file-like object is
returned. This supports the following methods: :meth:`read`, :meth:`readline`,
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
index 68e8dfa..77a1eec 100644
--- a/Doc/library/zipfile.rst
+++ b/Doc/library/zipfile.rst
@@ -163,13 +163,17 @@
Return a list of archive members by name.
+ .. index::
+ single: universal newlines; zipfile.ZipFile.open method
+
.. method:: ZipFile.open(name[, mode[, pwd]])
Extract a member from the archive as a file-like object (ZipExtFile). *name* is
the name of the file in the archive, or a :class:`ZipInfo` object. The *mode*
- parameter, if included, must be one of the following: ``'r'`` (the default),
- ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable universal newline
+ parameter, if included, must be one of the following: ``'r'`` (the default),
+ ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable
+ :term:`universal newline <universal newlines>`
support in the read-only object. *pwd* is the password used for encrypted files.
Calling :meth:`open` on a closed ZipFile will raise a :exc:`RuntimeError`.