Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e812bf7b
Commit
e812bf7b
authored
Apr 28, 2011
by
Łukasz Langa
Browse files
Options
Browse Files
Download
Plain Diff
Merged styling updates for #11670 from 3.2.
parents
2ea72709
ba702dae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
30 deletions
+24
-30
Doc/library/configparser.rst
Doc/library/configparser.rst
+17
-23
Lib/test/test_configparser.py
Lib/test/test_configparser.py
+7
-7
No files found.
Doc/library/configparser.rst
View file @
e812bf7b
...
...
@@ -975,7 +975,7 @@ ConfigParser Objects
.. 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 @@ ConfigParser Objects
.. 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 @@ ConfigParser Objects
.. 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
...
...
Lib/test/test_configparser.py
View file @
e812bf7b
...
...
@@ -1316,7 +1316,7 @@ class FakeFile:
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 @@ class ReadFileTestCase(unittest.TestCase):
parser
=
configparser
.
ConfigParser
()
with
open
(
file_path
)
as
f
:
parser
.
read_file
(
f
)
self
.
assert
True
(
"Foo Bar"
in
parser
)
self
.
assert
True
(
"foo"
in
parser
[
"Foo Bar"
])
self
.
assert
In
(
"Foo Bar"
,
parser
)
self
.
assert
In
(
"foo"
,
parser
[
"Foo Bar"
])
self
.
assertEqual
(
parser
[
"Foo Bar"
][
"foo"
],
"newbar"
)
def
test_iterable
(
self
):
...
...
@@ -1337,8 +1337,8 @@ class ReadFileTestCase(unittest.TestCase):
foo=newbar"""
).
strip
().
split
(
'
\
n
'
)
parser
=
configparser
.
ConfigParser
()
parser
.
read_file
(
lines
)
self
.
assert
True
(
"Foo Bar"
in
parser
)
self
.
assert
True
(
"foo"
in
parser
[
"Foo Bar"
])
self
.
assert
In
(
"Foo Bar"
,
parser
)
self
.
assert
In
(
"foo"
,
parser
[
"Foo Bar"
])
self
.
assertEqual
(
parser
[
"Foo Bar"
][
"foo"
],
"newbar"
)
def
test_readline_generator
(
self
):
...
...
@@ -1347,8 +1347,8 @@ class ReadFileTestCase(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
parser
.
read_file
(
FakeFile
())
parser
.
read_file
(
readline_generator
(
FakeFile
()))
self
.
assert
True
(
"Foo Bar"
in
parser
)
self
.
assert
True
(
"foo"
in
parser
[
"Foo Bar"
])
self
.
assert
In
(
"Foo Bar"
,
parser
)
self
.
assert
In
(
"foo"
,
parser
[
"Foo Bar"
])
self
.
assertEqual
(
parser
[
"Foo Bar"
][
"foo"
],
"newbar"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment