|
From: Michael F. <fuz...@vo...> - 2008-01-12 13:35:26
|
Arve Knudsen wrote:
> Hi again, Michael
>
> I have now written doctests for the new functionality. In doing so, I
> discovered there was a problem with my initial implementation: only
> fields for which there weren't specified any value were registered
> in the default_values attribute. In order to get at the default values
> for all fields, I had to make some changes to validate.py as well. The
> changes should be backwards-compatible from my testing (no doctests
> break). I've attached the difference against pythonutils trunk.
>
Ah - the value of tests. :-)
Cool. I have a couple more changes to make, so hopefully I can review
this weekend. I only have a fairly minor writing task first.
Michael
> Arve
>
> On 1/7/08, *Michael Foord* <fuz...@vo...
> <mailto:fuz...@vo...>> wrote:
>
> Arve Knudsen wrote:
> >
> >
> > On 1/6/08, *Michael Foord* <fuz...@vo...
> <mailto:fuz...@vo...>
> > <mailto: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...>
> > <mailto: 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...>
> > <mailto: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/
> <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
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> ------------------------------------------------------------------------
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
|