Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
85b8d01c
Kaydet (Commit)
85b8d01c
authored
Mar 03, 2017
tarafından
David Ellis
Kaydeden (comit)
Berker Peksag
Mar 03, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-29623: Make PathLike objects work with ConfigParser.read() (#242)
üst
677ab995
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
8 deletions
+31
-8
configparser.rst
Doc/library/configparser.rst
+13
-7
configparser.py
Lib/configparser.py
+4
-1
test_configparser.py
Lib/test/test_configparser.py
+11
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/configparser.rst
Dosyayı görüntüle @
85b8d01c
...
...
@@ -988,13 +988,16 @@ ConfigParser Objects
.. method:: read(filenames, encoding=None)
Attempt to read and parse a list of filenames, returning a list of
filenames which were successfully parsed. If *filenames* is a string, it
is treated as a single filename. If a file named in *filenames* cannot
be opened, that file will be ignored. This is designed so that you can
specify a list of potential configuration file locations (for example,
the current directory, the user's home directory, and some system-wide
directory), and all existing configuration files in the list will be
read. If none of the named files exist, the :class:`ConfigParser`
filenames which were successfully parsed.
If *filenames* is a string or :term:`path-like object`, it is treated as
a single filename. If a file named in *filenames* cannot be opened, that
file will be ignored. This is designed so that you can specify a list of
potential configuration file locations (for example, the current
directory, the user's home directory, and some system-wide directory),
and all existing configuration files in the list will be read.
If none of the named files exist, the :class:`ConfigParser`
instance will contain an empty dataset. An application which requires
initial values to be loaded from a file should load the required file or
files using :meth:`read_file` before calling :meth:`read` for any
...
...
@@ -1011,6 +1014,9 @@ ConfigParser Objects
The *encoding* parameter. Previously, all files were read using the
default encoding for :func:`open`.
.. versionadded:: 3.6.1
The *filenames* parameter accepts a :term:`path-like object`.
.. method:: read_file(f, source=None)
...
...
Lib/configparser.py
Dosyayı görüntüle @
85b8d01c
...
...
@@ -143,6 +143,7 @@ from collections import OrderedDict as _default_dict, ChainMap as _ChainMap
import
functools
import
io
import
itertools
import
os
import
re
import
sys
import
warnings
...
...
@@ -687,7 +688,7 @@ class RawConfigParser(MutableMapping):
Return list of successfully read files.
"""
if
isinstance
(
filenames
,
str
):
if
isinstance
(
filenames
,
(
str
,
os
.
PathLike
)
):
filenames
=
[
filenames
]
read_ok
=
[]
for
filename
in
filenames
:
...
...
@@ -696,6 +697,8 @@ class RawConfigParser(MutableMapping):
self
.
_read
(
fp
,
filename
)
except
OSError
:
continue
if
isinstance
(
filename
,
os
.
PathLike
):
filename
=
os
.
fspath
(
filename
)
read_ok
.
append
(
filename
)
return
read_ok
...
...
Lib/test/test_configparser.py
Dosyayı görüntüle @
85b8d01c
...
...
@@ -2,6 +2,7 @@ import collections
import
configparser
import
io
import
os
import
pathlib
import
textwrap
import
unittest
import
warnings
...
...
@@ -720,6 +721,16 @@ boolean {0[0]} NO
parsed_files
=
cf
.
read
(
file1
)
self
.
assertEqual
(
parsed_files
,
[
file1
])
self
.
assertEqual
(
cf
.
get
(
"Foo Bar"
,
"foo"
),
"newbar"
)
# check when we pass only a Path object:
cf
=
self
.
newconfig
()
parsed_files
=
cf
.
read
(
pathlib
.
Path
(
file1
))
self
.
assertEqual
(
parsed_files
,
[
file1
])
self
.
assertEqual
(
cf
.
get
(
"Foo Bar"
,
"foo"
),
"newbar"
)
# check when we passed both a filename and a Path object:
cf
=
self
.
newconfig
()
parsed_files
=
cf
.
read
([
pathlib
.
Path
(
file1
),
file1
])
self
.
assertEqual
(
parsed_files
,
[
file1
,
file1
])
self
.
assertEqual
(
cf
.
get
(
"Foo Bar"
,
"foo"
),
"newbar"
)
# check when we pass only missing files:
cf
=
self
.
newconfig
()
parsed_files
=
cf
.
read
([
"nonexistent-file"
])
...
...
Misc/NEWS
Dosyayı görüntüle @
85b8d01c
...
...
@@ -259,6 +259,9 @@ Extension Modules
Library
-------
-
bpo
-
29623
:
Allow
use
of
path
-
like
object
as
a
single
argument
in
ConfigParser
.
read
().
Patch
by
David
Ellis
.
-
bpo
-
9303
:
Migrate
sqlite3
module
to
_v2
API
.
Patch
by
Aviv
Palivoda
.
-
bpo
-
28963
:
Fix
out
of
bound
iteration
in
asyncio
.
Future
.
remove_done_callback
...
...
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