Read and parse a filename or an iterable of filenames. Files that cannot be opened are silently ignored; this is designed so that you can specify an iterable of potential configuration file locations (e.g. current directory, user's home directory, systemwide director
(self, filenames, encoding=None)
| 733 | return list(opts.keys()) |
| 734 | |
| 735 | def read(self, filenames, encoding=None): |
| 736 | """Read and parse a filename or an iterable of filenames. |
| 737 | |
| 738 | Files that cannot be opened are silently ignored; this is |
| 739 | designed so that you can specify an iterable of potential |
| 740 | configuration file locations (e.g. current directory, user's |
| 741 | home directory, systemwide directory), and all existing |
| 742 | configuration files in the iterable will be read. A single |
| 743 | filename may also be given. |
| 744 | |
| 745 | Return list of successfully read files. |
| 746 | """ |
| 747 | if isinstance(filenames, (str, bytes, os.PathLike)): |
| 748 | filenames = [filenames] |
| 749 | encoding = io.text_encoding(encoding) |
| 750 | read_ok = [] |
| 751 | for filename in filenames: |
| 752 | try: |
| 753 | with open(filename, encoding=encoding) as fp: |
| 754 | self._read(fp, filename) |
| 755 | except OSError: |
| 756 | continue |
| 757 | if isinstance(filename, os.PathLike): |
| 758 | filename = os.fspath(filename) |
| 759 | read_ok.append(filename) |
| 760 | return read_ok |
| 761 | |
| 762 | def read_file(self, f, source=None): |
| 763 | """Like read() but the argument must be a file-like object. |