mirror of https://github.com/python/cpython.git
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
http://mail.python.org/pipermail/python-checkins/2011-April/104688.html Thanks!
This commit is contained in:
parent
c20566cdf8
commit
ba702daef9
|
@ -975,7 +975,7 @@ ConfigParser Objects
|
||||||
.. method:: read_file(f, source=None)
|
.. method:: read_file(f, source=None)
|
||||||
|
|
||||||
Read and parse configuration data from *f* which must be an iterable
|
Read and parse configuration data from *f* which must be an iterable
|
||||||
yielding Unicode strings (for example any file object).
|
yielding Unicode strings (for example files opened in text mode).
|
||||||
|
|
||||||
Optional argument *source* specifies the name of the file being read. If
|
Optional argument *source* specifies the name of the file being read. If
|
||||||
not given and *f* has a :attr:`name` attribute, that is used for
|
not given and *f* has a :attr:`name` attribute, that is used for
|
||||||
|
@ -984,28 +984,6 @@ ConfigParser Objects
|
||||||
.. versionadded:: 3.2
|
.. versionadded:: 3.2
|
||||||
Replaces :meth:`readfp`.
|
Replaces :meth:`readfp`.
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
Prior to Python 3.2, :meth:`readfp` consumed lines from the file-like
|
|
||||||
argument by calling its :meth:`~file.readline` method. For existing code
|
|
||||||
calling :meth:`readfp` with arguments which don't support iteration,
|
|
||||||
the following generator may be used as a wrapper around the file-like
|
|
||||||
object::
|
|
||||||
|
|
||||||
def readline_generator(f):
|
|
||||||
line = f.readline()
|
|
||||||
while line != '':
|
|
||||||
yield line
|
|
||||||
line = f.readline()
|
|
||||||
|
|
||||||
Before::
|
|
||||||
|
|
||||||
parser.readfp(f)
|
|
||||||
|
|
||||||
After::
|
|
||||||
|
|
||||||
parser.read_file(readline_generator(f))
|
|
||||||
|
|
||||||
.. method:: read_string(string, source='<string>')
|
.. method:: read_string(string, source='<string>')
|
||||||
|
|
||||||
Parse configuration data from a string.
|
Parse configuration data from a string.
|
||||||
|
@ -1142,6 +1120,22 @@ ConfigParser Objects
|
||||||
.. deprecated:: 3.2
|
.. deprecated:: 3.2
|
||||||
Use :meth:`read_file` instead.
|
Use :meth:`read_file` instead.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.2
|
||||||
|
:meth:`readfp` now iterates on *f* instead of calling ``f.readline()``.
|
||||||
|
|
||||||
|
For existing code calling :meth:`readfp` with arguments which don't
|
||||||
|
support iteration, the following generator may be used as a wrapper
|
||||||
|
around the file-like object::
|
||||||
|
|
||||||
|
def readline_generator(f):
|
||||||
|
line = f.readline()
|
||||||
|
while line:
|
||||||
|
yield line
|
||||||
|
line = f.readline()
|
||||||
|
|
||||||
|
Instead of ``parser.readfp(f)`` use
|
||||||
|
``parser.read_file(readline_generator(f))``.
|
||||||
|
|
||||||
|
|
||||||
.. data:: MAX_INTERPOLATION_DEPTH
|
.. data:: MAX_INTERPOLATION_DEPTH
|
||||||
|
|
||||||
|
|
|
@ -1316,7 +1316,7 @@ def readline(self):
|
||||||
def readline_generator(f):
|
def readline_generator(f):
|
||||||
"""As advised in Doc/library/configparser.rst."""
|
"""As advised in Doc/library/configparser.rst."""
|
||||||
line = f.readline()
|
line = f.readline()
|
||||||
while line != '':
|
while line:
|
||||||
yield line
|
yield line
|
||||||
line = f.readline()
|
line = f.readline()
|
||||||
|
|
||||||
|
@ -1327,8 +1327,8 @@ def test_file(self):
|
||||||
parser = configparser.ConfigParser()
|
parser = configparser.ConfigParser()
|
||||||
with open(file_path) as f:
|
with open(file_path) as f:
|
||||||
parser.read_file(f)
|
parser.read_file(f)
|
||||||
self.assertTrue("Foo Bar" in parser)
|
self.assertIn("Foo Bar", parser)
|
||||||
self.assertTrue("foo" in parser["Foo Bar"])
|
self.assertIn("foo", parser["Foo Bar"])
|
||||||
self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
|
self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
|
||||||
|
|
||||||
def test_iterable(self):
|
def test_iterable(self):
|
||||||
|
@ -1337,8 +1337,8 @@ def test_iterable(self):
|
||||||
foo=newbar""").strip().split('\n')
|
foo=newbar""").strip().split('\n')
|
||||||
parser = configparser.ConfigParser()
|
parser = configparser.ConfigParser()
|
||||||
parser.read_file(lines)
|
parser.read_file(lines)
|
||||||
self.assertTrue("Foo Bar" in parser)
|
self.assertIn("Foo Bar", parser)
|
||||||
self.assertTrue("foo" in parser["Foo Bar"])
|
self.assertIn("foo", parser["Foo Bar"])
|
||||||
self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
|
self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
|
||||||
|
|
||||||
def test_readline_generator(self):
|
def test_readline_generator(self):
|
||||||
|
@ -1347,8 +1347,8 @@ def test_readline_generator(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
parser.read_file(FakeFile())
|
parser.read_file(FakeFile())
|
||||||
parser.read_file(readline_generator(FakeFile()))
|
parser.read_file(readline_generator(FakeFile()))
|
||||||
self.assertTrue("Foo Bar" in parser)
|
self.assertIn("Foo Bar", parser)
|
||||||
self.assertTrue("foo" in parser["Foo Bar"])
|
self.assertIn("foo", parser["Foo Bar"])
|
||||||
self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
|
self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue