|
70 | 70 | insensitively defined as 0, false, no, off for 0, and 1, true, |
71 | 71 | yes, on for 1). Returns 0 or 1. |
72 | 72 |
|
| 73 | + items(section, raw=0, vars=None) |
| 74 | + return a list of tuples with (name, value) for each option |
| 75 | + in the section. |
| 76 | +
|
73 | 77 | remove_section(section) |
74 | 78 | remove the given file section and all its options |
75 | 79 |
|
@@ -278,6 +282,35 @@ def get(self, section, option, raw=0, vars=None): |
278 | 282 | return value |
279 | 283 | return self._interpolate(section, option, value, d) |
280 | 284 |
|
| 285 | + def items(self, section, raw=0, vars=None): |
| 286 | + """Return a list of tuples with (name, value) for each option |
| 287 | + in the section. |
| 288 | +
|
| 289 | + All % interpolations are expanded in the return values, based on the |
| 290 | + defaults passed into the constructor, unless the optional argument |
| 291 | + `raw' is true. Additional substitutions may be provided using the |
| 292 | + `vars' argument, which must be a dictionary whose contents overrides |
| 293 | + any pre-existing defaults. |
| 294 | +
|
| 295 | + The section DEFAULT is special. |
| 296 | + """ |
| 297 | + d = self.__defaults.copy() |
| 298 | + try: |
| 299 | + d.update(self.__sections[section]) |
| 300 | + except KeyError: |
| 301 | + if section != DEFAULTSECT: |
| 302 | + raise NoSectionError(section) |
| 303 | + # Update with the entry specific variables |
| 304 | + if vars: |
| 305 | + d.update(vars) |
| 306 | + if raw: |
| 307 | + for option in self.options(section): |
| 308 | + yield (option, d[option]) |
| 309 | + else: |
| 310 | + for option in self.options(section): |
| 311 | + yield (option, |
| 312 | + self._interpolate(section, option, d[option], d)) |
| 313 | + |
281 | 314 | def _interpolate(self, section, option, rawval, vars): |
282 | 315 | # do the string interpolation |
283 | 316 | value = rawval |
|
0 commit comments