|
From: Michael F. <fuz...@vo...> - 2006-01-31 17:02:56
|
Hello all, The update to ConfigObj is now in subversion. In https://svn.rest2web.python-hosting.com/branches/configobj4/pythonutils/ This contains the new methods : * as_bool * as_int * as_float istrue is now deprecated with a warning. It also contains the new unicode support. This was easy enough to implement, and works on my tests with a UTF16 config file. I would really appreciate it if you could check this out and try and break it. Unicode is notoriously fiddly to get right ! There is still a question about automatic support for UTF8 files with a BOM. The new position is that UTF8 files with a BOM will be automatically decoded to unicode. I have also proposed a *better* way of handling the BOM. See my blog entry on the subject : http://www.voidspace.org.uk/python/weblog/arch_d7_2006_01_28.shtml#e204 Opinions and comments sought. Thanks Fuzzyman http://www.voidspace.org.uk/python/index.shtml |
|
From: Aaron B. <aar...@ut...> - 2006-02-02 03:55:49
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Michael Foord wrote: | I would really appreciate it if you could check this out and try and | break it. Unicode is notoriously fiddly to get right ! This all looks good. I will try converting bzr to the latest version soon, and let you know. | There is still a question about automatic support for UTF8 files with a | BOM. The new position is that UTF8 files with a BOM will be | automatically decoded to unicode. | | I have also proposed a *better* way of handling the BOM. I like the idea of BOM being a boolean, if that's what you mean. Aaron -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD4YK10F+nu1YWqI0RApP8AJ0S+tbZ3V+oYUXL1+MrKwnQQpEenQCghLVJ 7TmgjVEsz55qNapITDocMD4= =UHuk -----END PGP SIGNATURE----- |
|
From: Fuzzyman <fuz...@vo...> - 2006-02-02 08:55:16
|
Aaron Bentley wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Michael Foord wrote: > | I would really appreciate it if you could check this out and try and > | break it. Unicode is notoriously fiddly to get right ! > > This all looks good. I will try converting bzr to the latest version > soon, and let you know. > Great. > | There is still a question about automatic support for UTF8 files with a > | BOM. The new position is that UTF8 files with a BOM will be > | automatically decoded to unicode. > | > | I have also proposed a *better* way of handling the BOM. > > I like the idea of BOM being a boolean, if that's what you mean. > Ok, it's actually simpler than what I've currently implemented and is more sensible really. The other question is, if ConfigObj is passed a UTF8 file with a BOM, should it automatically decode to unicode ? The behaviour of ConfigObj 4.1.0 (and previous) was to preserve the BOM (UTF8 only) but not decode. On balance it is probably better *not* to decode (ConfigObj doesn't attempt to detect the encoding of other files). For UTF16 files it must automatically decode - otherwise it splits characters on byte boundaries which mangles them. So if BOM is True, but no encoding is specified, then a UTF8 BOM will be written out. Otherwise a BOM will only be written out if BOM is True and the encoding is UTF8 or UTF16. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Aaron > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFD4YK10F+nu1YWqI0RApP8AJ0S+tbZ3V+oYUXL1+MrKwnQQpEenQCghLVJ > 7TmgjVEsz55qNapITDocMD4= > =UHuk > -----END PGP SIGNATURE----- > > > ------------------------------------------------------- > 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 > |
|
From: Aaron B. <aar...@ut...> - 2006-02-02 18:15:40
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Fuzzyman wrote: > Aaron Bentley wrote: > > Michael Foord wrote: > | I would really appreciate it if you could check this out and try and > | break it. Unicode is notoriously fiddly to get right ! > > This all looks good. I will try converting bzr to the latest version > soon, and let you know. > >> Great. I have done this, and I was rather surprised that the output of cfg_obj.write() is a list of unicode strings, rather than a list of bytestrings. We need to supply our own file objects, so we've been using the lines output from cfg_obj.write() up to this point. The StringIO support looks awkward, but probably doable to me. (Am I right that the public member for the StringIO is ConfigObj.filename?) My preference would be the ability to specify a file object to cfg_obj.write(). Aaron -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD4kxA0F+nu1YWqI0RAgoLAJ9HlNNJ0bTOm4xPEL3NXzeGzEvAeQCdEJw5 FSyN2JEIBcKvT3lPHW2Zo/E= =gKuf -----END PGP SIGNATURE----- |
|
From: Michael F. <fuz...@vo...> - 2006-02-02 18:38:51
|
Aaron Bentley wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Fuzzyman wrote: > >> Aaron Bentley wrote: >> >> Michael Foord wrote: >> | I would really appreciate it if you could check this out and try and >> | break it. Unicode is notoriously fiddly to get right ! >> >> This all looks good. I will try converting bzr to the latest version >> soon, and let you know. >> >> >>> Great. >>> > > I have done this, and I was rather surprised that the output of > cfg_obj.write() is a list of unicode strings, rather than a list of > bytestrings. > > Ok - so if an encoding is specified, then ``write()`` should always return byte strings. That is what is called an 'over-sight'. :-) Will be fixed. > We need to supply our own file objects, so we've been using the lines > output from cfg_obj.write() up to this point. The StringIO support > looks awkward, but probably doable to me. (Am I right that the public > member for the StringIO is ConfigObj.filename?) > > Yes. > My preference would be the ability to specify a file object to > cfg_obj.write(). > So you'd like to be able to pass a file like object to ``write()``... hmmm... Again, this is something that you used to be able to do with ConfigObj 3, but I removed to reduce the level of complexity. To be symmetric with initialisation, you ought then be able to pass in a filename as well. Seeing as you can already achieve this just be setting the ``filename`` attribute (which ok sounds a little weird for this purpose), I decided not to do it. Hmmm... I guess it wouldn't hurt being able to pass an optional file object to write, it's just that the API keeps growing... Nicola, do you have any take on this ? All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Aaron > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFD4kxA0F+nu1YWqI0RAgoLAJ9HlNNJ0bTOm4xPEL3NXzeGzEvAeQCdEJw5 > FSyN2JEIBcKvT3lPHW2Zo/E= > =gKuf > -----END PGP SIGNATURE----- > > |
|
From: Nicola L. <ni...@te...> - 2006-02-02 19:13:45
|
>> My preference would be the ability to specify a file object to >> cfg_obj.write(). > So you'd like to be able to pass a file like object to ``write()``... > hmmm... > > Again, this is something that you used to be able to do with ConfigObj > 3, but I removed to reduce the level of complexity. > > To be symmetric with initialisation, you ought then be able to pass in a > filename as well. Seeing as you can already achieve this just be setting > the ``filename`` attribute (which ok sounds a little weird for this > purpose), I decided not to do it. > > Hmmm... I guess it wouldn't hurt being able to pass an optional file > object to write, it's just that the API keeps growing... > > Nicola, do you have any take on this ? Well, it actually feels a little awkward that ConfigObj is in the business of opening files, and having to store the filename in an attribute. It seems best that ``write`` just receives a file-like object, and be done with it. This seems a worthy addition to me. At this point you probably have to keep the filename attribute for compatibility anyway, but maybe you could even find a way to deprecate it? :-) -- Nicola Larosa - http://www.tekNico.net/ Using threads is like having no backups: you stay in denial of the problem until it bites you, and then it's too late. -- Nicola Larosa, November 2005 |
|
From: Michael F. <fuz...@vo...> - 2006-02-02 22:55:18
|
Nicola Larosa wrote:
>>> My preference would be the ability to specify a file object to
>>> cfg_obj.write().
>>>
>
>
>> So you'd like to be able to pass a file like object to ``write()``...
>> hmmm...
>>
>> Again, this is something that you used to be able to do with ConfigObj
>> 3, but I removed to reduce the level of complexity.
>>
>> To be symmetric with initialisation, you ought then be able to pass in a
>> filename as well. Seeing as you can already achieve this just be setting
>> the ``filename`` attribute (which ok sounds a little weird for this
>> purpose), I decided not to do it.
>>
>> Hmmm... I guess it wouldn't hurt being able to pass an optional file
>> object to write, it's just that the API keeps growing...
>>
>> Nicola, do you have any take on this ?
>>
>
> Well, it actually feels a little awkward that ConfigObj is in the business
> of opening files, and having to store the filename in an attribute. It
> seems best that ``write`` just receives a file-like object, and be done
> with it.
>
> This seems a worthy addition to me. At this point you probably have to keep
> the filename attribute for compatibility anyway, but maybe you could even
> find a way to deprecate it? :-)
>
I realise that in Python it is more common to pass around file like
objects than filenames. I guess this is more object oriented because of
the "like" bit. However it has always felt more awkward to me, because
>90% of the time I use "file-like" objects, they are file objects.
Invariably when I write a config file, it is to the same one that was
opened. My current idiom (based on having a hardwired config filename,
or retrieving from the user) is :
retrieve filename
instantiate ConfigObj
..
do stuff
..
write
The alternative becomes :
get filename
open file
instantiate ConfigObj (whilst keeping a separate reference to the
filename)
close file
..
do stuff
..
get filename again
open file
write
close file
It just seems a lot more awkward. ConfigObj *already* supports passing
it an open file on instantiation. I guess passing an open file to
``write`` is a logical extension of this, but I won't deprecate
``filename``.
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
|
|
From: Aaron B. <aar...@ut...> - 2006-02-03 01:37:00
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Michael Foord wrote: | I realise that in Python it is more common to pass around file like | objects than filenames. I guess this is more object oriented because of | the "like" bit. However it has always felt more awkward to me, because | >90% of the time I use "file-like" objects, they are file objects. For Bazaar-NG, the file-like objects currently represent http, sftp and ftp downloads and uploads. Not saying either way is best, or even that you have to change things. What we have now does work, after all, and I appreciate the changes you've made so far. Aaron -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD4rOU0F+nu1YWqI0RAudeAJ0fnGEecu5wVMNyLa4UiWyJ1ft5gQCfbEq+ 49JZmbgE0HaX8AtpzA6Jn9Q= =RNuq -----END PGP SIGNATURE----- |
|
From: Fuzzyman <fuz...@vo...> - 2006-02-03 10:33:54
|
Aaron Bentley wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Michael Foord wrote: > | I realise that in Python it is more common to pass around file like > | objects than filenames. I guess this is more object oriented because of > | the "like" bit. However it has always felt more awkward to me, because > | >90% of the time I use "file-like" objects, they are file objects. > > For Bazaar-NG, the file-like objects currently represent http, sftp and > ftp downloads and uploads. Not saying either way is best, or even that > you have to change things. What we have now does work, after all, and I > appreciate the changes you've made so far. > Thanks for your comments. Fixes discussed so far will be ready over the weekend. I *do* think it's weird that ConfigObj uses the filename attribute to store a reference to the file object/StringIO instance you pass in. This is illogical at best, and can lead to errors if you would normally expect a file object to be garbage collected. (It's better practise to close explicitly, but hey.) I think the best change is to *not* store a reference to "file-like-objects" passed in to ConfigObj, but change the ``write`` method to receive an optional file object as an argument. This is backwards incompatible - but because of all the changes I'm bumping the version number to 4.2.0. I'm open to protests from anyone else before I make this change... All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Aaron > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFD4rOU0F+nu1YWqI0RAudeAJ0fnGEecu5wVMNyLa4UiWyJ1ft5gQCfbEq+ > 49JZmbgE0HaX8AtpzA6Jn9Q= > =RNuq > -----END PGP SIGNATURE----- > |
|
From: Aaron B. <aar...@ut...> - 2006-02-02 19:25:17
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Michael Foord wrote: >> Ok - so if an encoding is specified, then ``write()`` should always >> return byte strings. That is what is called an 'over-sight'. :-) > >> Will be fixed. Cool. > My preference would be the ability to specify a file object to > cfg_obj.write(). > > >> So you'd like to be able to pass a file like object to ``write()``... >> hmmm... > >> Again, this is something that you used to be able to do with ConfigObj >> 3, but I removed to reduce the level of complexity. By way of explanation, the file-like objects we read from are not the same objects as the ones we write to. We have a get method that produces a read-only file-like, and a put method that accepts a file-like. Aaron -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD4lyF0F+nu1YWqI0RAiXmAJ0TuLzcDOjtLBi4LghjjMSc/mQm6QCcDi31 dkl8c/9AJMfneuT5S88hPYU= =qHDM -----END PGP SIGNATURE----- |