[Python-checkins] cpython (merge 3.2 -> default): Merged styling updates for #11670 from 3.2.

lukasz.langa python-checkins at python.org
Thu Apr 28 12:03:13 CEST 2011


http://hg.python.org/cpython/rev/339cd1d9b21a
changeset:   69664:339cd1d9b21a
parent:      69662:b9b8c8032080
parent:      69663:1bbda00bbe78
user:        Łukasz Langa <lukasz at langa.pl>
date:        Thu Apr 28 12:02:58 2011 +0200
summary:
  Merged styling updates for #11670 from 3.2.

files:
  Doc/library/configparser.rst  |  40 +++++++++-------------
  Lib/test/test_configparser.py |  14 ++++----
  2 files changed, 24 insertions(+), 30 deletions(-)


diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -975,7 +975,7 @@
    .. method:: read_file(f, source=None)
 
       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
       not given and *f* has a :attr:`name` attribute, that is used for
@@ -984,28 +984,6 @@
       .. versionadded:: 3.2
          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>')
 
       Parse configuration data from a string.
@@ -1142,6 +1120,22 @@
       .. deprecated:: 3.2
          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
 
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py
--- a/Lib/test/test_configparser.py
+++ b/Lib/test/test_configparser.py
@@ -1316,7 +1316,7 @@
 def readline_generator(f):
     """As advised in Doc/library/configparser.rst."""
     line = f.readline()
-    while line != '':
+    while line:
         yield line
         line = f.readline()
 
@@ -1327,8 +1327,8 @@
         parser = configparser.ConfigParser()
         with open(file_path) as f:
             parser.read_file(f)
-        self.assertTrue("Foo Bar" in parser)
-        self.assertTrue("foo" in parser["Foo Bar"])
+        self.assertIn("Foo Bar", parser)
+        self.assertIn("foo", parser["Foo Bar"])
         self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
 
     def test_iterable(self):
@@ -1337,8 +1337,8 @@
         foo=newbar""").strip().split('\n')
         parser = configparser.ConfigParser()
         parser.read_file(lines)
-        self.assertTrue("Foo Bar" in parser)
-        self.assertTrue("foo" in parser["Foo Bar"])
+        self.assertIn("Foo Bar", parser)
+        self.assertIn("foo", parser["Foo Bar"])
         self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
 
     def test_readline_generator(self):
@@ -1347,8 +1347,8 @@
         with self.assertRaises(TypeError):
             parser.read_file(FakeFile())
         parser.read_file(readline_generator(FakeFile()))
-        self.assertTrue("Foo Bar" in parser)
-        self.assertTrue("foo" in parser["Foo Bar"])
+        self.assertIn("Foo Bar", parser)
+        self.assertIn("foo", parser["Foo Bar"])
         self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
 
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list