Skip to content

Commit fa71a90

Browse files
committed
Merged revisions 67326,67498,67531-67532,67538,67553-67554,67556-67557 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67326 | benjamin.peterson | 2008-11-22 02:59:15 +0100 (Sat, 22 Nov 2008) | 1 line backport r67325: make FileIO.mode always contain 'b' ........ r67498 | raymond.hettinger | 2008-12-03 16:42:10 +0100 (Wed, 03 Dec 2008) | 1 line Backport r67478 ........ r67531 | georg.brandl | 2008-12-04 19:54:05 +0100 (Thu, 04 Dec 2008) | 2 lines Add reference to enumerate() to indices example. ........ r67532 | georg.brandl | 2008-12-04 19:59:16 +0100 (Thu, 04 Dec 2008) | 2 lines Add another heapq example. ........ r67538 | georg.brandl | 2008-12-04 22:28:16 +0100 (Thu, 04 Dec 2008) | 2 lines Clarification to avoid confusing output with file descriptors. ........ r67553 | georg.brandl | 2008-12-05 08:49:49 +0100 (Fri, 05 Dec 2008) | 2 lines python#4408: document regex.groups. ........ r67554 | georg.brandl | 2008-12-05 08:52:26 +0100 (Fri, 05 Dec 2008) | 2 lines python#4409: fix asterisks looking like footnotes. ........ r67556 | georg.brandl | 2008-12-05 09:02:17 +0100 (Fri, 05 Dec 2008) | 2 lines python#4441: improve doc for os.open() flags. ........ r67557 | georg.brandl | 2008-12-05 09:06:57 +0100 (Fri, 05 Dec 2008) | 2 lines Add an index entry for "subclassing immutable types". ........
1 parent 5667280 commit fa71a90

12 files changed

Lines changed: 74 additions & 42 deletions

File tree

Doc/library/heapq.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ Example of use:
8888
>>> print data == ordered
8989
True
9090

91+
Using a heap to insert items at the correct place in a priority queue:
92+
93+
>>> heap = []
94+
>>> data = [(1, 'J'), (4, 'N'), (3, 'H'), (2, 'O')]
95+
>>> for item in data:
96+
... heappush(heap, item)
97+
...
98+
>>> while heap:
99+
... print heappop(heap)[1]
100+
J
101+
O
102+
H
103+
N
104+
105+
91106
The module also offers three general purpose functions based on heaps.
92107

93108

Doc/library/os.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,11 @@ by file descriptors.
681681
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its :meth:`write`
682682
method.
683683

684-
The following data items are available for use in constructing the *flags*
685-
parameter to the :func:`open` function. Some items will not be available on all
686-
platforms. For descriptions of their availability and use, consult
687-
:manpage:`open(2)`.
684+
The following constants are options for the *flags* parameter to the
685+
:func:`open` function. They can be combined using the bitwise OR operator
686+
``|``. Some of them are not available on all platforms. For descriptions of
687+
their availability and use, consult the :manpage:`open(2)` manual page or the
688+
respective documentation for your operating system.
688689

689690

690691
.. data:: O_RDONLY
@@ -695,8 +696,7 @@ platforms. For descriptions of their availability and use, consult
695696
O_EXCL
696697
O_TRUNC
697698

698-
Options for the *flag* argument to the :func:`open` function. These can be
699-
combined using the bitwise OR operator ``|``. Availability: Unix, Windows.
699+
These constants are available on Unix and Windows.
700700

701701

702702
.. data:: O_DSYNC
@@ -708,8 +708,7 @@ platforms. For descriptions of their availability and use, consult
708708
O_SHLOCK
709709
O_EXLOCK
710710

711-
More options for the *flag* argument to the :func:`open` function. Availability:
712-
Unix.
711+
These constants are only available on Unix.
713712

714713

715714
.. data:: O_BINARY
@@ -720,8 +719,7 @@ platforms. For descriptions of their availability and use, consult
720719
O_SEQUENTIAL
721720
O_TEXT
722721

723-
Options for the *flag* argument to the :func:`open` function. These can be
724-
combined using the bitwise OR operator ``|``. Availability: Windows.
722+
These constants are only available on Windows.
725723

726724

727725
.. data:: O_ASYNC
@@ -730,8 +728,8 @@ platforms. For descriptions of their availability and use, consult
730728
O_NOFOLLOW
731729
O_NOATIME
732730

733-
Options for the *flag* argument to the :func:`open` function. These are
734-
GNU extensions and not present if they are not defined by the C library.
731+
These constants are GNU extensions and not present if they are not defined by
732+
the C library.
735733

736734

737735
.. data:: SEEK_SET

Doc/library/re.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ attributes:
750750
were provided.
751751

752752

753+
.. attribute:: RegexObject.groups
754+
755+
The number of capturing groups in the pattern.
756+
757+
753758
.. attribute:: RegexObject.groupindex
754759

755760
A dictionary mapping any symbolic group names defined by ``(?P<id>)`` to group

Doc/library/subprocess.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Instances of the :class:`Popen` class have the following methods:
207207
*input* argument should be a string to be sent to the child process, or
208208
``None``, if no data should be sent to the child.
209209

210-
:meth:`communicate` returns a tuple ``(stdout, stderr)``.
210+
:meth:`communicate` returns a tuple ``(stdoutdata, stderrdata)``.
211211

212212
Note that if you want to send data to the process's stdin, you need to create
213213
the Popen object with ``stdin=PIPE``. Similarly, to get anything other than
@@ -358,8 +358,8 @@ A more realistic example would look like this::
358358
print >>sys.stderr, "Execution failed:", e
359359

