mirror of https://github.com/python/cpython
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 #4408: document regex.groups. ........ r67554 | georg.brandl | 2008-12-05 08:52:26 +0100 (Fri, 05 Dec 2008) | 2 lines #4409: fix asterisks looking like footnotes. ........ r67556 | georg.brandl | 2008-12-05 09:02:17 +0100 (Fri, 05 Dec 2008) | 2 lines #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". ........
This commit is contained in:
parent
5667280a07
commit
fa71a90703
|
@ -88,6 +88,21 @@ Example of use:
|
||||||
>>> print data == ordered
|
>>> print data == ordered
|
||||||
True
|
True
|
||||||
|
|
||||||
|
Using a heap to insert items at the correct place in a priority queue:
|
||||||
|
|
||||||
|
>>> heap = []
|
||||||
|
>>> data = [(1, 'J'), (4, 'N'), (3, 'H'), (2, 'O')]
|
||||||
|
>>> for item in data:
|
||||||
|
... heappush(heap, item)
|
||||||
|
...
|
||||||
|
>>> while heap:
|
||||||
|
... print heappop(heap)[1]
|
||||||
|
J
|
||||||
|
O
|
||||||
|
H
|
||||||
|
N
|
||||||
|
|
||||||
|
|
||||||
The module also offers three general purpose functions based on heaps.
|
The module also offers three general purpose functions based on heaps.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -681,10 +681,11 @@ by file descriptors.
|
||||||
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its :meth:`write`
|
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its :meth:`write`
|
||||||
method.
|
method.
|
||||||
|
|
||||||
The following data items are available for use in constructing the *flags*
|
The following constants are options for the *flags* parameter to the
|
||||||
parameter to the :func:`open` function. Some items will not be available on all
|
:func:`open` function. They can be combined using the bitwise OR operator
|
||||||
platforms. For descriptions of their availability and use, consult
|
``|``. Some of them are not available on all platforms. For descriptions of
|
||||||
:manpage:`open(2)`.
|
their availability and use, consult the :manpage:`open(2)` manual page or the
|
||||||
|
respective documentation for your operating system.
|
||||||
|
|
||||||
|
|
||||||
.. data:: O_RDONLY
|
.. data:: O_RDONLY
|
||||||
|
@ -695,8 +696,7 @@ platforms. For descriptions of their availability and use, consult
|
||||||
O_EXCL
|
O_EXCL
|
||||||
O_TRUNC
|
O_TRUNC
|
||||||
|
|
||||||
Options for the *flag* argument to the :func:`open` function. These can be
|
These constants are available on Unix and Windows.
|
||||||
combined using the bitwise OR operator ``|``. Availability: Unix, Windows.
|
|
||||||
|
|
||||||
|
|
||||||
.. data:: O_DSYNC
|
.. data:: O_DSYNC
|
||||||
|
@ -708,8 +708,7 @@ platforms. For descriptions of their availability and use, consult
|
||||||
O_SHLOCK
|
O_SHLOCK
|
||||||
O_EXLOCK
|
O_EXLOCK
|
||||||
|
|
||||||
More options for the *flag* argument to the :func:`open` function. Availability:
|
These constants are only available on Unix.
|
||||||
Unix.
|
|
||||||
|
|
||||||
|
|
||||||
.. data:: O_BINARY
|
.. data:: O_BINARY
|
||||||
|
@ -720,8 +719,7 @@ platforms. For descriptions of their availability and use, consult
|
||||||
O_SEQUENTIAL
|
O_SEQUENTIAL
|
||||||
O_TEXT
|
O_TEXT
|
||||||
|
|
||||||
Options for the *flag* argument to the :func:`open` function. These can be
|
These constants are only available on Windows.
|
||||||
combined using the bitwise OR operator ``|``. Availability: Windows.
|
|
||||||
|
|
||||||
|
|
||||||
.. data:: O_ASYNC
|
.. data:: O_ASYNC
|
||||||
|
@ -730,8 +728,8 @@ platforms. For descriptions of their availability and use, consult
|
||||||
O_NOFOLLOW
|
O_NOFOLLOW
|
||||||
O_NOATIME
|
O_NOATIME
|
||||||
|
|
||||||
Options for the *flag* argument to the :func:`open` function. These are
|
These constants are GNU extensions and not present if they are not defined by
|
||||||
GNU extensions and not present if they are not defined by the C library.
|
the C library.
|
||||||
|
|
||||||
|
|
||||||
.. data:: SEEK_SET
|
.. data:: SEEK_SET
|
||||||
|
|
|
@ -750,6 +750,11 @@ attributes:
|
||||||
were provided.
|
were provided.
|
||||||
|
|
||||||
|
|
||||||
|
.. attribute:: RegexObject.groups
|
||||||
|
|
||||||
|
The number of capturing groups in the pattern.
|
||||||
|
|
||||||
|
|
||||||
.. attribute:: RegexObject.groupindex
|
.. attribute:: RegexObject.groupindex
|
||||||
|
|
||||||
A dictionary mapping any symbolic group names defined by ``(?P<id>)`` to group
|
A dictionary mapping any symbolic group names defined by ``(?P<id>)`` to group
|
||||||
|
|
|
@ -207,7 +207,7 @@ Instances of the :class:`Popen` class have the following methods:
|
||||||
*input* argument should be a string to be sent to the child process, or
|
*input* argument should be a string to be sent to the child process, or
|
||||||
``None``, if no data should be sent to the child.
|
``None``, if no data should be sent to the child.
|
||||||
|
|
||||||
:meth:`communicate` returns a tuple ``(stdout, stderr)``.
|
:meth:`communicate` returns a tuple ``(stdoutdata, stderrdata)``.
|
||||||
|
|
||||||
Note that if you want to send data to the process's stdin, you need to create
|
Note that if you want to send data to the process's stdin, you need to create
|
||||||
the Popen object with ``stdin=PIPE``. Similarly, to get anything other than
|
the Popen object with ``stdin=PIPE``. Similarly, to get anything other than
|
||||||
|
@ -358,8 +358,8 @@ A more realistic example would look like this::
|
||||||
print >>sys.stderr, "Execution failed:", e
|
print >>sys.stderr, "Execution failed:", e
|
||||||
|
|
||||||
|
|
||||||
Replacing os.spawn\*
|
Replacing the os.spawn family
|
||||||
^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
P_NOWAIT example::
|
P_NOWAIT example::
|
||||||
|
|
||||||
|
@ -386,8 +386,8 @@ Environment example::
|
||||||
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
|
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
|
||||||
|
|
||||||
|
|
||||||
Replacing os.popen\*
|
Replacing os.popen, os.popen2, os.popen3
|
||||||
^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
@ -430,8 +430,8 @@ Replacing os.popen\*
|
||||||
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
|
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
|
||||||
|
|
||||||
|
|
||||||
Replacing popen2.\*
|
Replacing functions from the popen2 module
|
||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
|
@ -1162,9 +1162,10 @@ of this is the :class:`NodeList` interface in the W3C's Document Object Model.)
|
||||||
Basic customization
|
Basic customization
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|
||||||
.. method:: object.__new__(cls[, ...])
|
.. method:: object.__new__(cls[, ...])
|
||||||
|
|
||||||
|
.. index:: pair: subclassing; immutable types
|
||||||
|
|
||||||
Called to create a new instance of class *cls*. :meth:`__new__` is a static
|
Called to create a new instance of class *cls*. :meth:`__new__` is a static
|
||||||
method (special-cased so you need not declare it as such) that takes the class
|
method (special-cased so you need not declare it as such) that takes the class
|
||||||
of which an instance was requested as its first argument. The remaining
|
of which an instance was requested as its first argument. The remaining
|
||||||
|
|
|
@ -104,8 +104,8 @@ increment (even negative; sometimes this is called the 'step')::
|
||||||
>>> range(-10, -100, -30)
|
>>> range(-10, -100, -30)
|
||||||
[-10, -40, -70]
|
[-10, -40, -70]
|
||||||
|
|
||||||
To iterate over the indices of a sequence, combine :func:`range` and :func:`len`
|
To iterate over the indices of a sequence, you can combine :func:`range` and
|
||||||
as follows::
|
:func:`len` as follows::
|
||||||
|
|
||||||
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
|
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
|
||||||
>>> for i in range(len(a)):
|
>>> for i in range(len(a)):
|
||||||
|
@ -117,6 +117,9 @@ as follows::
|
||||||
3 little
|
3 little
|
||||||
4 lamb
|
4 lamb
|
||||||
|
|
||||||
|
In most such cases, however, it is convenient to use the :func:`enumerate`
|
||||||
|
function, see :ref:`tut-loopidioms`.
|
||||||
|
|
||||||
|
|
||||||
.. _tut-break:
|
.. _tut-break:
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,8 @@ class CommonTest(seq_tests.CommonTest):
|
||||||
self.assertRaises(StopIteration, r.next)
|
self.assertRaises(StopIteration, r.next)
|
||||||
self.assertEqual(list(reversed(self.type2test())),
|
self.assertEqual(list(reversed(self.type2test())),
|
||||||
self.type2test())
|
self.type2test())
|
||||||
|
# Bug 3689: make sure list-reversed-iterator doesn't have __len__
|
||||||
|
self.assertRaises(TypeError, len, reversed([1,2,3]))
|
||||||
|
|
||||||
def test_setitem(self):
|
def test_setitem(self):
|
||||||
a = self.type2test([0, 1])
|
a = self.type2test([0, 1])
|
||||||
|
|
|
@ -50,7 +50,7 @@ class AutoFileTests(unittest.TestCase):
|
||||||
# verify expected attributes exist
|
# verify expected attributes exist
|
||||||
f = self.f
|
f = self.f
|
||||||
|
|
||||||
self.assertEquals(f.mode, "w")
|
self.assertEquals(f.mode, "wb")
|
||||||
self.assertEquals(f.closed, False)
|
self.assertEquals(f.closed, False)
|
||||||
|
|
||||||
# verify the attributes are readonly
|
# verify the attributes are readonly
|
||||||
|
@ -160,7 +160,7 @@ class OtherFileTests(unittest.TestCase):
|
||||||
|
|
||||||
def testModeStrings(self):
|
def testModeStrings(self):
|
||||||
# check invalid mode strings
|
# check invalid mode strings
|
||||||
for mode in ("", "aU", "wU+", "rb", "rt"):
|
for mode in ("", "aU", "wU+", "rw", "rt"):
|
||||||
try:
|
try:
|
||||||
f = _fileio._FileIO(TESTFN, mode)
|
f = _fileio._FileIO(TESTFN, mode)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -1266,7 +1266,7 @@ class MiscIOTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_attributes(self):
|
def test_attributes(self):
|
||||||
f = io.open(test_support.TESTFN, "wb", buffering=0)
|
f = io.open(test_support.TESTFN, "wb", buffering=0)
|
||||||
self.assertEquals(f.mode, "w")
|
self.assertEquals(f.mode, "wb")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
f = io.open(test_support.TESTFN, "U")
|
f = io.open(test_support.TESTFN, "U")
|
||||||
|
@ -1274,18 +1274,18 @@ class MiscIOTest(unittest.TestCase):
|
||||||
self.assertEquals(f.buffer.name, test_support.TESTFN)
|
self.assertEquals(f.buffer.name, test_support.TESTFN)
|
||||||
self.assertEquals(f.buffer.raw.name, test_support.TESTFN)
|
self.assertEquals(f.buffer.raw.name, test_support.TESTFN)
|
||||||
self.assertEquals(f.mode, "U")
|
self.assertEquals(f.mode, "U")
|
||||||
self.assertEquals(f.buffer.mode, "r")
|
self.assertEquals(f.buffer.mode, "rb")
|
||||||
self.assertEquals(f.buffer.raw.mode, "r")
|
self.assertEquals(f.buffer.raw.mode, "rb")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
f = io.open(test_support.TESTFN, "w+")
|
f = io.open(test_support.TESTFN, "w+")
|
||||||
self.assertEquals(f.mode, "w+")
|
self.assertEquals(f.mode, "w+")
|
||||||
self.assertEquals(f.buffer.mode, "r+") # Does it really matter?
|
self.assertEquals(f.buffer.mode, "rb+") # Does it really matter?
|
||||||
self.assertEquals(f.buffer.raw.mode, "r+")
|
self.assertEquals(f.buffer.raw.mode, "rb+")
|
||||||
|
|
||||||
g = io.open(f.fileno(), "wb", closefd=False)
|
g = io.open(f.fileno(), "wb", closefd=False)
|
||||||
self.assertEquals(g.mode, "w")
|
self.assertEquals(g.mode, "wb")
|
||||||
self.assertEquals(g.raw.mode, "w")
|
self.assertEquals(g.raw.mode, "wb")
|
||||||
self.assertEquals(g.name, f.fileno())
|
self.assertEquals(g.name, f.fileno())
|
||||||
self.assertEquals(g.raw.name, f.fileno())
|
self.assertEquals(g.raw.name, f.fileno())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
@ -17,9 +17,14 @@ Core and Builtins
|
||||||
kept open but the file object behaves like a closed file. The ``FileIO``
|
kept open but the file object behaves like a closed file. The ``FileIO``
|
||||||
object also got a new readonly attribute ``closefd``.
|
object also got a new readonly attribute ``closefd``.
|
||||||
|
|
||||||
|
- Issue #3689: The list reversed iterator now supports __length_hint__
|
||||||
|
instead of __len__. Behavior now matches other reversed iterators.
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- FileIO's mode attribute now always includes ``"b"``.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 2.6.1
|
What's New in Python 2.6.1
|
||||||
==========================
|
==========================
|
||||||
|
|
|
@ -208,6 +208,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
flags |= O_CREAT;
|
flags |= O_CREAT;
|
||||||
append = 1;
|
append = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'b':
|
||||||
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
if (plus)
|
if (plus)
|
||||||
goto bad_mode;
|
goto bad_mode;
|
||||||
|
@ -682,12 +684,12 @@ mode_string(PyFileIOObject *self)
|
||||||
{
|
{
|
||||||
if (self->readable) {
|
if (self->readable) {
|
||||||
if (self->writable)
|
if (self->writable)
|
||||||
return "r+";
|
return "rb+";
|
||||||
else
|
else
|
||||||
return "r";
|
return "rb";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return "w";
|
return "wb";
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -2911,11 +2911,11 @@ static PyObject *list_reversed(PyListObject *, PyObject *);
|
||||||
static void listreviter_dealloc(listreviterobject *);
|
static void listreviter_dealloc(listreviterobject *);
|
||||||
static int listreviter_traverse(listreviterobject *, visitproc, void *);
|
static int listreviter_traverse(listreviterobject *, visitproc, void *);
|
||||||
static PyObject *listreviter_next(listreviterobject *);
|
static PyObject *listreviter_next(listreviterobject *);
|
||||||
static Py_ssize_t listreviter_len(listreviterobject *);
|
static PyObject *listreviter_len(listreviterobject *);
|
||||||
|
|
||||||
static PySequenceMethods listreviter_as_sequence = {
|
static PyMethodDef listreviter_methods[] = {
|
||||||
(lenfunc)listreviter_len, /* sq_length */
|
{"__length_hint__", (PyCFunction)listreviter_len, METH_NOARGS, length_hint_doc},
|
||||||
0, /* sq_concat */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PyListRevIter_Type = {
|
PyTypeObject PyListRevIter_Type = {
|
||||||
|
@ -2931,7 +2931,7 @@ PyTypeObject PyListRevIter_Type = {
|
||||||
0, /* tp_compare */
|
0, /* tp_compare */
|
||||||
0, /* tp_repr */
|
0, /* tp_repr */
|
||||||
0, /* tp_as_number */
|
0, /* tp_as_number */
|
||||||
&listreviter_as_sequence, /* tp_as_sequence */
|
0, /* tp_as_sequence */
|
||||||
0, /* tp_as_mapping */
|
0, /* tp_as_mapping */
|
||||||
0, /* tp_hash */
|
0, /* tp_hash */
|
||||||
0, /* tp_call */
|
0, /* tp_call */
|
||||||
|
@ -2947,6 +2947,7 @@ PyTypeObject PyListRevIter_Type = {
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
PyObject_SelfIter, /* tp_iter */
|
PyObject_SelfIter, /* tp_iter */
|
||||||
(iternextfunc)listreviter_next, /* tp_iternext */
|
(iternextfunc)listreviter_next, /* tp_iternext */
|
||||||
|
listreviter_methods, /* tp_methods */
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3002,11 +3003,11 @@ listreviter_next(listreviterobject *it)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Py_ssize_t
|
static PyObject *
|
||||||
listreviter_len(listreviterobject *it)
|
listreviter_len(listreviterobject *it)
|
||||||
{
|
{
|
||||||
Py_ssize_t len = it->it_index + 1;
|
Py_ssize_t len = it->it_index + 1;
|
||||||
if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len)
|
if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len)
|
||||||
return 0;
|
len = 0;
|
||||||
return len;
|
return PyLong_FromSsize_t(len);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue