[New-bugs-announce] [issue9452] configparser support for reading from strings and dictionaries
Łukasz Langa
report at bugs.python.org
Mon Aug 2 02:31:16 CEST 2010
New submission from Łukasz Langa <lukasz at langa.pl>:
Overview
--------
It's a fairly common need in configuration parsing to take configuration from a string or a Python data structure (most commonly, a dictionary). The attached patch introduces two new methods to RawConfigParser that serve this purpose: readstring and readdict. In the process, two behavioral bugs were detected and fixed.
Detailed information about the patch
------------------------------------
Source changes:
* added readstring and readdict methods
* fixed a bug in SafeConfigParser.set when setting a None value would raise an exception (the code tried to remove interpolation escapes from None)
* added a new exception DuplicateOptionError, raised when during parsing a single file, string or a dictionary the same option occurs twice. This catches mispellings and case-sensitivity errors (parsers are by default case-insensitive in regard to options).
* added checking for option duplicates described above in _read
Test changes:
* self.fromstring is using readstring now
* self.cf removed because it was bad design, now config parser instances are explicit everywhere
** changed definition of get_error and parse_error
* split test_basic into two parts: config parser building and the actual test
** introduced config parser built from the dictionary
* added a duplicate option checking case for string and dictionary based reading
Documentation changes:
* documented readstring and readdict
* documented DuplicateOptionError
* explicit remark about the case-insensitivity
* corrected remark about leading whitespace being removed from values (also trailing whitespace is, and for keys as well)
----------
components: Library (Lib)
messages: 112409
nosy: lukasz.langa
priority: normal
severity: normal
status: open
title: configparser support for reading from strings and dictionaries
type: feature request
versions: Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9452>
_______________________________________
More information about the New-bugs-announce
mailing list