360360

361-
Replacing os.spawn\*
362-
^^^^^^^^^^^^^^^^^^^^
361+
Replacing the os.spawn family
362+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
363363

364364
P_NOWAIT example::
365365

@@ -386,8 +386,8 @@ Environment example::
386386
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
387387

388388

389-
Replacing os.popen\*
390-
^^^^^^^^^^^^^^^^^^^^
389+
Replacing os.popen, os.popen2, os.popen3
390+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
391391

392392
::
393393

@@ -430,8 +430,8 @@ Replacing os.popen\*
430430
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
431431

432432

433-
Replacing popen2.\*
434-
^^^^^^^^^^^^^^^^^^^
433+
Replacing functions from the popen2 module
434+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
435435

436436
.. note::
437437

Doc/reference/datamodel.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,9 +1162,10 @@ of this is the :class:`NodeList` interface in the W3C's Document Object Model.)
11621162
Basic customization
11631163
-------------------
11641164

1165-
11661165
.. method:: object.__new__(cls[, ...])
11671166

1167+
.. index:: pair: subclassing; immutable types
1168+
11681169
Called to create a new instance of class *cls*. :meth:`__new__` is a static
11691170
method (special-cased so you need not declare it as such) that takes the class
11701171
of which an instance was requested as its first argument. The remaining

Doc/tutorial/controlflow.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ increment (even negative; sometimes this is called the 'step')::
104104
>>> range(-10, -100, -30)
105105
[-10, -40, -70]
106106

107-
To iterate over the indices of a sequence, combine :func:`range` and :func:`len`
108-
as follows::
107+
To iterate over the indices of a sequence, you can combine :func:`range` and
108+
:func:`len` as follows::
109109

110110
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
111111
>>> for i in range(len(a)):
@@ -117,6 +117,9 @@ as follows::
117117
3 little
118118
4 lamb
119119

120+
In most such cases, however, it is convenient to use the :func:`enumerate`
121+
function, see :ref:`tut-loopidioms`.
122+
120123

121124
.. _tut-break:
122125

Lib/test/list_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def test_reversed(self):
8484
self.assertRaises(StopIteration, r.next)
8585
self.assertEqual(list(reversed(self.type2test())),
8686
self.type2test())
87+
# Bug 3689: make sure list-reversed-iterator doesn't have __len__
88+
self.assertRaises(TypeError, len, reversed([1,2,3]))
8789

8890
def test_setitem(self):
8991
a = self.type2test([0, 1])

Lib/test/test_fileio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def testAttributes(self):
5050
# verify expected attributes exist
5151
f = self.f
5252

53-
self.assertEquals(f.mode, "w")
53+
self.assertEquals(f.mode, "wb")
5454
self.assertEquals(f.closed, False)
5555

5656
# verify the attributes are readonly
@@ -160,7 +160,7 @@ def testAbles(self):
160160

161161
def testModeStrings(self):
162162
# check invalid mode strings
163-
for mode in ("", "aU", "wU+", "rb", "rt"):
163+
for mode in ("", "aU", "wU+", "rw", "rt"):
164164
try:
165165
f = _fileio._FileIO(TESTFN, mode)
166166
except ValueError:

Lib/test/test_io.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,26 +1266,26 @@ def testImport__all__(self):
12661266

12671267
def test_attributes(self):
12681268
f = io.open(test_support.TESTFN, "wb", buffering=0)
1269-
self.assertEquals(f.mode, "w")
1269+
self.assertEquals(f.mode, "wb")
12701270
f.close()
12711271

12721272
f = io.open(test_support.TESTFN, "U")
12731273
self.assertEquals(f.name, test_support.TESTFN)
12741274
self.assertEquals(f.buffer.name, test_support.TESTFN)
12751275
self.assertEquals(f.buffer.raw.name, test_support.TESTFN)
12761276
self.assertEquals(f.mode, "U")
1277-
self.assertEquals(f.buffer.mode, "r")
1278-
self.assertEquals(f.buffer.raw.mode, "r")
1277+
self.assertEquals(f.buffer.mode, "rb")
1278+
self.assertEquals(f.buffer.raw.mode, "rb")
12791279
f.close()
12801280

12811281
f = io.open(test_support.TESTFN, "w+")
12821282
self.assertEquals(f.mode, "w+")
1283-
self.assertEquals(f.buffer.mode, "r+") # Does it really matter?
1284-
self.assertEquals(f.buffer.raw.mode, "r+")
1283+
self.assertEquals(f.buffer.mode, "rb+") # Does it really matter?
1284+
self.assertEquals(f.buffer.raw.mode, "rb+")
12851285

12861286
g = io.open(f.fileno(), "wb", closefd=False)
1287-
self.assertEquals(g.mode, "w")
1288-
self.assertEquals(g.raw.mode, "w")
1287+
self.assertEquals(g.mode, "wb")
1288+
self.assertEquals(g.raw.mode, "wb")
12891289
self.assertEquals(g.name, f.fileno())
12901290
self.assertEquals(g.raw.name, f.fileno())
12911291
f.close()

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ Core and Builtins
1717
kept open but the file object behaves like a closed file. The ``FileIO``
1818
object also got a new readonly attribute ``closefd``.
1919

20+
- Issue #3689: The list reversed iterator now supports __length_hint__
21+
instead of __len__. Behavior now matches other reversed iterators.
22+
2023
Library
2124
-------
2225

26+
- FileIO's mode attribute now always includes ``"b"``.
27+
2328

2429
What's New in Python 2.6.1
2530
==========================

0 commit comments

Comments
 (0)