|
1 |
| -# Copyright (c) 2014, 2021, Oracle and/or its affiliates. |
| 1 | +# Copyright (c) 2014, 2022, Oracle and/or its affiliates. |
2 | 2 | #
|
3 | 3 | # This program is free software; you can redistribute it and/or modify
|
4 | 4 | # it under the terms of the GNU General Public License, version 2.0, as
|
@@ -224,23 +224,24 @@ def read(self, filenames): # pylint: disable=W0221
|
224 | 224 | for priority, filename in enumerate(filenames):
|
225 | 225 | try:
|
226 | 226 | out_file = io.StringIO()
|
227 |
| - for line in codecs.open(filename, encoding='utf-8'): |
228 |
| - line = line.strip() |
229 |
| - # Skip lines that begin with "!includedir" or "!include" |
230 |
| - if line.startswith('!include'): |
231 |
| - continue |
232 |
| - |
233 |
| - match_obj = self.OPTCRE.match(line) |
234 |
| - if not self.SECTCRE.match(line) and match_obj: |
235 |
| - optname, delimiter, optval = match_obj.group('option', |
236 |
| - 'vi', |
237 |
| - 'value') |
238 |
| - if optname and not optval and not delimiter: |
239 |
| - out_file.write(line + "=\n") |
| 227 | + with codecs.open(filename, encoding="utf-8") as in_file: |
| 228 | + for line in in_file: |
| 229 | + line = line.strip() |
| 230 | + # Skip lines that begin with "!includedir" or "!include" |
| 231 | + if line.startswith("!include"): |
| 232 | + continue |
| 233 | + |
| 234 | + match_obj = self.OPTCRE.match(line) |
| 235 | + if not self.SECTCRE.match(line) and match_obj: |
| 236 | + optname, delimiter, optval = match_obj.group( |
| 237 | + "option", "vi", "value" |
| 238 | + ) |
| 239 | + if optname and not optval and not delimiter: |
| 240 | + out_file.write(f"{line}=\n") |
| 241 | + else: |
| 242 | + out_file.write(f"{line}\n") |
240 | 243 | else:
|
241 |
| - out_file.write(line + '\n') |
242 |
| - else: |
243 |
| - out_file.write(line + '\n') |
| 244 | + out_file.write(f"{line}\n") |
244 | 245 | out_file.seek(0)
|
245 | 246 | except IOError:
|
246 | 247 | continue
|
|
0 commit comments