7
7
----------------------------------------
9
9
:Authors: Michael Foord, Nicola Larosa
10
:Version: ConfigObj 4.4.0
10
:Version: ConfigObj 4.5.1
12
12
:Homepage: `ConfigObj Homepage`_
13
13
:Sourceforge: Sourceforge_
14
14
:Development: `SVN Repository`_
51
53
* Full Unicode support
52
54
* 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
57
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
63
The current version is **4.5.1**, dated 5th February 2008. ConfigObj 4 is
68
64
now stable. We still expect to pick up a few bugs along the way though [#]_.
113
108
from the `Subversion Repository <http://svn.pythonutils.python-hosting.com/trunk/pythonutils/>`_.
115
110
.. _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
111
.. _configobj.zip: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.5.1.zip
117
112
.. _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
113
.. _this document:
120
114
.. _configobj homepage: http://www.voidspace.org.uk/python/configobj.html
121
115
.. _Sourceforge: http://sourceforge.net/projects/configobj
122
.. _EpyDoc: http://epydoc.sourceforge.net
123
116
.. _pythonutils: http://www.voidspace.org.uk/python/pythonutils.html
124
.. _Voidspace Python Projects: http://www.voidspace.org.uk/python
117
.. _Voidspace Python Projects: http://www.voidspace.org.uk/python/index.shtml
128
121
ConfigObj in the Real World
129
122
===========================
131
Projects that use **ConfigObj** include :
124
**ConfigObj** is widely used. Projects using it include:
133
126
* `Bazaar <http://bazaar-ng.org>`_.
144
137
A Python and `wxPython <http://www.wxpython.org>`_
145
138
{acro;PIM;Personal Information Manager}, being developed by the
146
139
`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.
141
* `IPython <http://ipython.scipy.org/moin/>`_
143
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>`_.
145
* ` Elisa - the Fluendo Mediacenter <http://elisa.fluendo.com/>`_
147
Elisa is an open source cross-platform media center solution designed to be simple for people not particularly familiar with computers.
600
588
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
589
conversion as well it can abstract away the config file altogether and present
602
590
the config *data* to your application (in the types it expects it to be).
604
592
If the ``configspec`` attribute of the ConfigObj is ``None``, it raises a
621
609
find this blog entry helpful :
622
610
`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
613
The ``copy`` parameter fills in missing values from the configspec (default
628
614
values), *without* marking the values as defaults. It also causes comments to
774
763
within configspecs, ``DEFAULT`` sections are not processed by
775
764
validation; even in copy mode.
770
If a ConfigObj instance was loaded from the filesystem, then this method will reload it. It
771
will also reuse any configspec you supplied at instantiation (including reloading it from
772
the filesystem if you passed it in as a filename).
774
If the ConfigObj does not have a filename attribute pointing to a file, then a ``ReloadError``
781
This method takes no arguments and doesn't return anything. It restores a ConfigObj
782
instance to a freshly created state.
1339
1374
It raises a ``ValueError`` if the conversion can't be done.
1376
* **restore_default**
1378
``restore_default(key)``
1380
Restore (and return) the default value for the specified key.
1382
This method will only work for a ConfigObj that was created
1383
with a configspec and has been validated.
1385
If there is no default value for this key, ``KeyError`` is raised.
1387
* **restore_defaults**
1389
``restore_defaults()``
1391
Recursively restore default values to all members
1394
This method will only work for a ConfigObj that was created
1395
with a configspec and has been validated.
1397
It doesn't delete or modify entries without default values.
1341
1400
Walking a Section
1342
1401
-----------------
1638
1702
find this blog entry helpful :
1639
1703
`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
1705
Validation is done through a combination of the configspec_ and a ``Validator``
1645
1706
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
2199
ConfigObj 3 is now deprecated in favour of ConfigObj 4. I can fix bugs in
2205
2200
ConfigObj 3 if needed, though.
2235
2230
Of course if it does, let us know and we'll fix the problem so it doesn't
2236
2231
happen to anyone else {sm;:-)}. ::
2238
Copyright (c) 2004 - 2006, Michael Foord & Nicola Larosa
2233
Copyright (c) 2004 - 2008, Michael Foord & Nicola Larosa
2239
2234
All rights reserved.
2241
2236
Redistribution and use in source and binary forms, with or without
2326
2321
of the current section, before moving on to the current section's parent and
2327
2322
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
2324
Does it matter that we don't support the ':' divider, which is supported
2334
2325
by ``ConfigParser`` ?
2346
2337
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.
2338
From version 4 it lists all releases and changes.
2341
2008/02/05 - Version 4.5.1
2342
--------------------------
2344
Distribution updated to include version 0.3.1 of validate_. This means that
2345
Unicode configspecs now work.
2348
2008/02/05 - Version 4.5.0
2349
--------------------------
2351
ConfigObj will now guarantee that files will be written terminated with a
2354
ConfigObj will no longer attempt to import the ``validate`` module, until/unless
2355
you call ``ConfigObj.validate`` with ``preserve_errors=True``. This makes it
2358
New methods ``restore_default`` and ``restore_defaults``. ``restore_default``
2359
resets an entry to its default value (and returns that value). ``restore_defaults``
2360
resets all entries to their default value. It doesn't modify entries without a
2361
default value. You must have validated a ConfigObj (which populates the
2362
``default_values`` dictionary) before calling these methods.
2364
BUGFIX: Proper quoting of keys, values and list values that contain hashes
2365
(when writing). When ``list_values=False``, values containing hashes are
2368
Added the ``reload`` method. This reloads a ConfigObj from file. If the filename
2369
attribute is not set then a ``ReloadError`` (a new exception inheriting from
2370
``IOError``) is raised.
2372
BUGFIX: Files are read in with 'rb' mode, so that native/non-native line endings work!
2374
Minor efficiency improvement in ``unrepr`` mode.
2376
Added missing docstrings for some overidden dictionary methods.
2378
Added the ``reset`` method. This restores a ConfigObj to a freshly created state.
2380
Removed old CHANGELOG file.
2351
2383
2007/02/04 - Version 4.4.0
2581
2617
Changed the mailing list address.
2583
2620
2005/08/28 - Version 4.0.0 beta 3
2584
2621
---------------------------------
2586
2623
Interpolation is switched off before writing out files.
2588
2625
Fixed bug in handling ``StringIO`` instances. (Thanks to report from
2589
"Gustavo Niemeyer" <gustavo@niemeyer.net>)
2591
2628
Moved the doctests from the ``__init__`` method to a separate function.
2592
2629
(For the sake of IDE calltips).
2594
2632
2005/08/25 - Version 4.0.0 beta 2
2595
2633
---------------------------------
2597
2635
Amendments to *validate.py*.
2637
First public release.
2601
2640
2005/08/21 - Version 4.0.0 beta 1
2602
2641
---------------------------------
2681
2722
The config object now behaves like a dictionary.
2683
2724
I've completely broken the interface, but I don't think anyone was really
2686
This new version is much more 'classy' {sm;:wink:}
2727
This new version is much more 'classy'. {sm;:wink:}
2688
2729
It will also read straight from/to a filename and completely parse a config
2689
2730
file without you *having* to supply a config spec.
2752
2794
.. [#] The exception is if it detects a ``UTF16`` encoded file which it
2753
2795
must decode before parsing.
2755
.. [#] The method signature in the API docs will show that this method takes
2797
.. [#] The method signature shows that this method takes
2756
2798
two arguments. The second is the section to be written. This is because the
2757
2799
``write`` method is called recursively.
2797
2839
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
2845
.. _listquote: http://www.voidspace.org.uk/python/modules.shtml#listquote
2817
.. _Michael Foord: http://www.voidspace.org.uk/index2.shtml
2846
.. _Michael Foord: http://www.voidspace.org.uk/python/weblog/index.shtml
2818
2847
.. _Nicola Larosa: http://www.teknico.net
2819
.. _Mark Andrews: http://www.la-la.com