|
From: Fuzzyman <fuz...@vo...> - 2006-01-30 09:39:19
|
Hello all,
I'm working on some changes to ConfigObj that add new functionality.
These add some of the ``get`` type methods from ConfigParser to
ConfigObj, as well as full unicode support.
Both are *relatively* easy and will become ConfigObj 4.2.0. (I may well
do a beta release first.)
There is a question about the method signature for the get methods. The
ConfigParser methods are :
get( section, option)
Get an option value for the named section.
getint( section, option)
A convenience method which coerces the option in the specified
section to an integer.
getfloat( section, option)
A convenience method which coerces the option in the specified
section to a floating point number.
getboolean( section, option)
A convenience method which coerces the option in the specified
section to a Boolean value. Note that the accepted values for
the option are "1", "yes", "true", and "on", which cause this
method to return True, and "0", "no", "false", and "off", which cause it
to return False. These string values are checked in a
case-insensitive manner. Any other value will cause it to raise
ValueError.
I *won't* implement get because it clashes with a dictionary method. If
I implement the ``ConfigParser`` compatibility layer then that will
change (but be on a subclass).
My intention is to make these methods *section* methods, so they are
available on all subsections, and to keep the ConfigParser method
signature. For values *not* in a subsection, this leads to the slightly
awkward syntax :
cfg = ConfigObj(cfg_file)
val = cfg.getboolean(None, 'key')
The alternatives are :
* To reverse the order of the arguments, with section defaulting to
None. This leads to confusion in the (theoretical) ConfigParser
compatibility layer, which will of course be reversed back. It is
*slightly* more friendly for normal use though.
* To make it a method on ConfigObj (*not* sections) and allow section to
be a string *or* a reference to a subsection - in which case the
specified key would be taken from that.
Should I then remove ``istrue`` (added in 4.1.0) which is effectively
the same as ``getboolean`` ? I would deprecate it and add a warning
until 4.3.0.
The unicode changes are reasonably straightforward. I'll re-implement
the system used in ConfigObj 3. (Unless anyone raises any objections or
suggests an alternative).
You will be able to pass in an (optional) 'encoding' keyword. If
present, this will be used to decode the input. This maps to an
'encoding' attribute which will be used used to encode when writing (and
can obviously be changed).
There will also be a 'default_encoding' keyword/attribute to override
the system default encoding. This is used (to decode) any values that
are byte-strings. These need to be turned into unicode prior to writing
out in the specified output encoding.
If encoding is None (the default) then no encoding or decoding is
explicitly done. This means the default behaviour for ConfigObj is
completely unchanged.
Opinions/responses solicited.
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/configobj.html
|
|
From: Michael F. <fuz...@vo...> - 2008-01-13 00:51:39
|
Hello guys, I have finally got around to giving ConfigObj some love. http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920 Things I will be looking at include: * Guaranteeing that written config files are newline terminated * Quoting keys, values and list members that contain hashes * Review a patch that adds a restore_defaults method * Evaluating how difficult adding a reload method would be * A couple of bugfixes to the validate module If there are any other (small!) things to look at then speak up now. For larger changes the 'patches welcome' rule applies I'm afraid. Michael http://www.manning.com/foord |
|
From: Arve K. <arv...@gm...> - 2008-01-13 12:16:39
|
Hiya Michael Will you be fixing the problem I reported a while back, where configuration fields declared to be lists, in the specification, can be interpreted as strings (if you forget to end with a ',')? Arve On 1/13/08, Michael Foord <fuz...@vo...> wrote: > > Hello guys, > > I have finally got around to giving ConfigObj some love. > > http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920 > > Things I will be looking at include: > > * Guaranteeing that written config files are newline terminated > * Quoting keys, values and list members that contain hashes > * Review a patch that adds a restore_defaults method > * Evaluating how difficult adding a reload method would be > * A couple of bugfixes to the validate module > > If there are any other (small!) things to look at then speak up now. For > larger changes the 'patches welcome' rule applies I'm afraid. > > Michael > http://www.manning.com/foord > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: Michael F. <fuz...@vo...> - 2008-01-13 12:56:17
|
Arve Knudsen wrote: > Hiya Michael > > Will you be fixing the problem I reported a while back, where > configuration fields declared to be lists, in the specification, can > be interpreted as strings (if you forget to end with a ',')? That's one of the validate issues that I will be looking at. Michael > > Arve > > On 1/13/08, *Michael Foord* <fuz...@vo... > <mailto:fuz...@vo...>> wrote: > > Hello guys, > > I have finally got around to giving ConfigObj some love. > > http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920 > <http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920> > > Things I will be looking at include: > > * Guaranteeing that written config files are newline terminated > * Quoting keys, values and list members that contain hashes > * Review a patch that adds a restore_defaults method > * Evaluating how difficult adding a reload method would be > * A couple of bugfixes to the validate module > > If there are any other (small!) things to look at then speak up > now. For > larger changes the 'patches welcome' rule applies I'm afraid. > > Michael > http://www.manning.com/foord > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > <http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace> > _______________________________________________ > Configobj-develop mailing list > Con...@li... > <mailto:Con...@li...> > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > ------------------------------------------------------------------------ > > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: Arve K. <arv...@gm...> - 2008-01-13 13:08:30
|
On 1/13/08, Michael Foord <fuz...@vo...> wrote: > > Arve Knudsen wrote: > > Hiya Michael > > > > Will you be fixing the problem I reported a while back, where > > configuration fields declared to be lists, in the specification, can > > be interpreted as strings (if you forget to end with a ',')? > That's one of the validate issues that I will be looking at. Great. Arve Michael > > > > > > Arve > > > > On 1/13/08, *Michael Foord* <fuz...@vo... > > <mailto:fuz...@vo...>> wrote: > > > > Hello guys, > > > > I have finally got around to giving ConfigObj some love. > > > > > http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920 > > < > http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920> > > > > Things I will be looking at include: > > > > * Guaranteeing that written config files are newline terminated > > * Quoting keys, values and list members that contain hashes > > * Review a patch that adds a restore_defaults method > > * Evaluating how difficult adding a reload method would be > > * A couple of bugfixes to the validate module > > > > If there are any other (small!) things to look at then speak up > > now. For > > larger changes the 'patches welcome' rule applies I'm afraid. > > > > Michael > > http://www.manning.com/foord > > > > > > > ------------------------------------------------------------------------- > > Check out the new SourceForge.net Marketplace. > > It's the best place to buy or sell services for > > just about anything Open Source. > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > < > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > > > _______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > <mailto:Con...@li...> > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------- > > Check out the new SourceForge.net Marketplace. > > It's the best place to buy or sell services for > > just about anything Open Source. > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: Arve K. <arv...@gm...> - 2008-01-13 16:01:31
Attachments:
defaults-v2.patch
|
I have another patch for you, apply this on top of my previous patch. This updates documentation, and renames the method I added to Validator to check_default, since I found this better reflects its relation to the check method. Arve On Jan 13, 2008 2:08 PM, Arve Knudsen <arv...@gm...> wrote: > On 1/13/08, Michael Foord <fuz...@vo...> wrote: > > > Arve Knudsen wrote: > > > Hiya Michael > > > > > > Will you be fixing the problem I reported a while back, where > > > configuration fields declared to be lists, in the specification, can > > > be interpreted as strings (if you forget to end with a ',')? > > That's one of the validate issues that I will be looking at. > > > Great. > > Arve > > > Michael > > > > > > > > > > Arve > > > > > > On 1/13/08, *Michael Foord* <fuz...@vo... > > > <mailto: fuz...@vo... >> wrote: > > > > > > Hello guys, > > > > > > I have finally got around to giving ConfigObj some love. > > > > > > > > http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920 > > > <http://www.voidspace.org.uk/python/weblog/arch_d7_2008_01_12.shtml#e920 > > > > > > > > > Things I will be looking at include: > > > > > > * Guaranteeing that written config files are newline > > terminated > > > * Quoting keys, values and list members that contain hashes > > > * Review a patch that adds a restore_defaults method > > > * Evaluating how difficult adding a reload method would be > > > * A couple of bugfixes to the validate module > > > > > > If there are any other (small!) things to look at then speak up > > > now. For > > > larger changes the 'patches welcome' rule applies I'm afraid. > > > > > > Michael > > > http://www.manning.com/foord > > > > > > > > > > > ------------------------------------------------------------------------- > > > Check out the new SourceForge.net Marketplace. > > > It's the best place to buy or sell services for > > > just about anything Open Source. > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > > > > < > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > > > > > _______________________________________________ > > > Configobj-develop mailing list > > > Con...@li... > > > <mailto: Con...@li...> > > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > ------------------------------------------------------------------------- > > > Check out the new SourceForge.net Marketplace. > > > It's the best place to buy or sell services for > > > just about anything Open Source. > > > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Configobj-develop mailing list > > > Con...@li... > > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > > > > > > ------------------------------------------------------------------------- > > > > Check out the new SourceForge.net Marketplace. > > It's the best place to buy or sell services for > > just about anything Open Source. > > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > _______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > |
|
From: Nicola L. <ni...@te...> - 2008-01-13 17:36:56
|
Michael Foord wrote: > If there are any other (small!) things to look at then speak up now. For > larger changes the 'patches welcome' rule applies I'm afraid. I've been sitting on a bug report about newlines on Windows for some time (sorry). It's in Italian, I'll translate it and send it here soon. -- Nicola Larosa - http://www.tekNico.net/ Just as a painter starts from a black canvas, a musician should start from silence; and one of our most essential skills is the ability to simply shut up and listen. -- Joe Jackson, A Cure for Gravity, 1999 |
|
From: Michael F. <fuz...@vo...> - 2008-01-13 18:12:25
|
Nicola Larosa wrote: > Michael Foord wrote: > >> If there are any other (small!) things to look at then speak up now. For >> larger changes the 'patches welcome' rule applies I'm afraid. >> > > I've been sitting on a bug report about newlines on Windows for some time > (sorry). It's in Italian, I'll translate it and send it here soon. > > Ok - cool. But how many problems with newlines can there *be*? :-) Michael |
|
From: Nicola L. <ni...@te...> - 2008-01-21 05:25:09
|
> Nicola Larosa wrote:
>> I've been sitting on a bug report about newlines on Windows for some time
>> (sorry). It's in Italian, I'll translate it and send it here soon.
Michael Foord wrote:
> Ok - cool. But how many problems with newlines can there *be*? :-)
That one, I'm not qualified to answer. ;-) Bug report follows.
---
When creating a ConfigObj, there's some code that tries to detect what
kind of newline is used in the input file, in order to use the same kind
when the ConfigObj is saved.
Now, in the "write" method the output file is open as binary, for
encoding reasons:
Lines from 1848 to 1050:
h = open(self.filename, 'wb')
h.write(output)
h.close()
and the lines are added to the output buffer appending to each one the
self.newlines character, the one detected in the constructor (one among
"\n", "\r" and "\r\n").
The problem is that in all systems the output newline character in
self.newlines will always be "\n", because the input file "infile",
passed in the constructor, is open in text mode, therefore the newline
characters it contains will already have been converted to "\n":
Lines 1022 and 1023:
if os.path.isfile(infile):
infile = open(infile).read() or []
So, I changed those two lines to:
if os.path.isfile(infile):
infile = open(infile,"rb").read() or []
That way, the input file too is open in binary mode, and the newline
character put into self.newlines is the actually used one.
All of that because on windows [lowercased in the original ;-) ], when a
ConfigObj is written to file, the newline characters were shown as "\n",
that in notepad are seen as annoying little boxes. :-)
---
I hope it's useful.
--
Nicola Larosa - http://www.tekNico.net/
I was a pilgrim, dedicated to the service of something larger than
myself, something that transcended the mundane material world,
something that could still fill me with awe. Music was my Christ on
the cross, my Wailing Wall, my Mecca. A universe in which music
existed could not be evil. -- Joe Jackson, A Cure for Gravity, 1999
|
|
From: Nicola L. <ni...@te...> - 2006-01-30 14:38:45
|
> I *won't* implement get because it clashes with a dictionary method. If > I implement the ``ConfigParser`` compatibility layer then that will > change (but be on a subclass). OK. > My intention is to make these methods *section* methods, so they are > available on all subsections, and to keep the ConfigParser method > signature. For values *not* in a subsection, this leads to the slightly > awkward syntax : > > cfg = ConfigObj(cfg_file) > val = cfg.getboolean(None, 'key') There's no explicit outer section, so None is an appropriate value, if a bit quirky. > The alternatives are : > > * To reverse the order of the arguments, with section defaulting to > None. This leads to confusion in the (theoretical) ConfigParser > compatibility layer, which will of course be reversed back. It is > *slightly* more friendly for normal use though. I don't like it, equivalent APIs should be consistent, otherwise it's like setting up traps for the unwary user, > * To make it a method on ConfigObj (*not* sections) and allow section to > be a string *or* a reference to a subsection - in which case the > specified key would be taken from that. How would you specify nested sections in a string? Dotted notation? Section names are not restricted to Python identifier syntax, right? Anyway, having methods on section objects seems more versatile. > Should I then remove ``istrue`` (added in 4.1.0) which is effectively > the same as ``getboolean`` ? I would deprecate it and add a warning > until 4.3.0. Yes, better avoid multiple ways of doing the same thing, especially if it's a recent thing. > The unicode changes are reasonably straightforward. I'll re-implement > the system used in ConfigObj 3. (Unless anyone raises any objections or > suggests an alternative). > > You will be able to pass in an (optional) 'encoding' keyword. If > present, this will be used to decode the input. This maps to an > 'encoding' attribute which will be used used to encode when writing (and > can obviously be changed). > > There will also be a 'default_encoding' keyword/attribute to override > the system default encoding. This is used (to decode) any values that > are byte-strings. These need to be turned into unicode prior to writing > out in the specified output encoding. > > If encoding is None (the default) then no encoding or decoding is > explicitly done. This means the default behaviour for ConfigObj is > completely unchanged. Sounds reasonable. -- Nicola Larosa - http://www.tekNico.net/ People just don't want to be pestered - they want shit to happen without being bugged. If technology is to help, it must be seren- dipitous rather than strident. -- Nathan Torkington, November 2005 |
|
From: Fuzzyman <fuz...@vo...> - 2006-01-30 14:45:44
|
Nicola Larosa wrote: > [snip..] >> * To make it a method on ConfigObj (*not* sections) and allow section to >> be a string *or* a reference to a subsection - in which case the >> specified key would be taken from that. >> > > How would you specify nested sections in a string? Dotted notation? Section > names are not restricted to Python identifier syntax, right? Anyway, having > methods on section objects seems more versatile. > > It sounds like a section method with ``None`` for the section (if not referencing a key in a sub-section) is the way. (Consider it decided unless someone shouts.) *However*, what I meant here is that you pass in a string to specify a section one level down. To specify a nested section you pass in a *reference* to the section - not a string at all. I don't come from a static language background, so I'm agnostic about arguments that can be of more than one type. In some circles I believe this is frowned upon as bad practise... > >> Should I then remove ``istrue`` (added in 4.1.0) which is effectively >> the same as ``getboolean`` ? I would deprecate it and add a warning >> until 4.3.0. >> > > Yes, better avoid multiple ways of doing the same thing, especially if it's > a recent thing. > > Cool - I added it in 4.1.0, but ``getboolean`` is better anyway. Thanks |
|
From: Fuzzyman <fuz...@vo...> - 2006-01-30 16:12:54
|
Aaron Bentley wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Fuzzyman wrote:
>
>> * To reverse the order of the arguments, with section defaulting to
>> None. This leads to confusion in the (theoretical) ConfigParser
>> compatibility layer, which will of course be reversed back. It is
>> *slightly* more friendly for normal use though.
>>
>
> For values in a subsection, we'd also be able to do:
> val=cfg['subsection'].getboolean('key'), right? That's more in keeping
> with your existing UI. Perhaps you'd prefer to use different names from
> the ConfigParser ones. ('asbool', 'asfloat'?)
>
>
I'm copying this to the configobj-develop mailing list because I value
Nicola's input on this. Perhaps you'd consider joining the list Aaron
(low traffic - via sourceforge).
I am going to implement these as section methods. My initial idea was to
implement them using the ConfigParser names and syntax. This means you
would have to specify a subsection, but could specify None to get values
in the section you are calling from.
In order to avoid this there are three (reasonable) options :
1) Implement ``asbool`` *and* ``getbool`` methods - ``getbool``
following ConfigParser signature.
2) Just implement ``asbool`` and leave ``getbool`` for a ConfigParser
compatibility layer - if it ever happens.
3) Implement ``getbool`` but make the second argument optional (by
having None as the default). If no second argument is specified, treat
the first argument as a key *not* a section...
I have a mild preference for 2) but quite like 3). 3) is weird because
it changes the meaning of the first argument *if* you provide a second...
Opinions please...
> I don't think we'll be exposing ConfigObj directly, so I don't think
> this is a big deal for us, either way.
>
>
>> Should I then remove ``istrue`` (added in 4.1.0) which is effectively
>> the same as ``getboolean`` ? I would deprecate it and add a warning
>> until 4.3.0.
>>
>
> I have no personal stake in istrue.
>
>
Don't start using it then. :-)
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
|
|
From: Fuzzyman <fuz...@vo...> - 2006-01-30 20:24:33
|
Fuzzyman wrote:
> Aaron Bentley wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Fuzzyman wrote:
>>
>>> * To reverse the order of the arguments, with section defaulting to
>>> None. This leads to confusion in the (theoretical) ConfigParser
>>> compatibility layer, which will of course be reversed back. It is
>>> *slightly* more friendly for normal use though.
>>>
>>
>> For values in a subsection, we'd also be able to do:
>> val=cfg['subsection'].getboolean('key'), right? That's more in keeping
>> with your existing UI. Perhaps you'd prefer to use different names from
>> the ConfigParser ones. ('asbool', 'asfloat'?)
>>
>>
> I'm copying this to the configobj-develop mailing list because I value
> Nicola's input on this. Perhaps you'd consider joining the list Aaron
> (low traffic - via sourceforge).
>
> I am going to implement these as section methods. My initial idea was
> to implement them using the ConfigParser names and syntax. This means
> you would have to specify a subsection, but could specify None to get
> values in the section you are calling from.
>
> In order to avoid this there are three (reasonable) options :
>
> 1) Implement ``asbool`` *and* ``getbool`` methods - ``getbool``
> following ConfigParser signature.
> 2) Just implement ``asbool`` and leave ``getbool`` for a ConfigParser
> compatibility layer - if it ever happens.
> 3) Implement ``getbool`` but make the second argument optional (by
> having None as the default). If no second argument is specified, treat
> the first argument as a key *not* a section...
>
> I have a mild preference for 2) but quite like 3). 3) is weird because
> it changes the meaning of the first argument *if* you provide a second...
>
> Opinions please...
>
Actually I like 3. It keeps compatibility with ConfigParser (benefit of
familiarity), and achieves both aims.
If you supply one argument it's a key, if you supply two they are
``section, key``.
Oh, except it's ``getboolean`` not ``getbool``. :-)
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
>> I don't think we'll be exposing ConfigObj directly, so I don't think
>> this is a big deal for us, either way.
>>
>>
>>> Should I then remove ``istrue`` (added in 4.1.0) which is effectively
>>> the same as ``getboolean`` ? I would deprecate it and add a warning
>>> until 4.3.0.
>>>
>>
>> I have no personal stake in istrue.
>>
>>
> Don't start using it then. :-)
>
> All the best,
>
> Fuzzyman
> http://www.voidspace.org.uk/python/index.shtml
|
|
From: Nicola L. <ni...@te...> - 2006-01-30 20:57:22
|
>> I am going to implement these as section methods. My initial idea was >> to implement them using the ConfigParser names and syntax. This means >> you would have to specify a subsection, but could specify None to get >> values in the section you are calling from. >> >> In order to avoid this there are three (reasonable) options : >> >> 1) Implement ``asbool`` *and* ``getbool`` methods - ``getbool`` >> following ConfigParser signature. >> 2) Just implement ``asbool`` and leave ``getbool`` for a ConfigParser >> compatibility layer - if it ever happens. >> 3) Implement ``getbool`` but make the second argument optional (by >> having None as the default). If no second argument is specified, treat >> the first argument as a key *not* a section... >> >> I have a mild preference for 2) but quite like 3). 3) is weird because >> it changes the meaning of the first argument *if* you provide a second... >> >> Opinions please... > Actually I like 3. It keeps compatibility with ConfigParser (benefit of > familiarity), and achieves both aims. > > If you supply one argument it's a key, if you supply two they are > ``section, key``. > > Oh, except it's ``getboolean`` not ``getbool``. :-) I think I'll disagree here. I concur that having to specify None for no subsection is a bit inconvenient. However, breaking the rule that optional parameters should be last in the signature is worse, IMO. I seem to recall a couple such cases in the standard library, and they feel out of place and inconsistent with the rest. Moreover, with option 3) you're not really compatible with ConfigParser anymore, since you changed the signature, by allowing one to use just one param. That may cause surprises in case of mistakes. Maybe it would be better to have separate methods with just one param, and that would be option 1), if I'm not mistaken. -- Nicola Larosa - http://www.tekNico.net/ People just don't want to be pestered - they want shit to happen without being bugged. If technology is to help, it must be seren- dipitous rather than strident. -- Nathan Torkington, November 2005 |
|
From: Fuzzyman <fuz...@vo...> - 2006-01-30 21:10:10
|
Nicola Larosa wrote: >>> I am going to implement these as section methods. My initial idea was >>> to implement them using the ConfigParser names and syntax. This means >>> you would have to specify a subsection, but could specify None to get >>> values in the section you are calling from. >>> >>> In order to avoid this there are three (reasonable) options : >>> >>> 1) Implement ``asbool`` *and* ``getbool`` methods - ``getbool`` >>> following ConfigParser signature. >>> 2) Just implement ``asbool`` and leave ``getbool`` for a ConfigParser >>> compatibility layer - if it ever happens. >>> 3) Implement ``getbool`` but make the second argument optional (by >>> having None as the default). If no second argument is specified, treat >>> the first argument as a key *not* a section... >>> >>> I have a mild preference for 2) but quite like 3). 3) is weird because >>> it changes the meaning of the first argument *if* you provide a second... >>> >>> Opinions please... >>> > > >> Actually I like 3. It keeps compatibility with ConfigParser (benefit of >> familiarity), and achieves both aims. >> >> If you supply one argument it's a key, if you supply two they are >> ``section, key``. >> >> Oh, except it's ``getboolean`` not ``getbool``. :-) >> > > I think I'll disagree here. I concur that having to specify None for no > subsection is a bit inconvenient. However, breaking the rule that optional > parameters should be last in the signature is worse, IMO. I seem to recall > a couple such cases in the standard library, and they feel out of place and > inconsistent with the rest. > > Moreover, with option 3) you're not really compatible with ConfigParser > anymore, since you changed the signature, by allowing one to use just one > param. That may cause surprises in case of mistakes. > > Maybe it would be better to have separate methods with just one param, and > that would be option 1), if I'm not mistaken. > > I can see your point. *However* there is a current discussion of ConfigObj going on in python-dev. Ian Bicking mentions about having *too much* in the API. Implementing two means of doing similar things seems like overkill. Do you greatly prefer ``getboolean`` (allowing but requiring you to specify a sub-section) to ``asboolean`` (not requiring or allowing you to specify a sub-section) ? Just implementing ``asboolean`` leaves the way open for ``getboolean`` in a subclass (implementation of either is trivial). All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml |
|
From: Nicola L. <ni...@te...> - 2006-01-30 21:25:09
|
>> I think I'll disagree here. I concur that having to specify None for no >> subsection is a bit inconvenient. However, breaking the rule that optional >> parameters should be last in the signature is worse, IMO. I seem to recall >> a couple such cases in the standard library, and they feel out of place and >> inconsistent with the rest. >> >> Moreover, with option 3) you're not really compatible with ConfigParser >> anymore, since you changed the signature, by allowing one to use just one >> param. That may cause surprises in case of mistakes. >> >> Maybe it would be better to have separate methods with just one param, and >> that would be option 1), if I'm not mistaken. > I can see your point. > > *However* there is a current discussion of ConfigObj going on in > python-dev. Ian Bicking mentions about having *too much* in the API. > Implementing two means of doing similar things seems like overkill. That's also true, I agree that the API should be as frugal as possible. > Do you greatly prefer ``getboolean`` (allowing but requiring you to > specify a sub-section) to ``asboolean`` (not requiring or allowing you > to specify a sub-section) ? No, I don't. It only seems useful for ConfigParser compatibility, subsect.as_bool(key) (I'd like it shorter and clearer) is simpler and functional. > Just implementing ``asboolean`` leaves the way open for ``getboolean`` > in a subclass (implementation of either is trivial). Then option 2) it is. -- Nicola Larosa - http://www.tekNico.net/ People just don't want to be pestered - they want shit to happen without being bugged. If technology is to help, it must be seren- dipitous rather than strident. -- Nathan Torkington, November 2005 |
|
From: Fuzzyman <fuz...@vo...> - 2006-01-30 21:49:03
|
Nicola Larosa wrote:
>>> I think I'll disagree here. I concur that having to specify None for no
>>> subsection is a bit inconvenient. However, breaking the rule that optional
>>> parameters should be last in the signature is worse, IMO. I seem to recall
>>> a couple such cases in the standard library, and they feel out of place and
>>> inconsistent with the rest.
>>>
>>> Moreover, with option 3) you're not really compatible with ConfigParser
>>> anymore, since you changed the signature, by allowing one to use just one
>>> param. That may cause surprises in case of mistakes.
>>>
>>> Maybe it would be better to have separate methods with just one param, and
>>> that would be option 1), if I'm not mistaken.
>>>
>
>
>> I can see your point.
>>
>> *However* there is a current discussion of ConfigObj going on in
>> python-dev. Ian Bicking mentions about having *too much* in the API.
>> Implementing two means of doing similar things seems like overkill.
>>
>
> That's also true, I agree that the API should be as frugal as possible.
>
>
>
>> Do you greatly prefer ``getboolean`` (allowing but requiring you to
>> specify a sub-section) to ``asboolean`` (not requiring or allowing you
>> to specify a sub-section) ?
>>
>
> No, I don't. It only seems useful for ConfigParser compatibility,
> subsect.as_bool(key) (I'd like it shorter and clearer) is simpler and
> functional.
>
>
>
>> Just implementing ``asboolean`` leaves the way open for ``getboolean``
>> in a subclass (implementation of either is trivial).
>>
>
> Then option 2) it is.
>
>
Done. :-)
I'll set about implementing :
as_bool
as_int
as_float
I'm part way through adding unicode support. Things like checking the
compiled (ascii) regular expressions handle unicode fine and fuller BOM
support make this not-quite-trivial-but-not-too-bad.
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
|
|
From: Michael F. <fuz...@vo...> - 2006-01-30 22:33:00
|
Fuzzyman wrote:
[snip..]
> Done. :-)
>
> I'll set about implementing :
>
> as_bool
> as_int
> as_float
>
>
Uhmm... that was embarrassingly easy, rename ``istrue`` to ``as_bool``
and new section methods :
def as_int(self, key):
return int(self[key])
def as_float(self, key):
return float(self[key])
Have I missed anything (they ought to raise a ValueError for invalid
values).
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
> I'm part way through adding unicode support. Things like checking the
> compiled (ascii) regular expressions handle unicode fine and fuller BOM
> support make this not-quite-trivial-but-not-too-bad.
>
> All the best,
>
>
> Fuzzyman
> http://www.voidspace.org.uk/python/index.shtml
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|