mirror of
https://github.com/python/cpython.git
synced 2025-08-26 19:55:24 +00:00
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
This commit is contained in:
parent
f206d0e393
commit
8dcaa7396f
5 changed files with 136 additions and 16 deletions
|
@ -61,7 +61,7 @@ ConfigParser -- responsible for parsing a list of
|
|||
options(section)
|
||||
Return list of configuration options for the named section.
|
||||
|
||||
read(filenames)
|
||||
read(filenames, encoding=None)
|
||||
Read and parse the list of named configuration files, given by
|
||||
name. A single filename is also allowed. Non-existing files
|
||||
are ignored. Return list of successfully read files.
|
||||
|
@ -369,7 +369,7 @@ class RawConfigParser:
|
|||
del opts['__name__']
|
||||
return list(opts.keys())
|
||||
|
||||
def read(self, filenames):
|
||||
def read(self, filenames, encoding=None):
|
||||
"""Read and parse a filename or a list of filenames.
|
||||
|
||||
Files that cannot be opened are silently ignored; this is
|
||||
|
@ -386,7 +386,7 @@ class RawConfigParser:
|
|||
read_ok = []
|
||||
for filename in filenames:
|
||||
try:
|
||||
fp = open(filename)
|
||||
fp = open(filename, encoding=encoding)
|
||||
except IOError:
|
||||
continue
|
||||
self._read(fp, filename)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue