{emo;development} I've just checked an updated version of `ConfigObj <http://www.voidspace.org.uk/python/configobj.html>`_ into the subversion repository. This is **ConfigObj 4.2.0 Beta 2**, and it's in the usual place :
https://svn.rest2web.python-hosting.com/branches/configobj4/pythonutils/
This now has a set of tests and I'm happy with the changes. If no bugs are found, then this will become **ConfigObj 4.2.0**. I'm happy with the changes.
.. warning::
The way that ConfigObj handles file like objects has changed. It no longer keeps a reference to them. This is *better*, but could break existing code.
Additionally, the {acro;BOM;Byte Order Mark} attribute is now a boolean.
I haven't yet done the documentation, but these are the changes :
* Full unicode support.
You can specify an ``encoding`` and a ``default_encoding`` when you create your instance.
The ``encoding`` keyword maps to the ``encoding`` attribute. It is used to decode your config file into unicode, and also to re-encode when writing.
The ``default_encoding`` (if supplied) is used to decode any byte-strings that have got into your ConfigObj instance, before writing in the specified encoding. This overrides the system default encoding that is otherwise used.
* UTF16 Handling
``UTF16`` encoded files are automatically detected and decoded to unicode. This is because ConfigObj *can't* handle them as byte strings.
* BOM Attribute
The BOM attribute is now a boolean. If a UTF8 or UTF16 BOM was detected then it is ``True``. The default is ``False``.
If BOM is ``True``, then a UTF8 BOM will be written out with files that have no encoding specified, or have a ``utf_8`` encoding.
* File like Objects.
ConfigObj no longer keeps a reference to file like objects you pass it. If you create a ConfigObj instance from a file like object, the ``filename`` attribute will be ``None``.
In addition to this, the ``seek`` method of file like objects is never called by ConfigObj. (It tests for the ``read`` method when you instantiate. You must call ``seek(0)`` yourself first, if necessary. This means you can use file like objects which don't implement seek.
* Writing to a file like object.
The ``write`` method can now receive an optional file like object as an argument. This will be written to in preference to a file specified by the ``filename`` attribute.
* Line Endings.
When passed a config file (by whatever method), ConfigObj will attempt to determine the line endings in use. (It chooses the first line ending character it finds, whether this be ``\r\n``, ``\n``, or ``\r``.)
This is preserved as the ``newlines`` attribute.
When writing (except when outputting a list of lines), this will be used as the line endings for the file.
For new ConfigObj instances (or where no line endings are found), it defaults to ``None``. In this case the platform native line ending (``os.linesep``) is used.
There are also the new `Section Methods <http://www.voidspace.org.uk/python/configobj.html#section-methods>`_ added in Beta 1 :
* ``as_bool``
* ``as_int``
* ``as_float``
They all take a single key as an argument, and return the value in the specified type. They can all raise ``KeyError`` or ``ValueError`` should the situation demand it. |