Re: [Rest2web-develop] Changed all references to value "tests" into value "checks"...
Brought to you by:
mjfoord
From: Michael F. <mi...@pc...> - 2005-07-21 10:33:42
|
Nicola Larosa wrote: >>It is possible to create new ConfigObjs programatically. Either manually >>- or by passing in a dictionary to create the ConfigObj. In both cases >>it is possible to create a ConfigObj where the first item is a section. >>This means that when you call the ``write`` method the resulting config >>file looks like : >> >> [ section ] >> key = value >>key = value >> >>Which is *invalid* ! >>My proposed solution is to have the ``write`` method check if the first >>value is a section - and write out non-section values first (there may >>not be any). This means not obeying sequence though, so it's not ideal. > > > Something is fishy here. I did not yet look closely at the refactored code, > so I'll only speak about concepts. > > As I understand it, the problem stems from the fact that the ConfigObj > instance is a Section itself. Its rendering, though, should implicit, that > is, without a section header, and without indenting for contained items, > either subsections or scalar values. > That won't work either. If you have values, then a section, then more values - if the section *isn't* indented then there's no way of indicating that the section has ended. If that doesn't matter to you (you have no values *after* the section) then you can *write* the config file without indentation. (ConfigObj will read it correctly) - but when it writes out it will indent sections. > What I don't get is, what difference does it make what the first item is? > All items contained in the ConfigObj instance should be "rendered" to text > without indentation, whether they were passed in, or read from a file. > > So I'd say, no workarounds, let's look closer at what's happening. > Part of the problem is that I allowed the root indentation to be non zero. In other words : key = value key2 = value2 [ section ] key = value is a valid config file. (Note the uniform indentation for the whole file). Hmmmm..... but this gives me an idea. The problem is that the initial indent level is set as ``None``. THe *initital* indent level is then set to the *first* indent it encounters : (line 690) if this_section.indent is None: this_section.indent = indent_lev However - if the first item is a section then it shouldn't do that - because later code might drop *back* an indent level to before that section. *damn* that means I have to special case it. (Normally stepping back too far is invalid - and it still can be invalid). Bah.... I think it's resolvable - but it means a little bit of spaghetti in the reader to cope with when the first item is an indented section (so we don't know what level of indent applies to any scalar values in the root section). I hope that enough of this makes sense. I think I can sort it out anyway - but sections still need to be indented by ``write`` as far as I can tell. Best Regards, Fuzzy http://www.voidspace.org.uk/python |