You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(5) |
Oct
(2) |
Nov
(18) |
Dec
(26) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(14) |
Feb
(28) |
Mar
(21) |
Apr
(17) |
May
(23) |
Jun
(12) |
Jul
(12) |
Aug
(7) |
Sep
(10) |
Oct
|
Nov
(4) |
Dec
(10) |
| 2007 |
Jan
(5) |
Feb
(8) |
Mar
|
Apr
|
May
(7) |
Jun
(1) |
Jul
(3) |
Aug
(3) |
Sep
(20) |
Oct
(3) |
Nov
(2) |
Dec
(12) |
| 2008 |
Jan
(40) |
Feb
(15) |
Mar
(1) |
Apr
|
May
(6) |
Jun
(19) |
Jul
(2) |
Aug
(17) |
Sep
(13) |
Oct
(7) |
Nov
(16) |
Dec
(5) |
| 2009 |
Jan
(15) |
Feb
(11) |
Mar
(11) |
Apr
(8) |
May
(6) |
Jun
(15) |
Jul
(19) |
Aug
(2) |
Sep
|
Oct
(19) |
Nov
(1) |
Dec
(3) |
| 2010 |
Jan
(12) |
Feb
(25) |
Mar
(45) |
Apr
(4) |
May
(2) |
Jun
(4) |
Jul
(6) |
Aug
(13) |
Sep
(1) |
Oct
(2) |
Nov
(2) |
Dec
(9) |
| 2011 |
Jan
(24) |
Feb
(7) |
Mar
(1) |
Apr
(6) |
May
(3) |
Jun
(3) |
Jul
|
Aug
(13) |
Sep
(9) |
Oct
(7) |
Nov
(17) |
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
(5) |
Apr
(3) |
May
|
Jun
|
Jul
(3) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
|
Dec
|
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(12) |
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
(4) |
Feb
(3) |
Mar
|
Apr
(17) |
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(3) |
Oct
(3) |
Nov
|
Dec
|
| 2015 |
Jan
(11) |
Feb
|
Mar
|
Apr
(2) |
May
(1) |
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
(2) |
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
(10) |
Dec
|
| 2017 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Michael F. <fuz...@vo...> - 2011-11-21 12:03:43
|
On 21/11/2011 11:46, Gibhardt, Holger wrote: > Dear Michael, > >> Ouch, not good. But if the attempt to write raises an exception, that can be > caught with try / except, why does that>exception not stop execution? If the > code blocks then it can't raise an exception. If it raises an exception then > it isn't>blocked. > > now I understand your point and see, that I explained the crash not exactly: > There is an exception, which comes from the python function "open". But, as I > did not catch this exception, my program hung up. That isn't how Python works, an unhandled exception causes program termination - so if your program is blocking when this exception is raised then something else is happening. >> This seems like good code for your particular situation, but I don't think > it's generally necessary. (The exception>handling masks the original error > for example by reraising the exception as a GammaError.) > > O.k., using my defined "GammaError" is the way, we get a possible error to > the user (giving him an information about a missing .ini-file). The original exception contains the specific error message as to why the file couldn't be written. Your code (which I realise is just how you handle this particular problem and not necessarily what you are suggesting should go directly into ConfigObj) removes this error message and raises its own. As a general matter obscuring error messages like this is not helpful - which is part of the reason I prefer to let the exception be unhandled in ConfigObj and let *callers* of the code decide how to handle any exceptions. > > I think, this is a problem, which should be handled in configobj.py: > > You check at the beginning, if the filehandler yields a good result (what I > called "safe"). But later, this is not done anymore: The file could be > blocked by another application, could be deleted whatsoever. Then you have > the "open" exception and you must find out, what was responsible for this > exception. It is fine for you to retry failed writes - but that is the decision for the people calling write (other people may want to handle the situation differently). So whilst I think your approach is fine I disagree that it should be built into configobj. An interesting discussion anyway. > > File opening should be handled safe at any time like in standard C. Standard C does not automatically retry failed writes :-) All the best, Michael Foord > If you don't agree to my opinion, it's no problem. > > Best regards > > Holger > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html |
|
From: Gibhardt, H. <hg...@gw...> - 2011-11-21 11:46:20
|
Dear Michael, >Ouch, not good. But if the attempt to write raises an exception, that can be caught with try / except, why does that >exception not stop execution? If the code blocks then it can't raise an exception. If it raises an exception then it isn't >blocked. now I understand your point and see, that I explained the crash not exactly: There is an exception, which comes from the python function "open". But, as I did not catch this exception, my program hung up. >This seems like good code for your particular situation, but I don't think it's generally necessary. (The exception >handling masks the original error for example by reraising the exception as a GammaError.) O.k., using my defined "GammaError" is the way, we get a possible error to the user (giving him an information about a missing .ini-file). I think, this is a problem, which should be handled in configobj.py: You check at the beginning, if the filehandler yields a good result (what I called "safe"). But later, this is not done anymore: The file could be blocked by another application, could be deleted whatsoever. Then you have the "open" exception and you must find out, what was responsible for this exception. File opening should be handled safe at any time like in standard C. If you don't agree to my opinion, it's no problem. Best regards Holger |
|
From: Michael F. <fuz...@vo...> - 2011-11-21 11:05:58
|
On 21/11/2011 10:44, Gibhardt, Holger wrote:
> Dear Michael,
>
> thank you for your reply. Here are my comments:
>
>> What do you mean by hangs up?
> The python control program hangs: no input possible, no Ctrl-C; even after
> minutes. I have to shot up my python program.
Ouch, not good. But if the attempt to write raises an exception, that
can be caught with try / except, why does that exception not stop
execution? If the code blocks then it can't raise an exception. If it
raises an exception then it isn't blocked.
>> How does this make file access "unsafe"? (I don't know what you mean by
> unsafe here?)
>
> I mean, the write-routine does not check, if the file handler to the file is
> valid. In that sense here, it might be that the file is blocked and you do
> not get an error from configobj, although you cannot open it and write to it.
>
>> Can you show me the actual code? Do you just catch and ignore exceptions
> raised during writing? That sounds like a bad idea in general.
>
> My code is now:
>
> from configobj import ConfigObj
> from time import *
> from errlog import *
>
> class GammaConfigObj(ConfigObj):
> def __init__(self, infile=None, options=None, **kwargs):
> ConfigObj.__init__(self,infile,options,**kwargs)
> def writeconfig(self,Attempts=2):
> for att in range(Attempts):
> try:
> self.write()
> break
> except:
> if (att +1< Attempts):
> mess = 'Writing to gamma.ini failed - Trying again.'
> print mess
> logerror('config',mess)
> sleep(3)
> else:
> mess = 'Writing to gamma.ini failed - Stop and Raise
> Error'
> logerror('config',mess)
> raise GammaError(mess)
>
> Now, the problem of robocopy and configobj is catched by attempting several
> times the writing with a small waiting time and the program can continue if
> it was successful. The occurrence of the error is logged. And if after the
> number of attempts the writing is not possible, the program aborts with an
> error. Since we added this functionality, we have a list with the occurrences
> of the error and comes roughly every 2 days.
This seems like good code for your particular situation, but I don't
think it's generally necessary. (The exception handling masks the
original error for example by reraising the exception as a GammaError.)
All the best,
Michael Foord
>
> Best regards
>
> Holger
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
|
|
From: Gibhardt, H. <hg...@gw...> - 2011-11-21 10:44:37
|
Dear Michael,
thank you for your reply. Here are my comments:
>What do you mean by hangs up?
The python control program hangs: no input possible, no Ctrl-C; even after
minutes. I have to shot up my python program.
>How does this make file access "unsafe"? (I don't know what you mean by
unsafe here?)
I mean, the write-routine does not check, if the file handler to the file is
valid. In that sense here, it might be that the file is blocked and you do
not get an error from configobj, although you cannot open it and write to it.
>Can you show me the actual code? Do you just catch and ignore exceptions
raised during writing? That sounds like a bad idea in general.
My code is now:
from configobj import ConfigObj
from time import *
from errlog import *
class GammaConfigObj(ConfigObj):
def __init__(self, infile=None, options=None, **kwargs):
ConfigObj.__init__(self,infile,options,**kwargs)
def writeconfig(self,Attempts=2):
for att in range(Attempts):
try:
self.write()
break
except:
if (att +1 < Attempts):
mess = 'Writing to gamma.ini failed - Trying again.'
print mess
logerror('config',mess)
sleep(3)
else:
mess = 'Writing to gamma.ini failed - Stop and Raise
Error'
logerror('config',mess)
raise GammaError(mess)
Now, the problem of robocopy and configobj is catched by attempting several
times the writing with a small waiting time and the program can continue if
it was successful. The occurrence of the error is logged. And if after the
number of attempts the writing is not possible, the program aborts with an
error. Since we added this functionality, we have a list with the occurrences
of the error and comes roughly every 2 days.
Best regards
Holger
|
|
From: Michael F. <fuz...@vo...> - 2011-11-18 11:23:20
|
On 17 Nov 2011, at 09:00, Gibhardt, Holger wrote: > Dear colleagues, > > I am not sure, if this is the correct way to inform you from a specific > problematic behaviour of this module: > > Situation: > 1. I make experiments with detectors and motors - with python as control > software (on windows xp). > > 2. I use configobj to log changes of status (movement of motors etc.). For > years, all that works without problems. > > 3. Since a couple of weeks, I use robocopy in parallel to copy new generated > and changed files on a separate file server. This is done 47 times per day. > > 4. It happens that if robocopy copies the changed .ini file and at the same > time configobj wants to write new information into that file, that python > hangs up. (This happened once a week and to some time to find out). What do you mean by hangs up? > > Solution: > After hard work for finding the reason for the hang up, I came into the > configobj module and found the following: If the handler is made at first, > configobj uses safe methods for verifying the logfile. However, any attempt > to write into the ini file is done unsafe: > > def write: > if outfile is not None: > outfile.write(output) > else: > h = open(self.filename, 'wb') > h.write(output) > h.close() > > That means, file access is unsafe any time. How does this make file access "unsafe"? (I don't know what you mean by unsafe here?) > > Now, I derived a new class from configobj and added a new function, which > only uses safe file access (with try blocks). And now, the problem is solved > and I see, that this happens once a week - but the error is catched. Can you show me the actual code? Do you just catch and ignore exceptions raised during writing? That sounds like a bad idea in general. > > I think, it would be better to do this in the original configobj module, as > the user takes it as whole and thinks, that it works well at any time. File > access should be safe. Well it should be, but errors mean that the file hasn't been written properly - so the correct thing to do is to just let the exception propagate I think. In your specific case it may be that retrying on exception is the right approach - but not for every case I don't think. All the best, Michael > > However, thank you for this great module! > > Holger > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html |
|
From: Gibhardt, H. <hg...@gw...> - 2011-11-17 09:00:24
|
Dear colleagues,
I am not sure, if this is the correct way to inform you from a specific
problematic behaviour of this module:
Situation:
1. I make experiments with detectors and motors - with python as control
software (on windows xp).
2. I use configobj to log changes of status (movement of motors etc.). For
years, all that works without problems.
3. Since a couple of weeks, I use robocopy in parallel to copy new generated
and changed files on a separate file server. This is done 47 times per day.
4. It happens that if robocopy copies the changed .ini file and at the same
time configobj wants to write new information into that file, that python
hangs up. (This happened once a week and to some time to find out).
Solution:
After hard work for finding the reason for the hang up, I came into the
configobj module and found the following: If the handler is made at first,
configobj uses safe methods for verifying the logfile. However, any attempt
to write into the ini file is done unsafe:
def write:
if outfile is not None:
outfile.write(output)
else:
h = open(self.filename, 'wb')
h.write(output)
h.close()
That means, file access is unsafe any time.
Now, I derived a new class from configobj and added a new function, which
only uses safe file access (with try blocks). And now, the problem is solved
and I see, that this happens once a week - but the error is catched.
I think, it would be better to do this in the original configobj module, as
the user takes it as whole and thinks, that it works well at any time. File
access should be safe.
However, thank you for this great module!
Holger
|
|
From: David H. <neg...@gm...> - 2011-10-28 18:27:12
|
Hey Thomas,
I had a comment that isn't configobj-specific, but I'll keep this on-list in
case it might benefit others.
You mentioned KeyErrors... One way to use dicts without risking KeyError
exceptions is to use the get() function instead of the [] syntax. I.e.:
>>> x = {'a':42}
>>> x.get('a')
42
>>> x.get('b')
>>>
>>> x.get('b') is None
True
>>> x.get('b', 'somedefault')
>>> 'somedefault'
So if a key exists, the value is returned, as expected. If the key doesn't
exist, you just get None, or a default value if you provide one in the
call. The concept is similar to the getattr() function, but you don't get
an exception if the entry doesn't exist even if you don't provide a default.
Not that you couldn't wrap dictionary access in a try/except block, but
using get() is a cleaner implementation when you know you're dealing with
something that may or may not exist.
cheers,
-hoss
David Hostetler
neg...@gm...
p.s. - I didn't understand your class comment regarding single quotes and am
curious what you mean (since I think classes probably can be used - there's
almost no circumstance in which they can't).
On Fri, Oct 28, 2011 at 13:04, Thomas Sturges-Allard <zi...@ho...>wrote:
> Thanks for all your input. I did quite quickly notice the limitations of
> the code but I think I have managed to work round it for my purposes. I am
> building a adventure game engine for fun/honing my Python knowledge and so I
> wanted to be able to check if, for example a given choice had requirements
> or effects (which would be stored in a sub-section) so that code relating to
> processing these could be bypassed. As such I am mostly going to be checking
> for a subsection in a section that is already known to be there (so no
> chance of a KeyError). The code I will probably use is
>
> 'Basics' *in* character.sections #for checking for primary sections
> 'name' *in* character*[*'Basics'*]*.scalars #for checking for options in a
> (known) primary section
> 'stuff' *in* character*[*'Basics'*]*.sections #for checking for
> sub-sections in a (known) primary section
> 'blah' *in* character*[*'Basics'*][*'stuff'*]*.scalars #for checking for
> options in a (known) sub-section in a (known) primary section
> etc if need be....
>
> I won't be using this for a bit though as I have only got just (today)
> finished off the adventure and character loading system but I didn't want to
> start building configobj into the code if then it would screw me over down
> the line. The methods above are simple enough so it looks like everything
> should be cool :) . Is somewhat of a shame they can't be used in a class
> thougth (as single quotes are needed inside and out of the class which I
> don't think is possible) because it would have been a great entry for me
> into classes (believe it or not I haven't used them yet). The GitHun Gist (I
> haven't got my head round Git yet) can be found here:
> https://gist.github.com/1322726 if you're interested.
>
> Thanks again! For a great module and help using it!
>
> Thomas Sturges-Allard
>
> ------------------------------
> From: neg...@gm...
> Date: Fri, 28 Oct 2011 10:44:32 -0400
> Subject: Re: [Configobj-develop] has_section function?
> To: fuz...@vo...
> CC: con...@li...; zi...@ho...
>
>
>
>
> On Fri, Oct 28, 2011 at 10:18, Michael Foord <fuz...@vo...>wrote:
>
> On 28/10/2011 15:08, David Hostetler wrote:
>
> Hey Michael,
>
> Unless I'm mistaken, your suggestions don't completely address Thomas'
> question.
>
> configfile.sections and configfile.scalars don't expose nested entries. So
> yes, he can use those, but they'll be misleading unless he's using
> configuration data that he can guarantee isn't nested, in which case he's
> not any better off than when he was using ConfigParser.
>
>
> Well he is because you can't have nested sections *at all* with
> ConfigParser (and there are lots of other reasons to prefer ConfigObj...).
>
>
>
> Of course - lots of really good reasons to prefer ConfigObj. :) I
> certainly didn't mean for that to sound disparaging. Just that if he
> migrated to ConfigObj because he wanted nested data, then artificially
> constraining himself to not be nested defeats the purpose.
>
>
>
>
> I *think* that he was hoping there was some super-convenient way to ask a
> ConfigObj instance to be deeply introspective and test for a given
> section-name/key-name anywhere in the cfg hierarchy.
>
> Not terribly difficult to do with a smidge of recursion, but not natively
> offered by the ConfigObj interface as far as I know.
>
>
> The code I suggested was an exact equivalent of "has_section" and
> "has_option" in ConfigParser - but you're right, this code only checks the
> current section and doesn't recurse. You could write a recursive version
> easily, but what would that be useful for? Knowing that *somewhere* inside a
> nested data structure the section/option exists isn't useful, because you
> still have to write the recursive code to find it. By the time you've done
> that you've written the code to check as well...
>
>
>
> All true. If I were to write something addressing this concept, I'd have
> it actually return the entity that it was testing for. I.e. if it returns
> None, the desired item doesn't exist, otherwise it does and here it is for
> your convenience.
>
>
> configob (and validate) rock, as always. :)
>
>
>
> regards,
>
> -hoss
>
> David Hostetler
> neg...@gm...
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|
|
From: Thomas Sturges-A. <zi...@ho...> - 2011-10-28 17:04:52
|
Thanks for all your input. I did quite quickly notice the limitations of the code but I think I have managed to work round it for my purposes. I am building a adventure game engine for fun/honing my Python knowledge and so I wanted to be able to check if, for example a given choice had requirements or effects (which would be stored in a sub-section) so that code relating to processing these could be bypassed. As such I am mostly going to be checking for a subsection in a section that is already known to be there (so no chance of a KeyError). The code I will probably use is 'Basics' in character.sections #for checking for primary sections 'name' in character['Basics'].scalars #for checking for options in a (known) primary section 'stuff' in character['Basics'].sections #for checking for sub-sections in a (known) primary section 'blah' in character['Basics']['stuff'].scalars #for checking for options in a (known) sub-section in a (known) primary section etc if need be.... I won't be using this for a bit though as I have only got just (today) finished off the adventure and character loading system but I didn't want to start building configobj into the code if then it would screw me over down the line. The methods above are simple enough so it looks like everything should be cool :) . Is somewhat of a shame they can't be used in a class thougth (as single quotes are needed inside and out of the class which I don't think is possible) because it would have been a great entry for me into classes (believe it or not I haven't used them yet). The GitHun Gist (I haven't got my head round Git yet) can be found here: https://gist.github.com/1322726 if you're interested. Thanks again! For a great module and help using it! Thomas Sturges-Allard From: neg...@gm... Date: Fri, 28 Oct 2011 10:44:32 -0400 Subject: Re: [Configobj-develop] has_section function? To: fuz...@vo... CC: con...@li...; zi...@ho... On Fri, Oct 28, 2011 at 10:18, Michael Foord <fuz...@vo...> wrote: On 28/10/2011 15:08, David Hostetler wrote: Hey Michael, Unless I'm mistaken, your suggestions don't completely address Thomas' question. configfile.sections and configfile.scalars don't expose nested entries. So yes, he can use those, but they'll be misleading unless he's using configuration data that he can guarantee isn't nested, in which case he's not any better off than when he was using ConfigParser. Well he is because you can't have nested sections *at all* with ConfigParser (and there are lots of other reasons to prefer ConfigObj...). Of course - lots of really good reasons to prefer ConfigObj. :) I certainly didn't mean for that to sound disparaging. Just that if he migrated to ConfigObj because he wanted nested data, then artificially constraining himself to not be nested defeats the purpose. I *think* that he was hoping there was some super-convenient way to ask a ConfigObj instance to be deeply introspective and test for a given section-name/key-name anywhere in the cfg hierarchy. Not terribly difficult to do with a smidge of recursion, but not natively offered by the ConfigObj interface as far as I know. The code I suggested was an exact equivalent of "has_section" and "has_option" in ConfigParser - but you're right, this code only checks the current section and doesn't recurse. You could write a recursive version easily, but what would that be useful for? Knowing that *somewhere* inside a nested data structure the section/option exists isn't useful, because you still have to write the recursive code to find it. By the time you've done that you've written the code to check as well... All true. If I were to write something addressing this concept, I'd have it actually return the entity that it was testing for. I.e. if it returns None, the desired item doesn't exist, otherwise it does and here it is for your convenience. configob (and validate) rock, as always. :) regards, -hoss David Hostetler neg...@gm... |
|
From: David H. <neg...@gm...> - 2011-10-28 14:45:05
|
On Fri, Oct 28, 2011 at 10:18, Michael Foord <fuz...@vo...>wrote: > On 28/10/2011 15:08, David Hostetler wrote: > > Hey Michael, > > Unless I'm mistaken, your suggestions don't completely address Thomas' > question. > > configfile.sections and configfile.scalars don't expose nested entries. So > yes, he can use those, but they'll be misleading unless he's using > configuration data that he can guarantee isn't nested, in which case he's > not any better off than when he was using ConfigParser. > > > Well he is because you can't have nested sections *at all* with > ConfigParser (and there are lots of other reasons to prefer ConfigObj...). > > Of course - lots of really good reasons to prefer ConfigObj. :) I certainly didn't mean for that to sound disparaging. Just that if he migrated to ConfigObj because he wanted nested data, then artificially constraining himself to not be nested defeats the purpose. > > I *think* that he was hoping there was some super-convenient way to ask a > ConfigObj instance to be deeply introspective and test for a given > section-name/key-name anywhere in the cfg hierarchy. > > Not terribly difficult to do with a smidge of recursion, but not natively > offered by the ConfigObj interface as far as I know. > > > The code I suggested was an exact equivalent of "has_section" and > "has_option" in ConfigParser - but you're right, this code only checks the > current section and doesn't recurse. You could write a recursive version > easily, but what would that be useful for? Knowing that *somewhere* inside a > nested data structure the section/option exists isn't useful, because you > still have to write the recursive code to find it. By the time you've done > that you've written the code to check as well... > > All true. If I were to write something addressing this concept, I'd have it actually return the entity that it was testing for. I.e. if it returns None, the desired item doesn't exist, otherwise it does and here it is for your convenience. configob (and validate) rock, as always. :) regards, -hoss David Hostetler neg...@gm... |
|
From: Michael F. <fuz...@vo...> - 2011-10-28 14:18:21
|
On 28/10/2011 15:08, David Hostetler wrote:
> Hey Michael,
>
> Unless I'm mistaken, your suggestions don't completely address Thomas'
> question.
>
> configfile.sections and configfile.scalars don't expose nested
> entries. So yes, he can use those, but they'll be misleading unless
> he's using configuration data that he can guarantee isn't nested, in
> which case he's not any better off than when he was using ConfigParser.
>
Well he is because you can't have nested sections *at all* with
ConfigParser (and there are lots of other reasons to prefer ConfigObj...).
> I *think* that he was hoping there was some super-convenient way to
> ask a ConfigObj instance to be deeply introspective and test for a
> given section-name/key-name anywhere in the cfg hierarchy.
>
> Not terribly difficult to do with a smidge of recursion, but not
> natively offered by the ConfigObj interface as far as I know.
The code I suggested was an exact equivalent of "has_section" and
"has_option" in ConfigParser - but you're right, this code only checks
the current section and doesn't recurse. You could write a recursive
version easily, but what would that be useful for? Knowing that
*somewhere* inside a nested data structure the section/option exists
isn't useful, because you still have to write the recursive code to find
it. By the time you've done that you've written the code to check as well...
(It may be useful for configfile of *known* structure - but in that case
you can just go to the section that should contain the option /
sub-section and use the code I suggested.)
That aside, recursively checking sections is easy, here's an example
that can be modified based on the exact use case required:
def contains_entry(section, entry):
if entry in section:
return True
for sub in section.sections:
if contains_entry(section[sub], entry):
return True
You call it with:
contains_entry(configfile, 'some_key')
All the best,
Michael Foord
>
>
> cheers,
>
> -hoss
>
> David Hostetler
> neg...@gm... <mailto:neg...@gm...>
>
>
>
> On Thu, Oct 27, 2011 at 19:51, Michael Foord
> <fuz...@vo... <mailto:fuz...@vo...>> wrote:
>
> Hello Thomas,
>
> Your email isn't spam, it's entirely on topic!
>
> ConfigObj doesn't have those methods specifically - *however* the
> information is easy to find out.
>
> The following tells you if an entry is in a ConfigObj instance
> (but not whether it is a section or a value):
>
> 'foo' in configfile
>
> For just checking for the presence of a section you can do:
>
> 'foo' in configfile.sections
>
> For values you can do:
>
> 'foo' in configfile.scalars
>
> That code works on individual sections as well as the main
> ConfigObj instance.
>
> You could also do:
>
> result = configfile.get('foo')
> if result is None:
> # entry is not present
> elif isinstance(result, dict):
> # entry is present and a section
> else:
> # entry is present and a value
>
> All the best,
>
> Michael Foord
>
>
> On 26/10/2011 23:03, Thomas Sturges-Allard wrote:
>> Sorry to spam, but i'm guessing this can be answered easily.
>>
>> Was really glad to discover the configobj module as I had
>> previously been restricted by ConfigParser.
>>
>> The only important feature I have yet to find is an equivalent of
>> " configfile.has_section('Blah') " and " configfile.has_option
>> ('Section1', 'Option1') " which are listed here:
>> http://docs.python.org/library/configparser.html?highlight=config%20parser#configparser-objects
>> . Do such things exist?
>>
>> I guess I could use ConfigParser as well just for this feature
>> but it would not support nested sections. I had a fiddle with
>> exceptions in classes as a way of making a feature myself but I
>> can't seem to get it to work for KeyError exceptions (i.e. they
>> crash the interpreter anyway). The validation system is not
>> practical in this instance as what will be checked and what it
>> will be checked for is reasonably dynamic.
>>
>> I am using Python 2.72 and configobj 7.72 on Windows XP with
>> Notepad ++
>>
>> Thanks!
>>
>> Thomas Sturges-Allard
>> http://zig13.termisoc.org
>>
>>
>> ------------------------------------------------------------------------------
>> The demand for IT networking professionals continues to grow, and the
>> demand for specialized networking skills is growing even more rapidly.
>> Take a complimentary Learning@Cisco Self-Assessment and learn
>> about Cisco certifications, training, and career opportunities.
>> http://p.sf.net/sfu/cisco-dev2dev
>>
>>
>> _______________________________________________
>> Configobj-develop mailing list
>> Con...@li... <mailto:Con...@li...>
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
> --
> http://www.voidspace.org.uk/
>
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
> -- the sqlite blessinghttp://www.sqlite.org/different.html
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> <mailto:Con...@li...>
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
>
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
|
|
From: David H. <neg...@gm...> - 2011-10-28 14:09:20
|
Hey Michael,
Unless I'm mistaken, your suggestions don't completely address Thomas'
question.
configfile.sections and configfile.scalars don't expose nested entries. So
yes, he can use those, but they'll be misleading unless he's using
configuration data that he can guarantee isn't nested, in which case he's
not any better off than when he was using ConfigParser.
I *think* that he was hoping there was some super-convenient way to ask a
ConfigObj instance to be deeply introspective and test for a given
section-name/key-name anywhere in the cfg hierarchy.
Not terribly difficult to do with a smidge of recursion, but not natively
offered by the ConfigObj interface as far as I know.
cheers,
-hoss
David Hostetler
neg...@gm...
On Thu, Oct 27, 2011 at 19:51, Michael Foord <fuz...@vo...>wrote:
> Hello Thomas,
>
> Your email isn't spam, it's entirely on topic!
>
> ConfigObj doesn't have those methods specifically - *however* the
> information is easy to find out.
>
> The following tells you if an entry is in a ConfigObj instance (but not
> whether it is a section or a value):
>
> 'foo' in configfile
>
> For just checking for the presence of a section you can do:
>
> 'foo' in configfile.sections
>
> For values you can do:
>
> 'foo' in configfile.scalars
>
> That code works on individual sections as well as the main ConfigObj
> instance.
>
> You could also do:
>
> result = configfile.get('foo')
> if result is None:
> # entry is not present
> elif isinstance(result, dict):
> # entry is present and a section
> else:
> # entry is present and a value
>
> All the best,
>
> Michael Foord
>
>
> On 26/10/2011 23:03, Thomas Sturges-Allard wrote:
>
> Sorry to spam, but i'm guessing this can be answered easily.
>
> Was really glad to discover the configobj module as I had previously been
> restricted by ConfigParser.
>
> The only important feature I have yet to find is an equivalent of "
> configfile.has_section('Blah') " and " configfile.has_option ('Section1',
> 'Option1') " which are listed here:
> http://docs.python.org/library/configparser.html?highlight=config%20parser#configparser-objects. Do such things exist?
>
> I guess I could use ConfigParser as well just for this feature but it
> would not support nested sections. I had a fiddle with exceptions in classes
> as a way of making a feature myself but I can't seem to get it to work for
> KeyError exceptions (i.e. they crash the interpreter anyway). The validation
> system is not practical in this instance as what will be checked and what it
> will be checked for is reasonably dynamic.
>
> I am using Python 2.72 and configobj 7.72 on Windows XP with Notepad ++
>
> Thanks!
>
> Thomas Sturges-Allard
> http://zig13.termisoc.org
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev
>
>
>
> _______________________________________________
> Configobj-develop mailing lis...@li...://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
>
> -- http://www.voidspace.org.uk/
>
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
> -- the sqlite blessing http://www.sqlite.org/different.html
>
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|
|
From: Michael F. <fuz...@vo...> - 2011-10-28 00:22:24
|
Hello Thomas,
Your email isn't spam, it's entirely on topic!
ConfigObj doesn't have those methods specifically - *however* the
information is easy to find out.
The following tells you if an entry is in a ConfigObj instance (but not
whether it is a section or a value):
'foo' in configfile
For just checking for the presence of a section you can do:
'foo' in configfile.sections
For values you can do:
'foo' in configfile.scalars
That code works on individual sections as well as the main ConfigObj
instance.
You could also do:
result = configfile.get('foo')
if result is None:
# entry is not present
elif isinstance(result, dict):
# entry is present and a section
else:
# entry is present and a value
All the best,
Michael Foord
On 26/10/2011 23:03, Thomas Sturges-Allard wrote:
> Sorry to spam, but i'm guessing this can be answered easily.
>
> Was really glad to discover the configobj module as I had previously
> been restricted by ConfigParser.
>
> The only important feature I have yet to find is an equivalent of "
> configfile.has_section('Blah') " and " configfile.has_option
> ('Section1', 'Option1') " which are listed here:
> http://docs.python.org/library/configparser.html?highlight=config%20parser#configparser-objects
> . Do such things exist?
>
> I guess I could use ConfigParser as well just for this feature but it
> would not support nested sections. I had a fiddle with exceptions in
> classes as a way of making a feature myself but I can't seem to get it
> to work for KeyError exceptions (i.e. they crash the interpreter
> anyway). The validation system is not practical in this instance as
> what will be checked and what it will be checked for is reasonably
> dynamic.
>
> I am using Python 2.72 and configobj 7.72 on Windows XP with Notepad ++
>
> Thanks!
>
> Thomas Sturges-Allard
> http://zig13.termisoc.org
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
>
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
|
|
From: Thomas Sturges-A. <zi...@ho...> - 2011-10-26 22:16:32
|
Sorry to spam, but i'm guessing this can be answered easily.
Was really glad to discover the configobj module as I had previously been restricted by ConfigParser.
The only important feature I have yet to find is an equivalent of " configfile.has_section('Blah') " and " configfile.has_option ('Section1', 'Option1') " which are listed here: http://docs.python.org/library/configparser.html?highlight=config%20parser#configparser-objects . Do such things exist?
I guess I could use ConfigParser as well just for this feature but it would not support nested sections. I had a fiddle with exceptions in classes as a way of making a feature myself but I can't seem to get it to work for KeyError exceptions (i.e. they crash the interpreter anyway). The validation system is not practical in this instance as what will be checked and what it will be checked for is reasonably dynamic.
I am using Python 2.72 and configobj 7.72 on Windows XP with Notepad ++
Thanks!
Thomas Sturges-Allardhttp://zig13.termisoc.org |
|
From: <gar...@th...> - 2011-09-06 23:27:51
|
Hi Chris and Michael,
Sorry, I spoke too soon. Not sure what I did just a few minutes ago, but
it works now as you mentioned.
Thanks!
Gary
From: Chris Sontag [mailto:so...@st...]
Sent: Tuesday, September 06, 2011 6:22 PM
To: con...@li...
Cc: Siaw, Gary (Professional)
Subject: Re: [Configobj-develop] default values not being set with
validation.
Hi Gary,
Are you saying that you have inspected the Python object (self.config)
and, after validation, it does not have those keys?
Or are you saying that you later call self.config.write() and those keys
are not written out?
Those are two different things. If the Python object has those keys
(which it should), the values will be the defaults.
Chris
On 9/6/11 7:13 PM, gar...@th... wrote:
Thanks for the quick responses!
Unfortunately, that is not what happens.
If I remove the lines so that my config_file looks like this:
[Environment]
name = 'qapod5'
and have the same configspec, the defaults are not put in.
-----Original Message-----
From: Michael Foord [mailto:fuz...@vo...]
Sent: Tuesday, September 06, 2011 5:19 PM
To: con...@li...
Cc: Siaw, Gary (Professional)
Subject: Re: [Configobj-develop] default values not being set with
validation.
Hey Gary,
Chris is correct - those values are not "missing", they exist but are
set to the empty string. Remove them and the validation defaults should
be filled in. Alternatively write your own validation functions that
interpret and empty value as missing and uses the default instead.
The validate module documentation shows how to write validation
functions.
All the best,
Michael
On 6 Sep 2011, at 23:01, Chris Sontag wrote:
Hi Gary,
I'm usually just a lurker on this list, but try taking
"services" and
"deploy_sso" out of your config file. Right now they are set to empty
strings. If they come out, they will be filled with default values (in
self.config) after your validate() call.
Chris
On 9/6/11 5:36 PM, gar...@th... wrote:
Hello there, thanks for this library tool!
Im trying to incorporate configobj-4.7.2 into an object
to read
configuration files with default values. The configobj can load the
configurationfile fine, but the configspec default values are not being
read in, and therefore validation fails.
not sure if my code is at fault.
What steps will reproduce the problem?
1.
Im loading code like this:
config = ConfigObj( infile=self.config_file,
configspec=self.config_spec,
encoding='latin-1',
create_empty=True,
unrepr=True,
stringify=True,
)
2.
my config_file looks like this:
[Environment]
name = 'qapod5'
services =
email =
deploy_sso =
3.
my configspec looks like this:
[Environment]
name = string()
services = list(default=list(''))
email = string(default="tes...@th..."
<mailto:tes...@th...> )
deploy_sso = boolean(default=False)
4. my validator code looks like this:
val = Validator()
test = self.config.validate(val, preserve_errors=True,
copy=True)
with the configspec above, i would expect that the
loaded configobj
would have the defaults after being validated with the Validator.
However, i get this error:
ValidateError: [([u'Environment'], 'deploy_sso',
VdtTypeError(u'the
value "" is of the wrong type.',)), ([u'Environment'], 'services',
VdtTypeError(u'the value "" is of the wrong type.',))]
Is my configspec not written properly?
Thanks,
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . .
Gary Siaw
Application Engineer, Paisley
Thomson Reuters
Phone: 763-450-4776
Fax: 763-450-4710
gar...@th...
paisley.thomsonreuters.com
------------------------------------------------------------------------
------
Malware Security Report: Protecting Your Business,
Customers, and the
Bottom Line. Protect your business and customers by
understanding the
threat from malware and how it can impact your online
business.
http://www.accelacomm.com/jaw/sfnl/114/51427462/
_______________________________________________
Configobj-develop mailing list
Con...@li...
https://lists.sourceforge.net/lists/listinfo/configobj-develop
------------------------------------------------------------------------
------
Malware Security Report: Protecting Your Business, Customers,
and the
Bottom Line. Protect your business and customers by
understanding the
threat from malware and how it can impact your online business.
http://www.accelacomm.com/jaw/sfnl/114/51427462/________________________
_______________________
Configobj-develop mailing list
Con...@li...
https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing
http://www.sqlite.org/different.html
------------------------------------------------------------------------
------
Malware Security Report: Protecting Your Business, Customers, and the
Bottom Line. Protect your business and customers by understanding the
threat from malware and how it can impact your online business.
http://www.accelacomm.com/jaw/sfnl/114/51427462/
_______________________________________________
Configobj-develop mailing list
Con...@li...
https://lists.sourceforge.net/lists/listinfo/configobj-develop
|
|
From: Chris S. <so...@st...> - 2011-09-06 23:23:33
|
Hi Gary,
Are you saying that you have inspected the Python object (self.config) and, after validation, it does not have those keys?
Or are you saying that you later call self.config.write() and those keys are not written out?
Those are two different things. If the Python object has those keys (which it should), the values will be the defaults.
Chris
On 9/6/11 7:13 PM, gar...@th... wrote:
> Thanks for the quick responses!
>
> Unfortunately, that is not what happens.
>
> If I remove the lines so that my config_file looks like this:
> [Environment]
> name = 'qapod5'
>
> and have the same configspec, the defaults are not put in.
>
>
>
>
> -----Original Message-----
> From: Michael Foord [mailto:fuz...@vo...]
> Sent: Tuesday, September 06, 2011 5:19 PM
> To: con...@li...
> Cc: Siaw, Gary (Professional)
> Subject: Re: [Configobj-develop] default values not being set with
> validation.
>
> Hey Gary,
>
> Chris is correct - those values are not "missing", they exist but are
> set to the empty string. Remove them and the validation defaults should
> be filled in. Alternatively write your own validation functions that
> interpret and empty value as missing and uses the default instead.
>
> The validate module documentation shows how to write validation
> functions.
>
> All the best,
>
> Michael
>
>
> On 6 Sep 2011, at 23:01, Chris Sontag wrote:
>> Hi Gary,
>>
>> I'm usually just a lurker on this list, but try taking "services" and
> "deploy_sso" out of your config file. Right now they are set to empty
> strings. If they come out, they will be filled with default values (in
> self.config) after your validate() call.
>
>> Chris
>>
>>
>> On 9/6/11 5:36 PM, gar...@th... wrote:
>>> Hello there, thanks for this library tool!
>>>
>>> Im trying to incorporate configobj-4.7.2 into an object to read
> configuration files with default values. The configobj can load the
> configurationfile fine, but the configspec default values are not being
> read in, and therefore validation fails.
>>> not sure if my code is at fault.
>>>
>>>
>>> What steps will reproduce the problem?
>>> 1.
>>> Im loading code like this:
>>> config = ConfigObj( infile=self.config_file,
>>> configspec=self.config_spec,
>>> encoding='latin-1',
>>> create_empty=True,
>>> unrepr=True,
>>> stringify=True,
>>> )
>>> 2.
>>> my config_file looks like this:
>>> [Environment]
>>> name = 'qapod5'
>>> services =
>>> email =
>>> deploy_sso =
>>>
>>> 3.
>>> my configspec looks like this:
>>> [Environment]
>>> name = string()
>>> services = list(default=list(''))
>>> email = string(default="tes...@th...")
>>> deploy_sso = boolean(default=False)
>>>
>>> 4. my validator code looks like this:
>>> val = Validator()
>>> test = self.config.validate(val, preserve_errors=True, copy=True)
>>>
>>>
>>> with the configspec above, i would expect that the loaded configobj
> would have the defaults after being validated with the Validator.
> However, i get this error:
>>>
>>> ValidateError: [([u'Environment'], 'deploy_sso', VdtTypeError(u'the
> value "" is of the wrong type.',)), ([u'Environment'], 'services',
> VdtTypeError(u'the value "" is of the wrong type.',))]
>>>
>>>
>>> Is my configspec not written properly?
>>>
>>> Thanks,
>>>
>>>
>>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> . . . . . . .
>>> Gary Siaw
>>> Application Engineer, Paisley
>>>
>>> Thomson Reuters
>>>
>>> Phone: 763-450-4776
>>> Fax: 763-450-4710
>>> gar...@th...
>>>
>>> paisley.thomsonreuters.com
>>>
>>>
>>>
>>>
> ------------------------------------------------------------------------
> ------
>>> Malware Security Report: Protecting Your Business, Customers, and the
>>> Bottom Line. Protect your business and customers by understanding the
>>> threat from malware and how it can impact your online business.
>>>
>>> http://www.accelacomm.com/jaw/sfnl/114/51427462/
>>>
>>>
>>> _______________________________________________
>>> Configobj-develop mailing list
>>>
>>> Con...@li...
>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
> ------------------------------------------------------------------------
> ------
>> Malware Security Report: Protecting Your Business, Customers, and the
>> Bottom Line. Protect your business and customers by understanding the
>> threat from malware and how it can impact your online business.
>>
> http://www.accelacomm.com/jaw/sfnl/114/51427462/________________________
> _______________________
>> Configobj-develop mailing list
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
> --
> http://www.voidspace.org.uk/
>
>
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
> -- the sqlite blessing
> http://www.sqlite.org/different.html
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Malware Security Report: Protecting Your Business, Customers, and the
> Bottom Line. Protect your business and customers by understanding the
> threat from malware and how it can impact your online business.
> http://www.accelacomm.com/jaw/sfnl/114/51427462/
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
|
|
From: <gar...@th...> - 2011-09-06 23:13:14
|
Thanks for the quick responses!
Unfortunately, that is not what happens.
If I remove the lines so that my config_file looks like this:
[Environment]
name = 'qapod5'
and have the same configspec, the defaults are not put in.
-----Original Message-----
From: Michael Foord [mailto:fuz...@vo...]
Sent: Tuesday, September 06, 2011 5:19 PM
To: con...@li...
Cc: Siaw, Gary (Professional)
Subject: Re: [Configobj-develop] default values not being set with
validation.
Hey Gary,
Chris is correct - those values are not "missing", they exist but are
set to the empty string. Remove them and the validation defaults should
be filled in. Alternatively write your own validation functions that
interpret and empty value as missing and uses the default instead.
The validate module documentation shows how to write validation
functions.
All the best,
Michael
On 6 Sep 2011, at 23:01, Chris Sontag wrote:
>
> Hi Gary,
>
> I'm usually just a lurker on this list, but try taking "services" and
"deploy_sso" out of your config file. Right now they are set to empty
strings. If they come out, they will be filled with default values (in
self.config) after your validate() call.
>
> Chris
>
>
> On 9/6/11 5:36 PM, gar...@th... wrote:
>> Hello there, thanks for this library tool!
>>
>> Im trying to incorporate configobj-4.7.2 into an object to read
configuration files with default values. The configobj can load the
configurationfile fine, but the configspec default values are not being
read in, and therefore validation fails.
>> not sure if my code is at fault.
>>
>>
>> What steps will reproduce the problem?
>> 1.
>> Im loading code like this:
>> config = ConfigObj( infile=self.config_file,
>> configspec=self.config_spec,
>> encoding='latin-1',
>> create_empty=True,
>> unrepr=True,
>> stringify=True,
>> )
>> 2.
>> my config_file looks like this:
>> [Environment]
>> name = 'qapod5'
>> services =
>> email =
>> deploy_sso =
>>
>> 3.
>> my configspec looks like this:
>> [Environment]
>> name = string()
>> services = list(default=list(''))
>> email = string(default="tes...@th...")
>> deploy_sso = boolean(default=False)
>>
>> 4. my validator code looks like this:
>> val = Validator()
>> test = self.config.validate(val, preserve_errors=True, copy=True)
>>
>>
>> with the configspec above, i would expect that the loaded configobj
would have the defaults after being validated with the Validator.
However, i get this error:
>>
>> ValidateError: [([u'Environment'], 'deploy_sso', VdtTypeError(u'the
value "" is of the wrong type.',)), ([u'Environment'], 'services',
VdtTypeError(u'the value "" is of the wrong type.',))]
>>
>>
>> Is my configspec not written properly?
>>
>> Thanks,
>>
>>
>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . .
>> Gary Siaw
>> Application Engineer, Paisley
>>
>> Thomson Reuters
>>
>> Phone: 763-450-4776
>> Fax: 763-450-4710
>> gar...@th...
>>
>> paisley.thomsonreuters.com
>>
>>
>>
>>
------------------------------------------------------------------------
------
>> Malware Security Report: Protecting Your Business, Customers, and the
>> Bottom Line. Protect your business and customers by understanding the
>> threat from malware and how it can impact your online business.
>>
>> http://www.accelacomm.com/jaw/sfnl/114/51427462/
>>
>>
>> _______________________________________________
>> Configobj-develop mailing list
>>
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
------------------------------------------------------------------------
------
> Malware Security Report: Protecting Your Business, Customers, and the
> Bottom Line. Protect your business and customers by understanding the
> threat from malware and how it can impact your online business.
>
http://www.accelacomm.com/jaw/sfnl/114/51427462/________________________
_______________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing
http://www.sqlite.org/different.html
|
|
From: Michael F. <fuz...@vo...> - 2011-09-06 22:18:54
|
Hey Gary,
Chris is correct - those values are not "missing", they exist but are set to the empty string. Remove them and the validation defaults should be filled in. Alternatively write your own validation functions that interpret and empty value as missing and uses the default instead.
The validate module documentation shows how to write validation functions.
All the best,
Michael
On 6 Sep 2011, at 23:01, Chris Sontag wrote:
>
> Hi Gary,
>
> I'm usually just a lurker on this list, but try taking "services" and "deploy_sso" out of your config file. Right now they are set to empty strings. If they come out, they will be filled with default values (in self.config) after your validate() call.
>
> Chris
>
>
> On 9/6/11 5:36 PM, gar...@th... wrote:
>> Hello there, thanks for this library tool!
>>
>> Im trying to incorporate configobj-4.7.2 into an object to read configuration files with default values. The configobj can load the configurationfile fine, but the configspec default values are not being read in, and therefore validation fails.
>> not sure if my code is at fault.
>>
>>
>> What steps will reproduce the problem?
>> 1.
>> Im loading code like this:
>> config = ConfigObj( infile=self.config_file,
>> configspec=self.config_spec,
>> encoding='latin-1',
>> create_empty=True,
>> unrepr=True,
>> stringify=True,
>> )
>> 2.
>> my config_file looks like this:
>> [Environment]
>> name = 'qapod5'
>> services =
>> email =
>> deploy_sso =
>>
>> 3.
>> my configspec looks like this:
>> [Environment]
>> name = string()
>> services = list(default=list(''))
>> email = string(default="tes...@th...")
>> deploy_sso = boolean(default=False)
>>
>> 4. my validator code looks like this:
>> val = Validator()
>> test = self.config.validate(val, preserve_errors=True, copy=True)
>>
>>
>> with the configspec above, i would expect that the loaded configobj would have the defaults after being validated with the Validator. However, i get this error:
>>
>> ValidateError: [([u'Environment'], 'deploy_sso', VdtTypeError(u'the value "" is of the wrong type.',)), ([u'Environment'], 'services', VdtTypeError(u'the value "" is of the wrong type.',))]
>>
>>
>> Is my configspec not written properly?
>>
>> Thanks,
>>
>>
>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>> Gary Siaw
>> Application Engineer, Paisley
>>
>> Thomson Reuters
>>
>> Phone: 763-450-4776
>> Fax: 763-450-4710
>> gar...@th...
>>
>> paisley.thomsonreuters.com
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Malware Security Report: Protecting Your Business, Customers, and the
>> Bottom Line. Protect your business and customers by understanding the
>> threat from malware and how it can impact your online business.
>>
>> http://www.accelacomm.com/jaw/sfnl/114/51427462/
>>
>>
>> _______________________________________________
>> Configobj-develop mailing list
>>
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
> ------------------------------------------------------------------------------
> Malware Security Report: Protecting Your Business, Customers, and the
> Bottom Line. Protect your business and customers by understanding the
> threat from malware and how it can impact your online business.
> http://www.accelacomm.com/jaw/sfnl/114/51427462/_______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing
http://www.sqlite.org/different.html
|
|
From: Chris S. <so...@st...> - 2011-09-06 22:05:57
|
Hi Gary,
I'm usually just a lurker on this list, but try taking "services" and "deploy_sso" out of your config file. Right now they are set to empty strings. If they come out, they will be filled with default values (in self.config) after your validate() call.
Chris
On 9/6/11 5:36 PM, gar...@th... wrote:
>
> Hello there, thanks for this library tool!
>
> Im trying to incorporate configobj-4.7.2 into an object to read configuration files with default values. The configobj can load the configurationfile fine, but the configspec default values are not being read in, and therefore validation fails.
>
> not sure if my code is at fault.
>
> What steps will reproduce the problem?
>
> 1.
>
> Im loading code like this:
>
> config = ConfigObj( infile=self.config_file,
>
> configspec=self.config_spec,
>
> encoding='latin-1',
>
> create_empty=True,
>
> unrepr=True,
>
> stringify=True,
>
> )
>
> 2.
>
> my config_file looks like this:
>
> [Environment]
>
> name = 'qapod5'
>
> services =
>
> email =
>
> deploy_sso =
>
> 3.
>
> my configspec looks like this:
>
> [Environment]
>
> name = string()
>
> services = list(default=list(''))
>
> email = string(default="tes...@th...")
>
> deploy_sso = boolean(default=False)
>
> 4. my validator code looks like this:
>
> val = Validator()
>
> test = self.config.validate(val, preserve_errors=True,copy=True)
>
> with the configspec above, i would expect that the loaded configobj would have the defaults after being validated with the Validator. However, i get this error:
>
> ValidateError: [([u'Environment'], 'deploy_sso', VdtTypeError(u'the value "" is of the wrong type.',)), ([u'Environment'], 'services', VdtTypeError(u'the value "" is of the wrong type.',))]
>
> Is my configspec not written properly?
>
> Thanks,
>
> **
>
> *. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .****. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*
> *Gary Siaw *
> Application Engineer, Paisley
>
>
> *Thomson Reuters <thomsonreuters.com>***
>
>
> Phone: 763-450-4776
> Fax: 763-450-4710
> gar...@th... <mailto:gar...@th...>
>
> paisley.thomsonreuters.com
>
>
>
> ------------------------------------------------------------------------------
> Malware Security Report: Protecting Your Business, Customers, and the
> Bottom Line. Protect your business and customers by understanding the
> threat from malware and how it can impact your online business.
> http://www.accelacomm.com/jaw/sfnl/114/51427462/
>
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
|
|
From: <gar...@th...> - 2011-09-06 21:53:07
|
Hello there, thanks for this library tool!
Im trying to incorporate configobj-4.7.2 into an object to read
configuration files with default values. The configobj can load the
configurationfile fine, but the configspec default values are not being
read in, and therefore validation fails.
not sure if my code is at fault.
What steps will reproduce the problem?
1.
Im loading code like this:
config = ConfigObj( infile=self.config_file,
configspec=self.config_spec,
encoding='latin-1',
create_empty=True,
unrepr=True,
stringify=True,
)
2.
my config_file looks like this:
[Environment]
name = 'qapod5'
services =
email =
deploy_sso =
3.
my configspec looks like this:
[Environment]
name = string()
services = list(default=list(''))
email = string(default="tes...@th...")
deploy_sso = boolean(default=False)
4. my validator code looks like this:
val = Validator()
test = self.config.validate(val, preserve_errors=True, copy=True)
with the configspec above, i would expect that the loaded configobj
would have the defaults after being validated with the Validator.
However, i get this error:
ValidateError: [([u'Environment'], 'deploy_sso', VdtTypeError(u'the
value "" is of the wrong type.',)), ([u'Environment'], 'services',
VdtTypeError(u'the value "" is of the wrong type.',))]
Is my configspec not written properly?
Thanks,
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . .
Gary Siaw
Application Engineer, Paisley
Thomson Reuters
Phone: 763-450-4776
Fax: 763-450-4710
gar...@th... <mailto:gar...@th...>
paisley.thomsonreuters.com
|
|
From: Michael F. <fuz...@vo...> - 2011-09-01 14:03:05
|
On 01/09/2011 14:43, Whitaker, Maria - BLS wrote: > > Thanks. > You have to do it yourself, using the same way you signed up for the list. See the link at the bottom of each email from the list. All the best, Michael Foord > > > ------------------------------------------------------------------------------ > Special Offer -- Download ArcSight Logger for FREE! > Finally, a world-class log management solution at an even better > price-free! And you'll get a free "Love Thy Logs" t-shirt when you > download Logger. Secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsisghtdev2dev > > > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html |
|
From: Whitaker, M. - B. <Whi...@BL...> - 2011-09-01 13:43:56
|
Thanks. |
|
From: Michael F. <fuz...@vo...> - 2011-09-01 10:24:54
|
On 30/08/2011 20:26, Entityreborn wrote: > As opposed to setting your template for validation via a seperate file, can this be done by providing the validator class with a string? You can read a configspec file manually (e.g. from a list of strings or a StringIO instance). You must create the ConfigObj using the arguments "_inspec=True" and "list_values=False". (This is because configspecs have a different syntax to config files, so you need to turn off parts of the parser in ConfigObj.) All the best, Michael > > ------------------------------------------------------------------------------ > Special Offer -- Download ArcSight Logger for FREE! > Finally, a world-class log management solution at an even better > price-free! And you'll get a free "Love Thy Logs" t-shirt when you > download Logger. Secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsisghtdev2dev > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html |
|
From: Entity R. <ent...@gm...> - 2011-08-30 21:18:47
|
>
> *import StringIO*
>
> *
>> *
>
> *from configobj import ConfigObj, flatten_errors*
>
> *from validate import Validator*
>
> *
>> *
>
> *def validateConfig(config):*
>
> * validator = Validator()*
>
> * haserrors = config.validate(validator, preserve_errors=True)*
>
> * errors = []*
>
> * if haserrors is True:*
>
> * for (section_list, key, exc) in flatten_errors(config,
>> haserrors):*
>
> * if key is not None:*
>
> * errors.append('\t"%s" in "%s" failed validation. (%s)' %
>> (key, ', '.join(section_list), exc))*
>
> * else:*
>
> * errors.append('\tThe following sections were missing:%s '
>> % ', '.join(section_list))*
>
> *
>> *
>
> * return errors*
>
> *
>> *
>
> *def loadConfig(filename, validatefile, path="."):*
>
> * config = ConfigObj("%s/%s"%(path, filename),*
>
> * configspec=validatefile)*
>
> *
>> *
>
> * invalid = validateConfig(config)*
>
> * if invalid:*
>
> * return False*
>
> *
>> *
>
> * return config*
>
> *
>> *
>
> *# config file:*
>
> *# [general]*
>
> *# test = abcd*
>
> *
>> *
>
> *s = StringIO.StringIO()*
>
> *s.write("""*
>
> *[general]*
>
> *test = integer()*
>
> *""")*
>
> *
>> *
>
> *conf = loadConfig("config.conf", s)*
>
> *
>> *
>
> *errors = validateConfig(conf)*
>
> *print errors # should print something :(*
>
> *print conf*
>
>
> This doesn't seem to work :/
Output:
> *[]
> {'general': {'test': 'abcd'}} *
On Tue, Aug 30, 2011 at 12:39 PM, David Hostetler <neg...@gm...>wrote:
> Try StringIO.
>
>
> -hoss
>
>
>
> On Tue, Aug 30, 2011 at 15:26, Entityreborn <ent...@gm...>wrote:
>
>>
>> As opposed to setting your template for validation via a seperate file,
>> can this be done by providing the validator class with a string?
>>
>>
>> ------------------------------------------------------------------------------
>> Special Offer -- Download ArcSight Logger for FREE!
>> Finally, a world-class log management solution at an even better
>> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
>> download Logger. Secure your free ArcSight Logger TODAY!
>> http://p.sf.net/sfu/arcsisghtdev2dev
>> _______________________________________________
>> Configobj-develop mailing list
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>
>
>
>
> ------------------------------------------------------------------------------
> Special Offer -- Download ArcSight Logger for FREE!
> Finally, a world-class log management solution at an even better
> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
> download Logger. Secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsisghtdev2dev
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
--
~EntityReborn
|
|
From: David H. <neg...@gm...> - 2011-08-30 19:39:51
|
Try StringIO. -hoss On Tue, Aug 30, 2011 at 15:26, Entityreborn <ent...@gm...> wrote: > > As opposed to setting your template for validation via a seperate file, can > this be done by providing the validator class with a string? > > > ------------------------------------------------------------------------------ > Special Offer -- Download ArcSight Logger for FREE! > Finally, a world-class log management solution at an even better > price-free! And you'll get a free "Love Thy Logs" t-shirt when you > download Logger. Secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsisghtdev2dev > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: Entityreborn <ent...@gm...> - 2011-08-30 19:26:13
|
As opposed to setting your template for validation via a seperate file, can this be done by providing the validator class with a string? |