Hello Nicola,
It would be nice to get ConfigObj 4 finished. I guess a substantial part
of moving away from indentation is that the tests and docs will need
re-writing as well *sigh*. Are you going to do that as well ?
I had an email yesterday from a couple of folk using the current
version. I've let them know it's about to change !
Anyway - as for how to do the change, it should be quite easy. The
current regex that checks for a section marker looks *something* like
(simplified) :
(\s*)\[(.*)\]\s*(#.*)?
The first group is the indentation, the second is the section-name, the
third is the comment.
It can change to (simplified) :
\s*(\[)+(.*)(\])+\s*(#.*)?
First group is the number of open square brackets, second is the
section-name, third is the number of close brackets, fourth is the comment.
Just check that the length of the first group is the same as the length
of the second group and that gives you the depth of the section being
created. (Root section is depth 0). So instead of an indent attribute -
each section has a depth attribute. If the new section has a lower depth
- you just step up until you find the right parent (depth of one less
than the new one). Each section could even have a list of it's parents -
so you find the right parent by indexing the list.
Obviously a new section can have a *maximum depth* of one more than the
current section.
You'll need a new 'indent_type' option - which should map to an
attribute on the ConfigObj. This should default to ' ', and allowed
values are ' ', '\t', or None ('' ?). This only refers to how the
ConfigObj is written back out again. (So the write methods need to use it).
Those changes should actually be quite minor... changing the tests and
documentation is a bit more laborious as I put quite a bit of work into
these.
All the best.
Fuzzy
|