|
From: Michael F. <fuz...@vo...> - 2008-01-07 00:22:40
|
Arve Knudsen wrote:
>
>
> On 1/6/08, *Michael Foord* <fuz...@vo...
> <mailto:fuz...@vo...>> wrote:
>
> Hello Arve,
>
> Thanks for the patch. I have some work to do on ConfigObj so I will
> include it in that. Any chance you could provide tests and
> documentation?
>
>
> I will have to look at how ConfigObj does docs/tests, hopefully
> sometime this week. Do you agree with that there should be a separate
> method restore_default, instead of restoring the default as part of
> __delitem__?
Agreed - that sounds better to me. I prefer not to 'proliferate
methods', but this change in behaviour would be a bit 'too magical'.
Michael
>
> Arve
>
> Thanks
>
> Michael
>
> Arve Knudsen wrote:
> > Hello
> >
> > I found I missed the ability to restore entries to their default
> value
> > in ConfigObj, so that you can differentiate between actualy
> deleting
> > an entry and just restoring it to the default state. My
> suggestion is
> > to track sections' default values with an additional attribute
> > "default_values", and to add a method "restore_default" for
> restoring
> > a particular entry. I also considered restoring default values
> as part
> > of __delitem__, but figured this might be too implicit and breaking
> > backwards compatibility.
> >
> > I hope to see this integrated with ConfigObj upstream as I need
> it in
> > my own project :_)
> >
> > --- configobj.py_orig 2008-01-06 22:33:58.000000000 +0100
> > +++ configobj.py 2008-01-06 22:34:29.000000000 +0100
> > @@ -498,7 +498,8 @@
> > self._cs_section_comments = {}
> > self._cs_section_inline_comments = {}
> > # for defaults
> > - self.defaults = []
> > + self.defaults = [] # Entries that have their default value
> > + self.default_values = {} # The original default values
> > #
> > # we do this explicitly so that __setitem__ is used properly
> > # (rather than just passing to ``dict.__init__``)
> > @@ -751,6 +752,18 @@
> > else:
> > self[key] = val
> > + def restore_default(self, key):
> > + """
> > + Restore default value.
> > +
> > + If there is no default value for this key, ValueError is raised.
> > + """
> > + if key not in self.default_values:
> > + raise ValueError(key)
> > + if key not in self.defaults:
> > + self.defaults.append(key)
> > + dict.__setitem__(self, key, self.default_values[key])
> > +
> > def rename(self, oldkey, newkey):
> > """
> > Change a keyname to another, without changing position in sequence.
> > @@ -2103,6 +2116,7 @@
> > section[entry] = check
> > if not copy and missing and entry not in section.defaults :
> > section.defaults.append(entry)
> > + section.default_values[entry] = check
> > #
> > # Missing sections will have been created as empty ones when the
> > # configspec was read.
> >
> >
> >
> > Cheers,
> > Arve
> >
> >
> ------------------------------------------------------------------------
> >
> >
> -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2005.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> <http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/>
> >
> ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Configobj-develop mailing list
> > Con...@li...
> <mailto:Con...@li...>
> > https://lists.sourceforge.net/lists/listinfo/configobj-develop
> >
>
>
> -------------------------------------------------------------------------
>
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> <http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> <mailto:Con...@li...>
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> ------------------------------------------------------------------------
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
|