|
From: Jeremy G. <jr...@gm...> - 2009-10-14 15:23:34
|
Hi Michael and everyone,
I'm new to using configobj, and like it a lot. thanks for your work on this!
I have 3 hopefully simple questions that I could not figure out after
reading the online manuals / help pages or past postings to the list.
my goal: I want allow users to edit their application preferences, eg,
key-bindings and other settings for the app. I'm storing the settings
in text files with syntax as expected by configobj, and have a spec
file for default values and for validation purposes. the idea is to
let users edit their config files in a text window, validate their
entries, and save. Mostly this works fabulously. the eventual goal is
to do this through a GUI, but its text for now. I'm using python 2.5,
and need to end up with code that works cross-platform (mac, win,
linux).
here's what I'm asking about: if a user enters a badly formed value
(i.e., that fails validation against the spec file), I've been using
the flatten_errors() function to process it further, like this
mock-code (hopefully indentation will be preserved when posted...):
<code>
for (section_list, key, _) in configobj.flatten_errors(cfg,
resultOfValidate):
if key is not None:
print "Bad value"
# code here to replace the bad value with the default
given in the spec file
else:
print "Missing section"
# code here to handle missing sections
</code>
my questions:
1. how to restore a default value?
I tried using restore_default(), but I kept getting key errors (and
tried several things as keys). I also tried get_default_value(), but
am confused by how to call it, and what to pass to it. I wrote a few
lines to extract the default value from the spec file as a string and
then convert the type (which mostly works, I'm just having trouble
getting default lists to work properly). it would be nice to use the
existing functions. any ideas?
2. how are missing sections reported by a Validator()? I was thinking
that they would be indicated by the key being None, based on the
example(s) on the web, but my code never hits the "missing section"
part. if a user deletes a section, the section name appears to be
deleted in the config file, but there's no missing section flagged as
a key == None in flatten_errors(). if the user then adds the [section]
back into the text, I get a duplicate section name error. so I am
confused -- what should I be looking for?
3. finally, does anyone know of an existing project I could look at
(and borrow from) that uses wxPython for a GUI for letting users
manipulate configobj data? I found a relevant post to this list by
Sebastian Wiesner on Aug 12, 2008 that linked to examples using PyQt4
(http://paste.pocoo.org/show/79974/ ) -- is there anything using
wxPython?
thanks!
--Jeremy
|
|
From: Michael F. <fuz...@vo...> - 2009-10-14 22:52:45
|
Jeremy Gray wrote:
> Hi Michael and everyone,
>
> I'm new to using configobj, and like it a lot. thanks for your work on this!
>
> I have 3 hopefully simple questions that I could not figure out after
> reading the online manuals / help pages or past postings to the list.
>
> my goal: I want allow users to edit their application preferences, eg,
> key-bindings and other settings for the app. I'm storing the settings
> in text files with syntax as expected by configobj, and have a spec
> file for default values and for validation purposes. the idea is to
> let users edit their config files in a text window, validate their
> entries, and save. Mostly this works fabulously. the eventual goal is
> to do this through a GUI, but its text for now. I'm using python 2.5,
> and need to end up with code that works cross-platform (mac, win,
> linux).
>
> here's what I'm asking about: if a user enters a badly formed value
> (i.e., that fails validation against the spec file), I've been using
> the flatten_errors() function to process it further, like this
> mock-code (hopefully indentation will be preserved when posted...):
> <code>
> for (section_list, key, _) in configobj.flatten_errors(cfg,
> resultOfValidate):
> if key is not None:
> print "Bad value"
> # code here to replace the bad value with the default
> given in the spec file
> else:
> print "Missing section"
> # code here to handle missing sections
> </code>
>
> my questions:
> 1. how to restore a default value?
> I tried using restore_default(), but I kept getting key errors (and
> tried several things as keys).
This is very odd. There is a passing test for restore_default, but when
I call it myself it doesn't work.
I need to investigate, but at least I have a failing test.
restore_default and restore_defaults should just work...
> I also tried get_default_value(), but
> am confused by how to call it, and what to pass to it.
get_default_value takes the configspec check string. You could call it
like this:
>>> from configobj import ConfigObj
>>> from validate import Validator
>>> a = ['foo = fish']
>>> b = ['foo = integer(default=3)']
>>> c = ConfigObj(a, configspec=b)
>>> c
ConfigObj({'foo': 'fish'})
>>> v = Validator()
>>> c.validate(v)
False
>>> v.get_default_value(c.configspec['foo'])
3
It shouldn't be necessary though.
I have a version 4.7 in the works that I am part way through with
various improvements / bugfixes so I can make sure this issue is included.
> I wrote a few
> lines to extract the default value from the spec file as a string and
> then convert the type (which mostly works, I'm just having trouble
> getting default lists to work properly). it would be nice to use the
> existing functions. any ideas?
>
> 2. how are missing sections reported by a Validator()? I was thinking
> that they would be indicated by the key being None, based on the
> example(s) on the web, but my code never hits the "missing section"
> part. if a user deletes a section, the section name appears to be
> deleted in the config file, but there's no missing section flagged as
> a key == None in flatten_errors(). if the user then adds the [section]
> back into the text, I get a duplicate section name error. so I am
> confused -- what should I be looking for?
>
I'm not seeing that behavior, can you provide a minimal repro. Here is a
small example of using flatten_errors where a missing section is
represented with None for the key value:
>>> from configobj import ConfigObj, flatten_errors
>>> from validate import Validator
>>> a = ['baz = 3']
>>> b = ['baz = integer', '[foo]', 'bar=integer']
>>> c = ConfigObj(a, configspec=b)
>>> v = Validator()
>>> r = c.validate(v)
>>> r
{'foo': False, 'baz': True}
>>> flatten_errors(c, r)
[(['foo'], None, False)]
> 3. finally, does anyone know of an existing project I could look at
> (and borrow from) that uses wxPython for a GUI for letting users
> manipulate configobj data? I found a relevant post to this list by
> Sebastian Wiesner on Aug 12, 2008 that linked to examples using PyQt4
> (http://paste.pocoo.org/show/79974/ ) -- is there anything using
> wxPython?
>
>
I can't help with this one I'm afraid.
Michael
> thanks!
>
> --Jeremy
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|
|
From: Jeremy G. <jr...@gm...> - 2009-10-15 01:43:50
|
Michael
thanks for such a quick reply!
> I have a version 4.7 in the works that I am part way through with
> various improvements / bugfixes so I can make sure this issue is included.
cool
>> 2. how are missing sections reported by a Validator()?
> I'm not seeing that behavior, can you provide a minimal repro.
I think I have a repro but am not positive I am doing everything
right. its not ultra-minimal because I used two text files, doing so
because this is close to my actual arrangement. its the first thing I
tried and seems to reproduce the lack of error reported for a missing
section. at the very least, going through this will reveal more
precisely what I am confused about.
so one file is 'test.cfg' and contains 4 lines (3rd line is blank--its
where I would have a section named [b] but I deleted it from the text
file):
[a]
a1 = 2
b1 = dsa
the other file is 'test.spec' and also has 4 lines:
[a]
a1 = integer(default=2)
[b]
b1 = integer(default=1)
then interactively:
>>> import configobj
>>> configobj.__version__
'4.6.0'
>>> from configobj import ConfigObj, flatten_errors
>>> from validate import Validator
>>> sp = ConfigObj('test.spec')
>>> sp
ConfigObj({'a': {'a1': 'integer(default=2)'}, 'b': {'b1':
'integer(default=1)'}})
>>> cfg = ConfigObj('test.cfg', configspec=sp)
>>> cfg
ConfigObj({'a': {'a1': '2', 'b1': 'dsa'}})
>>> v = Validator()
>>> r = cfg.validate(v)
>>> r
True
>>> flatten_errors(cfg, r)
[]
>>> cfg['a']
{'a1': 2, 'b1': 'dsa'}
>>> cfg['b']
{'b1': 1}
it seems like:
- b1 ends up in cfg[a] and is is not getting flagged as invalid
- [b] is in sp / test.spec but is not flagged as missing in cfg /
test.cfg--which surprises me
- after validation there is now a section [b] in cfg but it contains
stuff from the spec, namely the default value b1 = 1. I'm surprised
that [b] shows up at all. the fact that is does could explain why I
get a "duplicate section error" if I add the section back into my cfg
file (in my code).
I also tried doing the above but with an explicit copy=False in the
validation step, but still get section [b] showing up in cfg
>>> r = cfg.validate(v, copy=False)
>>> r
True
>>> cfg['b']
{'b1': 1}
thanks for any clarification on what should be happening
>> 3. finally, does anyone know of an existing project I could look at
>> (and borrow from) that uses wxPython for a GUI for letting users
>> manipulate configobj data?
>
> I can't help with this one I'm afraid.
ah well. maybe someone else will know of a wx example?
of course, just having configobj is a huge help! thanks again,
--Jeremy
|
|
From: Jeremy G. <jr...@gm...> - 2009-10-15 16:11:21
|
here's a more streamlined version of my repro:
>>> from configobj import ConfigObj, flatten_errors
>>> from validate import Validator
>>> s = ConfigObj(['[a]','a1=integer(default=1)','[b]','b1=integer(default=2)'])
>>> c = ConfigObj(['[a]','a1=2','b1=dsa'], configspec=s)
>>> v = Validator()
>>> r = cfg.validate(v)
>>> r
True
>>> cfg['b']
{'b1': 2}
On Wed, Oct 14, 2009 at 9:36 PM, Jeremy Gray <jr...@gm...> wrote:
> Michael
>
> thanks for such a quick reply!
>
>> I have a version 4.7 in the works that I am part way through with
>> various improvements / bugfixes so I can make sure this issue is included.
>
> cool
>
>>> 2. how are missing sections reported by a Validator()?
>> I'm not seeing that behavior, can you provide a minimal repro.
>
> I think I have a repro but am not positive I am doing everything
> right. its not ultra-minimal because I used two text files, doing so
> because this is close to my actual arrangement. its the first thing I
> tried and seems to reproduce the lack of error reported for a missing
> section. at the very least, going through this will reveal more
> precisely what I am confused about.
>
> so one file is 'test.cfg' and contains 4 lines (3rd line is blank--its
> where I would have a section named [b] but I deleted it from the text
> file):
> [a]
> a1 = 2
>
> b1 = dsa
> the other file is 'test.spec' and also has 4 lines:
> [a]
> a1 = integer(default=2)
> [b]
> b1 = integer(default=1)
>
> then interactively:
>>>> import configobj
>>>> configobj.__version__
> '4.6.0'
>>>> from configobj import ConfigObj, flatten_errors
>>>> from validate import Validator
>>>> sp = ConfigObj('test.spec')
>>>> sp
> ConfigObj({'a': {'a1': 'integer(default=2)'}, 'b': {'b1':
> 'integer(default=1)'}})
>>>> cfg = ConfigObj('test.cfg', configspec=sp)
>>>> cfg
> ConfigObj({'a': {'a1': '2', 'b1': 'dsa'}})
>>>> v = Validator()
>>>> r = cfg.validate(v)
>>>> r
> True
>>>> flatten_errors(cfg, r)
> []
>>>> cfg['a']
> {'a1': 2, 'b1': 'dsa'}
>>>> cfg['b']
> {'b1': 1}
>
> it seems like:
> - b1 ends up in cfg[a] and is is not getting flagged as invalid
> - [b] is in sp / test.spec but is not flagged as missing in cfg /
> test.cfg--which surprises me
> - after validation there is now a section [b] in cfg but it contains
> stuff from the spec, namely the default value b1 = 1. I'm surprised
> that [b] shows up at all. the fact that is does could explain why I
> get a "duplicate section error" if I add the section back into my cfg
> file (in my code).
>
> I also tried doing the above but with an explicit copy=False in the
> validation step, but still get section [b] showing up in cfg
>>>> r = cfg.validate(v, copy=False)
>>>> r
> True
>>>> cfg['b']
> {'b1': 1}
>
> thanks for any clarification on what should be happening
>
>>> 3. finally, does anyone know of an existing project I could look at
>>> (and borrow from) that uses wxPython for a GUI for letting users
>>> manipulate configobj data?
>>
>> I can't help with this one I'm afraid.
>
> ah well. maybe someone else will know of a wx example?
>
> of course, just having configobj is a huge help! thanks again,
>
> --Jeremy
>
|
|
From: Jeremy G. <jr...@gm...> - 2009-10-16 23:21:48
|
Hi Michael,
I think I've isolated this to whether the spec contains defaults for
items in the section that goes missing. if there are defaults
specified, the section gets recreated using the defaults, and
validation succeeds (== the section is not reported as missing). its
very cool to have the option to recreate the section from defaults,
but it would seem nice to be warned about that situation too. is this
expected behavior? is there a way to tell configobj what to do? sorry
if I just missed this on the web page(s).
original example that succeeds (validate reports missing section):
>>> from configobj import ConfigObj, flatten_errors
>>> from validate import Validator
>>> a = ['baz = 3']
>>> b = ['baz = integer', '[foo]', 'bar=integer']
>>> c = ConfigObj(a, configspec=b)
>>> v = Validator()
>>> r = c.validate(v)
>>> r
{'foo': False, 'baz': True}
adding 'default=2' WITHIN the section in b that is missing from a
(namely section [foo]): validate does not report the missing section:
>>> a = ['baz = 3']
>>> b = ['baz = integer', '[foo]', 'bar=integer(default=2)']
>>> c = ConfigObj(a, configspec=b)
>>> r = c.validate(v)
>>> r
True
adding 'default=2', but outside the section that is missing: validate
does report the missing section:
>>> b = ['baz = integer(default=2)', '[foo]', 'bar=integer']
>>> c = ConfigObj(a, configspec=b)
>>> r = c.validate(v)
>>> r
{'foo': False, 'baz': True}
--Jeremy
|
|
From: Michael F. <fuz...@vo...> - 2009-10-17 16:49:08
|
Jeremy Gray wrote:
> Hi Michael,
>
> I think I've isolated this to whether the spec contains defaults for
> items in the section that goes missing. if there are defaults
> specified, the section gets recreated using the defaults, and
> validation succeeds (== the section is not reported as missing). its
> very cool to have the option to recreate the section from defaults,
> but it would seem nice to be warned about that situation too. is this
> expected behavior? is there a way to tell configobj what to do? sorry
> if I just missed this on the web page(s).
>
> original example that succeeds (validate reports missing section):
>
>>>> from configobj import ConfigObj, flatten_errors
>>>> from validate import Validator
>>>> a = ['baz = 3']
>>>> b = ['baz = integer', '[foo]', 'bar=integer']
>>>> c = ConfigObj(a, configspec=b)
>>>> v = Validator()
>>>> r = c.validate(v)
>>>> r
>>>>
> {'foo': False, 'baz': True}
>
> adding 'default=2' WITHIN the section in b that is missing from a
> (namely section [foo]): validate does not report the missing section:
>
>>>> a = ['baz = 3']
>>>> b = ['baz = integer', '[foo]', 'bar=integer(default=2)']
>>>> c = ConfigObj(a, configspec=b)
>>>> r = c.validate(v)
>>>> r
>>>>
> True
>
> adding 'default=2', but outside the section that is missing: validate
> does report the missing section:
>
>>>> b = ['baz = integer(default=2)', '[foo]', 'bar=integer']
>>>> c = ConfigObj(a, configspec=b)
>>>> r = c.validate(v)
>>>> r
>>>>
> {'foo': False, 'baz': True}
>
Thanks for tracking this down - however I don't think that it is a bug.
If the only values in a missing section have defaults then there are no
missing values and nothing to report. In order to fill in the default
ConfigObj *has* to create the section so it is no longer missing.
It would also make things harder for error handling code - if you have
to handle a missing section then you would no longer know if the section
is actually present in the resulting ConfigObj instance or not...
All the best,
Michael Foord
> --Jeremy
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|
|
From: Jeremy G. <jr...@gm...> - 2009-10-17 17:27:46
|
> Thanks for tracking this down - however I don't think that it is a bug. > If the only values in a missing section have defaults then there are no > missing values yes, makes sense. but.... > and nothing to report. it seems to me that there is something that validate could usefully report (and I guess I was expecting it to): if all values in a section are being reverted to the defaults, then there is at least the possibility that they have been changed right under the user's nose. so it would be nice for validate to convey this to the outside world somehow, eg by reporting 'True' 'Default' rather than just True? It seems like returning 'True' is overly silent about this situation. eventually I'll be structuring things so that my users cannot edit the config file directly, avoiding this situation. > In order to fill in the default > ConfigObj *has* to create the section so it is no longer missing. that makes sense. thanks again, --Jeremy > It would also make things harder for error handling code - if you have > to handle a missing section then you would no longer know if the section > is actually present in the resulting ConfigObj instance or not... > > All the best, > > Michael Foord >> --Jeremy >> >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> > > > -- > http://www.ironpythoninaction.com/ > http://www.voidspace.org.uk/blog > > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: Michael F. <fuz...@vo...> - 2009-10-17 17:43:22
|
Jeremy Gray wrote: >> Thanks for tracking this down - however I don't think that it is a bug. >> If the only values in a missing section have defaults then there are no >> missing values >> > > yes, makes sense. but.... > > >> and nothing to report. >> > > it seems to me that there is something that validate could usefully > report (and I guess I was expecting it to): if all values in a section > are being reverted to the defaults, Allowing ConfigObj to provide them when the user doesn't is the only purpose of default values... > then there is at least the > possibility that they have been changed right under the user's nose. > Only if they didn't supply them (i.e. nothing has 'changed'). > so it would be nice for validate to convey this to the outside world > somehow, eg by reporting 'True' 'Default' rather than just True? It > seems like returning 'True' is overly silent about this situation. > You can always use 'config.defaults' for a list of all entries filled from default values. All the best, Michael Foord > eventually I'll be structuring things so that my users cannot edit the > config file directly, avoiding this situation. > > >> In order to fill in the default >> ConfigObj *has* to create the section so it is no longer missing. >> > > that makes sense. > > thanks again, > > --Jeremy > > > >> It would also make things harder for error handling code - if you have >> to handle a missing section then you would no longer know if the section >> is actually present in the resulting ConfigObj instance or not... >> >> All the best, >> >> Michael Foord >> >>> --Jeremy >>> >>> ------------------------------------------------------------------------------ >>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >>> is the only developer event you need to attend this year. Jumpstart your >>> developing skills, take BlackBerry mobile applications to market and stay >>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >>> http://p.sf.net/sfu/devconference >>> _______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>> >>> >> -- >> http://www.ironpythoninaction.com/ >> http://www.voidspace.org.uk/blog >> >> >> >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >> > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog |
|
From: Jeremy G. <jr...@gm...> - 2009-10-17 18:42:10
|
at risk of getting academic about this (sorry, that's my day job, being an academic :-) ), I have one more thought.... and I want to emphasize that I'm certainly not asking for a new feature, or somehow insisting that there's a bug. not at all! its your program, it works, and I'm glad to be using it. >> then there is at least the >> possibility that they have been changed right under the user's nose. >> > > Only if they didn't supply them (i.e. nothing has 'changed'). this may be true most of the time. in my case, however, I allow users to edit the config files (which I recognize is probably a bad idea, and I plan to rewrite so they can't do this). currently, my users can set specific values to something other than the defaults. if the user then deletes only the section name, all values within that section revert to defaults when validate is called -- so something has indeed changed. (the previously-edited values are retained but now they are in a different section, and so no longer accessible reliably.) and there's not a handy flag that I can catch to handle this situation. I could track which items were non-default, and then after validating check if some of the values had become the default (by comparing each against using config.defaults). but it would seem more straightforward to have validation fail and report a missing section, which could then be reset to defaults if so desired. (in my case I would not do that -- its not always a desirable action). anyway, just my .02 -- its a very nice set of tools. > You can always use 'config.defaults' for a list of all entries filled > from default values. interesting... looking forward to 4.7, --Jeremy > All the best, > > Michael Foord >> eventually I'll be structuring things so that my users cannot edit the >> config file directly, avoiding this situation. >> >> >>> In order to fill in the default >>> ConfigObj *has* to create the section so it is no longer missing. >>> >> >> that makes sense. >> >> thanks again, >> >> --Jeremy >> >> >> >>> It would also make things harder for error handling code - if you have >>> to handle a missing section then you would no longer know if the section >>> is actually present in the resulting ConfigObj instance or not... >>> >>> All the best, >>> >>> Michael Foord >>> >>>> --Jeremy >>>> >>>> ------------------------------------------------------------------------------ >>>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >>>> is the only developer event you need to attend this year. Jumpstart your >>>> developing skills, take BlackBerry mobile applications to market and stay >>>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >>>> http://p.sf.net/sfu/devconference >>>> _______________________________________________ >>>> Configobj-develop mailing list >>>> Con...@li... >>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>>> >>>> >>> -- >>> http://www.ironpythoninaction.com/ >>> http://www.voidspace.org.uk/blog >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >>> is the only developer event you need to attend this year. Jumpstart your >>> developing skills, take BlackBerry mobile applications to market and stay >>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >>> http://p.sf.net/sfu/devconference >>> _______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>> >>> >> >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> > > > -- > http://www.ironpythoninaction.com/ > http://www.voidspace.org.uk/blog > > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: David H. <neg...@gm...> - 2009-10-18 01:00:56
|
I have to respectfully disagree with your description of a 'nicer' behavior. What you're proposing would break the clean semantic behavior of cfg parsing and validating. If a user deletes a section name, but leaves the key/value pairs that previously belonged to it, then those key/value pairs *ARE* part of the preceeding section! What you're asking is for validate to complain about a scenario that is only a problem in your contorted use case. It is simultaneously a perfectly valid scenario in other cases. And furthermore, there is nothing semantically wrong with the cfg content that you provided for validation. The format and interpretation of cfg content is unambiguous and semantically robust. It's behavior in the scenario you've described is both predictable and exactly what I would want it to do. If you change a cfg file in the way you describe, and validate it with the same validation spec, it's adhering to both the cfg rules and the validation spec perfectly. You omitted a section whose values all have defaults, so it provides those defaults for you. You have key/value pairs in another section that are prefectly legitimate key/value pairs, and if there were validation rules that applied to those keywords in that particular section, they would get applied normally. Just because you didn't want those key/value pairs in that section -- i.e. their presence there is inadvertent and a result of someone changing cfg content in an unintended/undesirable way -- doesn't mean that it is the responsibility of configobj or validate to either fix or detect it, because the changes themselves are perfectly valid, and the modules can't determine intent. What you're asking is like asking the python interpreter to complain about a comment in the code because maybe someone inadvertently put a '#' in front of some lines. How is the interpreter supposed to know the difference between an intended comment and an unintended comment? regards, David Hostetler On Sat, Oct 17, 2009 at 14:41, Jeremy Gray <jr...@gm...> wrote: > at risk of getting academic about this (sorry, that's my day job, > being an academic :-) ), I have one more thought.... > > and I want to emphasize that I'm certainly not asking for a new > feature, or somehow insisting that there's a bug. not at all! its your > program, it works, and I'm glad to be using it. > > >> then there is at least the > >> possibility that they have been changed right under the user's nose. > >> > > > > Only if they didn't supply them (i.e. nothing has 'changed'). > > this may be true most of the time. in my case, however, I allow users > to edit the config files (which I recognize is probably a bad idea, > and I plan to rewrite so they can't do this). currently, my users can > set specific values to something other than the defaults. if the user > then deletes only the section name, all values within that section > revert to defaults when validate is called -- so something has indeed > changed. (the previously-edited values are retained but now they are > in a different section, and so no longer accessible reliably.) and > there's not a handy flag that I can catch to handle this situation. I > could track which items were non-default, and then after validating > check if some of the values had become the default (by comparing each > against using config.defaults). but it would seem more straightforward > to have validation fail and report a missing section, which could then > be reset to defaults if so desired. (in my case I would not do that -- > its not always a desirable action). > > anyway, just my .02 -- its a very nice set of tools. > > > You can always use 'config.defaults' for a list of all entries filled > > from default values. > > interesting... > > looking forward to 4.7, > > --Jeremy > > > > All the best, > > > > Michael Foord > >> eventually I'll be structuring things so that my users cannot edit the > >> config file directly, avoiding this situation. > >> > >> > >>> In order to fill in the default > >>> ConfigObj *has* to create the section so it is no longer missing. > >>> > >> > >> that makes sense. > >> > >> thanks again, > >> > >> --Jeremy > >> > >> > >> > >>> It would also make things harder for error handling code - if you have > >>> to handle a missing section then you would no longer know if the > section > >>> is actually present in the resulting ConfigObj instance or not... > >>> > >>> All the best, > >>> > >>> Michael Foord > >>> > >>>> --Jeremy > >>>> > >>>> > ------------------------------------------------------------------------------ > >>>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA > >>>> is the only developer event you need to attend this year. Jumpstart > your > >>>> developing skills, take BlackBerry mobile applications to market and > stay > >>>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! > >>>> http://p.sf.net/sfu/devconference > >>>> _______________________________________________ > >>>> Configobj-develop mailing list > >>>> Con...@li... > >>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop > >>>> > >>>> > >>> -- > >>> http://www.ironpythoninaction.com/ > >>> http://www.voidspace.org.uk/blog > >>> > >>> > >>> > >>> > ------------------------------------------------------------------------------ > >>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA > >>> is the only developer event you need to attend this year. Jumpstart > your > >>> developing skills, take BlackBerry mobile applications to market and > stay > >>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! > >>> http://p.sf.net/sfu/devconference > >>> _______________________________________________ > >>> Configobj-develop mailing list > >>> Con...@li... > >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop > >>> > >>> > >> > >> > ------------------------------------------------------------------------------ > >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA > >> is the only developer event you need to attend this year. Jumpstart your > >> developing skills, take BlackBerry mobile applications to market and > stay > >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! > >> http://p.sf.net/sfu/devconference > >> _______________________________________________ > >> Configobj-develop mailing list > >> Con...@li... > >> https://lists.sourceforge.net/lists/listinfo/configobj-develop > >> > > > > > > -- > > http://www.ironpythoninaction.com/ > > http://www.voidspace.org.uk/blog > > > > > > > > > ------------------------------------------------------------------------------ > > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > > is the only developer event you need to attend this year. Jumpstart your > > developing skills, take BlackBerry mobile applications to market and stay > > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > > http://p.sf.net/sfu/devconference > > _______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: Jeremy G. <jr...@gm...> - 2009-10-18 13:44:42
|
David, thanks for taking the time to carefully explain this, it helps a lot. I was confused about what validation is intended to do. I was thinking that validation should just fail if there's not an explicit section label in the config file (e.g., Michael's example). > there is nothing semantically wrong with the cfg content that you provided > for validation. I was thinking that there was something wrong--namely no section '[b]'. But it seems that a valid section can be given either a) explicitly (in the config file), or b) implicitly (in the spec file -- but only if there are defaults for the items in the section). I was only expecting "explicitly present" to count as valid, not the implicit part. So as I now understand it, validation is not merely a process to *check* whether the contents of a config file are valid by themselves (explicit), but also a process to try to *make* those contents valid, reconstructing anything necessary (such as missing sections, i.e., making the implicit part explicit again). and it can only do such reconstruction if there are default values. thanks again, --Jeremy On Sat, Oct 17, 2009 at 9:00 PM, David Hostetler <neg...@gm...> wrote: > I have to respectfully disagree with your description of a 'nicer' behavior. > > What you're proposing would break the clean semantic behavior of cfg parsing > and validating. > > If a user deletes a section name, but leaves the key/value pairs that > previously belonged to it, then those key/value pairs *ARE* part of the > preceeding section! What you're asking is for validate to complain about a > scenario that is only a problem in your contorted use case. It is > simultaneously a perfectly valid scenario in other cases. And furthermore, > there is nothing semantically wrong with the cfg content that you provided > for validation. > > The format and interpretation of cfg content is unambiguous and semantically > robust. It's behavior in the scenario you've described is both predictable > and exactly what I would want it to do. If you change a cfg file in the way > you describe, and validate it with the same validation spec, it's adhering > to both the cfg rules and the validation spec perfectly. You omitted a > section whose values all have defaults, so it provides those defaults for > you. You have key/value pairs in another section that are prefectly > legitimate key/value pairs, and if there were validation rules that applied > to those keywords in that particular section, they would get applied > normally. Just because you didn't want those key/value pairs in that > section -- i.e. their presence there is inadvertent and a result of someone > changing cfg content in an unintended/undesirable way -- doesn't mean that > it is the responsibility of configobj or validate to either fix or detect > it, because the changes themselves are perfectly valid, and the modules > can't determine intent. > > What you're asking is like asking the python interpreter to complain about a > comment in the code because maybe someone inadvertently put a '#' in front > of some lines. How is the interpreter supposed to know the difference > between an intended comment and an unintended comment? > > > regards, > > David Hostetler > > > > On Sat, Oct 17, 2009 at 14:41, Jeremy Gray <jr...@gm...> wrote: >> >> at risk of getting academic about this (sorry, that's my day job, >> being an academic :-) ), I have one more thought.... >> >> and I want to emphasize that I'm certainly not asking for a new >> feature, or somehow insisting that there's a bug. not at all! its your >> program, it works, and I'm glad to be using it. >> >> >> then there is at least the >> >> possibility that they have been changed right under the user's nose. >> >> >> > >> > Only if they didn't supply them (i.e. nothing has 'changed'). >> >> this may be true most of the time. in my case, however, I allow users >> to edit the config files (which I recognize is probably a bad idea, >> and I plan to rewrite so they can't do this). currently, my users can >> set specific values to something other than the defaults. if the user >> then deletes only the section name, all values within that section >> revert to defaults when validate is called -- so something has indeed >> changed. (the previously-edited values are retained but now they are >> in a different section, and so no longer accessible reliably.) and >> there's not a handy flag that I can catch to handle this situation. I >> could track which items were non-default, and then after validating >> check if some of the values had become the default (by comparing each >> against using config.defaults). but it would seem more straightforward >> to have validation fail and report a missing section, which could then >> be reset to defaults if so desired. (in my case I would not do that -- >> its not always a desirable action). >> >> anyway, just my .02 -- its a very nice set of tools. >> >> > You can always use 'config.defaults' for a list of all entries filled >> > from default values. >> >> interesting... >> >> looking forward to 4.7, >> >> --Jeremy >> >> >> > All the best, >> > >> > Michael Foord >> >> eventually I'll be structuring things so that my users cannot edit the >> >> config file directly, avoiding this situation. >> >> >> >> >> >>> In order to fill in the default >> >>> ConfigObj *has* to create the section so it is no longer missing. >> >>> >> >> >> >> that makes sense. >> >> >> >> thanks again, >> >> >> >> --Jeremy >> >> >> >> >> >> >> >>> It would also make things harder for error handling code - if you have >> >>> to handle a missing section then you would no longer know if the >> >>> section >> >>> is actually present in the resulting ConfigObj instance or not... >> >>> >> >>> All the best, >> >>> >> >>> Michael Foord >> >>> >> >>>> --Jeremy >> >>>> >> >>>> >> >>>> ------------------------------------------------------------------------------ >> >>>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> >>>> is the only developer event you need to attend this year. Jumpstart >> >>>> your >> >>>> developing skills, take BlackBerry mobile applications to market and >> >>>> stay >> >>>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> >>>> http://p.sf.net/sfu/devconference >> >>>> _______________________________________________ >> >>>> Configobj-develop mailing list >> >>>> Con...@li... >> >>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >>>> >> >>>> >> >>> -- >> >>> http://www.ironpythoninaction.com/ >> >>> http://www.voidspace.org.uk/blog >> >>> >> >>> >> >>> >> >>> >> >>> ------------------------------------------------------------------------------ >> >>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> >>> is the only developer event you need to attend this year. Jumpstart >> >>> your >> >>> developing skills, take BlackBerry mobile applications to market and >> >>> stay >> >>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> >>> http://p.sf.net/sfu/devconference >> >>> _______________________________________________ >> >>> Configobj-develop mailing list >> >>> Con...@li... >> >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >>> >> >>> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> >> is the only developer event you need to attend this year. Jumpstart >> >> your >> >> developing skills, take BlackBerry mobile applications to market and >> >> stay >> >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> >> http://p.sf.net/sfu/devconference >> >> _______________________________________________ >> >> Configobj-develop mailing list >> >> Con...@li... >> >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >> >> > >> > >> > -- >> > http://www.ironpythoninaction.com/ >> > http://www.voidspace.org.uk/blog >> > >> > >> > >> > >> > ------------------------------------------------------------------------------ >> > Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> > is the only developer event you need to attend this year. Jumpstart your >> > developing skills, take BlackBerry mobile applications to market and >> > stay >> > ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> > http://p.sf.net/sfu/devconference >> > _______________________________________________ >> > Configobj-develop mailing list >> > Con...@li... >> > https://lists.sourceforge.net/lists/listinfo/configobj-develop >> > >> >> >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > |
|
From: Cameron S. <cam...@cs...> - 2009-10-19 00:10:56
|
On Sun, 18 Oct 2009 12:00:23 pm David Hostetler wrote: > I have to respectfully disagree with your description of a 'nicer' > behavior. > > What you're proposing would break the clean semantic behavior of cfg > parsing and validating. > > If a user deletes a section name, but leaves the key/value pairs that > previously belonged to it, then those key/value pairs *ARE* part of the > preceeding section! What you're asking is for validate to complain about > a scenario that is only a problem in your contorted use case. It is > simultaneously a perfectly valid scenario in other cases. I must respectfully agree with you here. I also like the idea of optionally flagging extra key/value pairs that aren't in the spec, as a way of detecting typos and other errors. I'm using a ConfigObj to parse a file that also gets modified manually, so it happens more often than I'd like. Nice work, Cameron. |
|
From: Michael F. <fuz...@vo...> - 2009-10-19 00:19:51
|
On 19 Oct 2009, at 01:10, Cameron Stone <cam...@cs...> wrote: > On Sun, 18 Oct 2009 12:00:23 pm David Hostetler wrote: >> I have to respectfully disagree with your description of a 'nicer' >> behavior. >> >> What you're proposing would break the clean semantic behavior of cfg >> parsing and validating. >> >> If a user deletes a section name, but leaves the key/value pairs that >> previously belonged to it, then those key/value pairs *ARE* part of >> the >> preceeding section! What you're asking is for validate to >> complain about >> a scenario that is only a problem in your contorted use case. It is >> simultaneously a perfectly valid scenario in other cases. > > I must respectfully agree with you here. > Nice to see people respectfully agreeing with each other. It doesn't happen enough on open source mailing lists. Michael Foord -- http://www.ironpythoninaction.com > I also like the idea of optionally flagging extra key/value pairs > that aren't > in the spec, as a way of detecting typos and other errors. I'm using a > ConfigObj to parse a file that also gets modified manually, so it > happens more > often than I'd like. > > Nice work, > > Cameron. > > --- > --- > --- > --------------------------------------------------------------------- > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart > your > developing skills, take BlackBerry mobile applications to market and > stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop |