[Patches] [ python-Patches-1410680 ] Add 'surgical editing' to ConfigParser
SourceForge.net
noreply at sourceforge.net
Thu Jun 8 09:15:59 CEST 2006
Patches item #1410680, was opened at 2006-01-20 06:12
Message generated for change (Comment added) made by geekmug
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1410680&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Tony Meyer (anadelonbrin)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add 'surgical editing' to ConfigParser
Initial Comment:
See also:
[ 1399309 ] ConfigParser to save with order
[ 1371075 ] ConfigParser to accept a custom dict to
allow ordering
The attached patch adds a new method, update_file, to
RawConfigParser. This method is similar to the
existing write method, but preserves blank lines,
comments, and ordering, as requested many times on
python-dev and python-list. These are the three
requirements that Guido specified in January 2005.
IMO the attached patch is better than 1399309 because
it includes all the functionality (passing a pointer to
an empty file results in a sorted write() output), but
is completely backwards compatible as write() is
unchanged. The addition of preserving comments is
also essential for many applications.
IMO the attached patch is better than 1371075 because
the latter really requires a custom class (e.g. the
third party one suggested) in order to be useful. It
also doesn't address the issue of preserving comments.
The attached patch is essentially a tidied up version
of the one included with SpamBayes (in the
OptionClass.py module), which is used extensively
within SpamBayes (and has been for several years).
Also attached are additional unittests for the new
method, and a documentation patch.
Please let me know if there are recommended changes.
This patch does not address any of the additional
ConfigParser improvements that have been suggested at
various times.
----------------------------------------------------------------------
Comment By: Scott Dial (geekmug)
Date: 2006-06-08 03:15
Message:
Logged In: YES
user_id=383208
Before I lose track of the updated patches I made.. They can
be found here:
http://scottdial.com/python-dev/ConfigParser.diff
http://scottdial.com/python-dev/test_cfgparser.diff
The notes I emailed Tony were:
* I have modified the OPTCRE matching to not just throw away
the whitespace after a [=:]. Second, I have modified the
opt.rstrip(), again so that the whitespace isn't just thrown
away. A new variable padded_vi then appears which is a
formatting-preserved version of vi.
* I have removed at least one erroneous write('\n'), and
changed the pattern for adding newlines to missing sections,
such that the newlines are added /before/ the section
heading (and only if there are lines appearing before).
These together solve the growing blank lines phenomena.
* I have modified the add_missing section to deal with
DEFAULTSECT appropriately. Which solves the
appearing/disappearing act that I had mentioned.
* I have updated the test's to match the new expected output.
---
And in reponse to Jim's comment, such a feature is not in
the scope of the patch. The patch is to explicitly leave
things the way they are, so any sort of sorting would make
no sense.
----------------------------------------------------------------------
Comment By: Jim Jewett (jimjjewett)
Date: 2006-01-20 10:11
Message:
Logged In: YES
user_id=764593
Wanting to keep the whole thing (except defaultsection) in
sorted order will probably be a common use case.
It sounds like you can do this by "updating" to an empty
file, but it isn't the obvious solution. Could you either
add an option to sort the whole thing (so inserts may not be
at the end) or an explicit mention in the docstring of how
to get this?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1410680&group_id=5470
More information about the Patches
mailing list