7
7
----------------------------------------
9
9
:Authors: Michael Foord, Nicola Larosa
10
:Version: ConfigObj 4.4.0
10
:Version: ConfigObj 4.5.2
12
12
:Homepage: `ConfigObj Homepage`_
13
13
:Sourceforge: Sourceforge_
14
14
:Development: `SVN Repository`_
45
47
- repeated sections
46
48
- and allowing default values
48
* All comments in the file are preserved
49
* The order of keys/sections is preserved
50
* No external dependencies
50
* When writing out config files, ConfigObj preserves all comments and the order of members and sections
51
* Many useful methods and options for working with configuration files (like the 'reload' method)
51
52
* Full Unicode support
52
* A powerful ``unrepr`` mode for storing basic datatypes
54
ConfigObj has a barrage of doctests [#]_ built into it, testing almost every
55
feature. Run ``python configobj_test.py -v`` to see them in action.
57
55
For support and bug reports please use the ConfigObj `Mailing List`_.
60
.. _ConfigObj for Data Persistence: http://www.voidspace.org.uk/python/articles/configobj_for_data_persistence.shtml
61
.. _ConfigPersist.py: http://www.voidspace.org.uk/python/configpersist.html
67
The current version is **4.4.0**, dated 4th February 2007. ConfigObj 4 is
61
The current version is **4.5.2**, dated 24th February 2008. ConfigObj 4 is
68
62
now stable. We still expect to pick up a few bugs along the way though [#]_.
113
106
from the `Subversion Repository <http://svn.pythonutils.python-hosting.com/trunk/pythonutils/>`_.
115
108
.. _configobj.py: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj.py
116
.. _configobj.zip: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.4.0.zip
109
.. _configobj.zip: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.5.2.zip
117
110
.. _validate.py: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=validate.py
118
.. _API Docs: http://www.voidspace.org.uk/python/configobj-api/
119
111
.. _this document:
120
112
.. _configobj homepage: http://www.voidspace.org.uk/python/configobj.html
121
113
.. _Sourceforge: http://sourceforge.net/projects/configobj
122
.. _EpyDoc: http://epydoc.sourceforge.net
123
114
.. _pythonutils: http://www.voidspace.org.uk/python/pythonutils.html
124
.. _Voidspace Python Projects: http://www.voidspace.org.uk/python
115
.. _Voidspace Python Projects: http://www.voidspace.org.uk/python/index.shtml
128
119
ConfigObj in the Real World
129
120
===========================
131
Projects that use **ConfigObj** include :
122
**ConfigObj** is widely used. Projects using it include:
133
124
* `Bazaar <http://bazaar-ng.org>`_.
144
135
A Python and `wxPython <http://www.wxpython.org>`_
145
136
{acro;PIM;Personal Information Manager}, being developed by the
146
137
`OSAFoundation <http://www.osafoundation.org/>`_.
148
* `CryptoBox <https://systemausfall.org/trac/cryptobox/wiki/CryptoBox/en>`_
150
A very interesting looking Debian based Live-CD which supports storing
151
data using an encrypted harddisk; usable even by non technical users.
153
* `Simple64 <http://ubuntuforums.org/showthread.php?t=266290>`_
155
A Ubuntu tool which provides a GUI to install a host of applications.
157
* `Debian-cd-ng <http://wiki.debian.org/debian-cd-ng>`_
159
*Debian-cd-ng* recommends ConfigObj for parsing the Debian-cd configuration files.
161
* `NeuroImaging in Python <http://projects.scipy.org/neuroimaging/ni/wiki>`_
163
BrainSTAT is a project with the ultimate goal to produce a
164
platform-independent python environment for the analysis of brain
167
* `Gruik <http://www.tracos.org/gruik/wiki>`_
169
Gruik is a free software network packet sniffer.
139
* `matplotlib <http://matplotlib.sourceforge.net/>`_
141
A 2D plotting library.
143
* `IPython <http://ipython.scipy.org/moin/>`_
145
IPython is an enhanced interactive Python shell. IPython uses ConfigObj in a module called 'TConfig' that combines it with enthought `Traits <http://code.enthought.com/traits/>`_: `tconfig <http://ipython.scipy.org/ipython/ipython/browser/ipython/branches/saw/sandbox/tconfig>`_.
147
* `Elisa - the Fluendo Mediacenter <http://elisa.fluendo.com/>`_
149
Elisa is an open source cross-platform media center solution designed to be simple for people not particularly familiar with computers.
600
590
This method validates the ConfigObj against the configspec. By doing type
601
conversion as well, it can abstract away the config file altogether and present
591
conversion as well it can abstract away the config file altogether and present
602
592
the config *data* to your application (in the types it expects it to be).
604
594
If the ``configspec`` attribute of the ConfigObj is ``None``, it raises a
621
611
find this blog entry helpful :
622
612
`Transforming Values with ConfigObj <http://www.voidspace.org.uk/python/weblog/arch_d7_2006_03_04.shtml#e257>`_.
624
There is also a module to assist in auto-generating configspecs called
625
ConfigPersist.py_. Its use is explained in `ConfigObj for Data Persistence`_.
627
615
The ``copy`` parameter fills in missing values from the configspec (default
628
616
values), *without* marking the values as defaults. It also causes comments to
774
765
within configspecs, ``DEFAULT`` sections are not processed by
775
766
validation; even in copy mode.
772
If a ConfigObj instance was loaded from the filesystem, then this method will reload it. It
773
will also reuse any configspec you supplied at instantiation (including reloading it from
774
the filesystem if you passed it in as a filename).
776
If the ConfigObj does not have a filename attribute pointing to a file, then a ``ReloadError``
783
This method takes no arguments and doesn't return anything. It restores a ConfigObj
784
instance to a freshly created state.
1339
1376
It raises a ``ValueError`` if the conversion can't be done.
1378
* **restore_default**
1380
``restore_default(key)``
1382
Restore (and return) the default value for the specified key.
1384
This method will only work for a ConfigObj that was created
1385
with a configspec and has been validated.
1387
If there is no default value for this key, ``KeyError`` is raised.
1389
* **restore_defaults**
1391
``restore_defaults()``
1393
Recursively restore default values to all members
1396
This method will only work for a ConfigObj that was created
1397
with a configspec and has been validated.
1399
It doesn't delete or modify entries without default values.
1341
1402
Walking a Section
1342
1403
-----------------
1638
1704
find this blog entry helpful :
1639
1705
`Transforming Values with ConfigObj <http://www.voidspace.org.uk/python/weblog/arch_d7_2006_03_04.shtml#e257>`_.
1641
There is also a module to assist in auto-generating configspecs called
1642
ConfigPersist.py_. Its use is explained in `ConfigObj for Data Persistence`_.
1644
1707
Validation is done through a combination of the configspec_ and a ``Validator``
1645
1708
object. For this you need *validate.py* [#]_. See downloading_ if you don't
2127
Backwards Compatibility
2128
=======================
2130
There have been a lot of changes since ConfigObj 3. The core parser is now
2131
based on regular expressions, and is a lot faster and smaller. There is now no
2132
difference in the way we treat flat files and non-flatfiles, that is, no empty
2133
sections. This means some of the code can be a lot simpler, less code does
2134
more of the work [#]_.
2136
There have been other simplifications: for example we only have eight options
2137
instead of seventeen.
2139
Most config files created for ConfigObj 3 will be read with no changes and many
2140
programs will work without having to alter code. Some of the changes do break
2141
backwards compatibility: for example, code that uses the previous options will
2142
now raise an error. It should be very easy to fix these, though.
2144
Below is a list of all the changes that affect backwards compatibility. This
2145
doesn't include details of method signatures that have changed, because almost
2148
Incompatible Changes
2149
--------------------
2151
(I have removed a lot of needless complications: this list is probably not
2152
conclusive, many option/attribute/method names have changed.)
2156
The only valid divider is '='.
2158
Line continuations with ``\`` removed.
2160
No recursive lists in values.
2164
No distinction between flatfiles and non flatfiles.
2166
Change in list syntax: use commas to indicate list, not parentheses (square
2167
brackets and parentheses are no longer recognised as lists).
2169
';' is no longer valid for comments, and no multiline comments.
2171
No attribute-style access to values.
2173
Empty values not allowed: use '' or "".
2175
In ConfigObj 3, setting a non-flatfile member to ``None`` would initialise it
2176
as an empty section.
2178
The escape entities '&mjf-lf;' and '&mjf-quot;' have gone, replaced by triple
2179
quote, multiple line values.
2181
The ``newline``, ``force_return``, and ``default`` options have gone.
2183
``fileerror`` and ``createempty`` options have become ``file_error`` and
2186
Partial configspecs (for specifying the order members should be written out,
2187
and which should be present) have gone. The configspec is no longer used to
2188
specify order for the ``write`` method.
2190
Infinite loops in string interpolation are now detected and raise an error
2191
``InterpolationLoopError``.
2193
Specifying a value for interpolation which doesn't exist now raises a
2194
``MissingInterpolationOption`` error (instead of merely being ignored).
2196
The ``writein`` method has been removed.
2198
The comments attribute is now a list (``inline_comments`` equates to the old
2199
comments attribute).
2204
2201
ConfigObj 3 is now deprecated in favour of ConfigObj 4. I can fix bugs in
2205
2202
ConfigObj 3 if needed, though.
2235
2232
Of course if it does, let us know and we'll fix the problem so it doesn't
2236
2233
happen to anyone else {sm;:-)}. ::
2238
Copyright (c) 2004 - 2006, Michael Foord & Nicola Larosa
2235
Copyright (c) 2004 - 2008, Michael Foord & Nicola Larosa
2239
2236
All rights reserved.
2241
2238
Redistribution and use in source and binary forms, with or without
2326
2323
of the current section, before moving on to the current section's parent and
2327
2324
so on up the tree.
2329
Logically a 'DEFAULT' section should apply to all subsections of the *same
2330
parent* - this means that checking the 'DEFAULT' subsection in the
2331
*current section* is not necessarily logical ?
2333
2326
Does it matter that we don't support the ':' divider, which is supported
2334
2327
by ``ConfigParser`` ?
2346
2339
This is an abbreviated changelog showing the major releases up to version 4.
2347
From version 4 it lists all releases and changes. *More* data on individual
2348
changes may be found in the source code or the CHANGELOG file.
2340
From version 4 it lists all releases and changes.
2343
2008/02/05 - Version 4.5.2
2344
--------------------------
2346
Distribution updated to include version 0.3.2 of validate_. This means that
2347
``None`` as a default value win configspecs works.
2350
2008/02/05 - Version 4.5.1
2351
--------------------------
2353
Distribution updated to include version 0.3.1 of validate_. This means that
2354
Unicode configspecs now work.
2357
2008/02/05 - Version 4.5.0
2358
--------------------------
2360
ConfigObj will now guarantee that files will be written terminated with a
2363
ConfigObj will no longer attempt to import the ``validate`` module, until/unless
2364
you call ``ConfigObj.validate`` with ``preserve_errors=True``. This makes it
2367
New methods ``restore_default`` and ``restore_defaults``. ``restore_default``
2368
resets an entry to its default value (and returns that value). ``restore_defaults``
2369
resets all entries to their default value. It doesn't modify entries without a
2370
default value. You must have validated a ConfigObj (which populates the
2371
``default_values`` dictionary) before calling these methods.
2373
BUGFIX: Proper quoting of keys, values and list values that contain hashes
2374
(when writing). When ``list_values=False``, values containing hashes are
2377
Added the ``reload`` method. This reloads a ConfigObj from file. If the filename
2378
attribute is not set then a ``ReloadError`` (a new exception inheriting from
2379
``IOError``) is raised.
2381
BUGFIX: Files are read in with 'rb' mode, so that native/non-native line endings work!
2383
Minor efficiency improvement in ``unrepr`` mode.
2385
Added missing docstrings for some overidden dictionary methods.
2387
Added the ``reset`` method. This restores a ConfigObj to a freshly created state.
2389
Removed old CHANGELOG file.
2351
2392
2007/02/04 - Version 4.4.0
2581
2626
Changed the mailing list address.
2583
2629
2005/08/28 - Version 4.0.0 beta 3
2584
2630
---------------------------------
2586
2632
Interpolation is switched off before writing out files.
2588
2634
Fixed bug in handling ``StringIO`` instances. (Thanks to report from
2589
"Gustavo Niemeyer" <gustavo@niemeyer.net>)
2591
2637
Moved the doctests from the ``__init__`` method to a separate function.
2592
2638
(For the sake of IDE calltips).
2594
2641
2005/08/25 - Version 4.0.0 beta 2
2595
2642
---------------------------------
2597
2644
Amendments to *validate.py*.
2646
First public release.
2601
2649
2005/08/21 - Version 4.0.0 beta 1
2602
2650
---------------------------------
2681
2731
The config object now behaves like a dictionary.
2683
2733
I've completely broken the interface, but I don't think anyone was really
2686
This new version is much more 'classy' {sm;:wink:}
2736
This new version is much more 'classy'. {sm;:wink:}
2688
2738
It will also read straight from/to a filename and completely parse a config
2689
2739
file without you *having* to supply a config spec.
2752
2803
.. [#] The exception is if it detects a ``UTF16`` encoded file which it
2753
2804
must decode before parsing.
2755
.. [#] The method signature in the API docs will show that this method takes
2806
.. [#] The method signature shows that this method takes
2756
2807
two arguments. The second is the section to be written. This is because the
2757
2808
``write`` method is called recursively.
2797
2848
alt="Python on Voidspace" border="0" />
2801
<a href="http://sourceforge.net/donate/index.php?group_id=123265">
2802
<img src="http://images.sourceforge.net/images/project-support.jpg" width="88" height="32" border="0" alt="Support This Project" />
2806
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
2808
<script type="text/javascript">
2809
_uacct = "UA-203625-1";
2816
2854
.. _listquote: http://www.voidspace.org.uk/python/modules.shtml#listquote
2817
.. _Michael Foord: http://www.voidspace.org.uk/index2.shtml
2855
.. _Michael Foord: http://www.voidspace.org.uk/python/weblog/index.shtml
2818
2856
.. _Nicola Larosa: http://www.teknico.net
2819
.. _Mark Andrews: http://www.la-la.com