~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/util/configobj/docs/configobj.txt

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-29 15:57:16 UTC
  • mfrom: (3427.5.9 dep_warnings)
  • Revision ID: pqm@pqm.ubuntu.com-20080529155716-0w3kic8lioa63231
(jam) Enable Deprecation Warnings when running -Werror and when
        running selftest

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
----------------------------------------
8
8
 
9
9
:Authors: Michael Foord, Nicola Larosa
10
 
:Version: ConfigObj 4.2.0
11
 
:Date: 2006/02/16
 
10
:Version: ConfigObj 4.5.2
 
11
:Date: 2008/02/24
12
12
:Homepage: `ConfigObj Homepage`_
13
13
:Sourceforge: Sourceforge_
 
14
:Development: `SVN Repository`_
14
15
:License: `BSD License`_
15
16
:Support: `Mailing List`_
16
17
 
17
18
.. _Mailing List: http://lists.sourceforge.net/lists/listinfo/configobj-develop
 
19
.. _SVN Repository: http://svn.pythonutils.python-hosting.com
18
20
 
19
21
.. meta::
20
22
   :description: ConfigObj - a Python module for easy reading and writing of 
22
24
   :keywords: python, script, module, config, configuration, data, persistence,
23
25
              developer, configparser
24
26
 
 
27
 
25
28
.. contents:: ConfigObj Manual
26
29
.. sectnum::
27
30
 
 
31
 
28
32
Introduction
29
33
============
30
34
 
32
36
file round tripper*. Its main feature is that it is very easy to use, with a
33
37
straightforward programmer's interface and a simple syntax for config files.
34
38
It has lots of other features though :
35
 
 
36
 
.. sidebar:: ConfigObj in Bazaar
37
 
 
38
 
    **ConfigObj** is now used as the config file parser for `Bazaar <http://bazaar-ng.org>`_.
39
 
    
40
 
    Bazaar is *the* Python  distributed {acro;VCS;Version Control System}. 
41
 
    ConfigObj is used to read ``bazaar.conf`` and ``branches.conf``.
42
 
    
43
 
    Other projects that use **ConfigObj** include :
44
 
    
45
 
    * `Planet Plus <http://planetplus.python-hosting.com/>`_
46
 
    
47
 
        A new web application version of `Planet <http://www.planetplanet.org/>`_, 
48
 
        the web aggregator.
49
 
        
50
 
    * `NeuroImaging in Python <http://projects.scipy.org/neuroimaging/ni/wiki>`_
51
 
    
52
 
        BrainSTAT is a project with the ultimate goal to produce a
53
 
        platform-independent python environment for the analysis of brain
54
 
        imaging data.
55
 
        
56
 
    * `Gruik <http://www.tracos.org/gruik/wiki>`_
57
 
    
58
 
        Gruik is a free software network packet sniffer.
59
 
 
 
39
    
60
40
* Nested sections (subsections), to any level
61
41
* List values
62
42
* Multiple line values
67
47
    - repeated sections
68
48
    - and allowing default values
69
49
 
70
 
* All comments in the file are preserved
71
 
* The order of keys/sections is preserved
72
 
* No external dependencies
73
 
* Full unicode support.
 
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)
 
52
* Full Unicode support
74
53
 
75
 
ConfigObj 4 is a complete rewrite of ConfigObj. ConfigObj now has a barrage [#]_
76
 
of doctests built into it, testing almost every feature. Run ``python configobj.py -v``
77
 
to see them in action. Despite the tests, ConfigObj 4 is smaller than version 3
78
 
and has no external dependencies.
79
54
 
80
55
For support and bug reports please use the ConfigObj `Mailing List`_.
81
56
 
82
 
.. hint::
83
 
 
84
 
    ConfigObj provides a convenient API for storing all sorts of data, not just
85
 
    config files. There is an article on using `ConfigObj for Data Persistence`_.
86
 
    
87
 
    The code from that article is available as ConfigPersist.py_.
88
 
 
89
 
.. _ConfigObj for Data Persistence: http://www.voidspace.org.uk/python/articles/configobj_for_data_persistence.shtml
90
 
.. _ConfigPersist.py: http://www.voidspace.org.uk/python/configpersist.html
91
 
 
92
57
 
93
58
Downloading
94
59
===========
95
60
 
96
 
The current version is **4.2.0**, dated 16th February 2006. ConfigObj 4 is
 
61
The current version is **4.5.2**, dated 24th February 2008. ConfigObj 4 is
97
62
now stable. We still expect to pick up a few bugs along the way though [#]_.
98
63
{sm;:-)}
99
64
 
109
74
 
110
75
* configobj.zip_ from Voidspace
111
76
 
112
 
    This also contains validate.py_ , the `API Docs`_ and `this document`_.
 
77
    This also contains validate.py_  and `this document`_.
113
78
 
114
79
* The latest development version can be obtained from the `Subversion
115
80
  Repository`_.
121
86
Documentation
122
87
-------------
123
88
 
124
 
*configobj.zip* contains `this document`_ and full `API Docs`_, generated by
125
 
the EpyDoc_ program.
126
 
 
127
 
* You can view `this document`_ online as the `ConfigObj Homepage`_.
128
 
 
129
 
* You can also browse the `API Docs`_ online.
 
89
*configobj.zip* also contains `this document`_.
 
90
 
 
91
* You can view `this document`_ online at the `ConfigObj Homepage`_.
 
92
 
130
93
 
131
94
Pythonutils
132
95
-----------
135
98
various other useful modules, and is required by many of the `Voidspace Python
136
99
Projects`_.
137
100
 
 
101
 
 
102
Development Version
 
103
-------------------
 
104
 
 
105
It is sometimes possible to get the latest *development version* of ConfigObj
 
106
from the `Subversion Repository <http://svn.pythonutils.python-hosting.com/trunk/pythonutils/>`_.
 
107
 
138
108
.. _configobj.py: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj.py
139
 
.. _configobj.zip: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.2.0.zip
 
109
.. _configobj.zip: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.5.2.zip
140
110
.. _validate.py: http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=validate.py
141
 
.. _API Docs: http://www.voidspace.org.uk/python/configobj-api/
142
111
.. _this document:
143
112
.. _configobj homepage: http://www.voidspace.org.uk/python/configobj.html
144
 
.. _Subversion Repository: http://svn.rest2web.python-hosting.com/branches/configobj4
145
113
.. _Sourceforge: http://sourceforge.net/projects/configobj
146
 
.. _EpyDoc: http://epydoc.sourceforge.net
147
114
.. _pythonutils: http://www.voidspace.org.uk/python/pythonutils.html
148
 
.. _Voidspace Python Projects: http://www.voidspace.org.uk/python
 
115
.. _Voidspace Python Projects: http://www.voidspace.org.uk/python/index.shtml
 
116
 
 
117
 
 
118
 
 
119
ConfigObj in the Real World
 
120
===========================
 
121
    
 
122
**ConfigObj** is widely used. Projects using it include:
 
123
 
 
124
* `Bazaar <http://bazaar-ng.org>`_.
 
125
 
 
126
    Bazaar is a Python distributed {acro;VCS;Version Control System}.
 
127
    ConfigObj is used to read ``bazaar.conf`` and ``branches.conf``.
 
128
 
 
129
* `Turbogears <http://www.turbogears.org/>`_
 
130
 
 
131
    Turbogears is a web application framework.
 
132
 
 
133
* `Chandler <http://chandler.osafoundation.org/>`_
 
134
 
 
135
   A Python and `wxPython <http://www.wxpython.org>`_ 
 
136
   {acro;PIM;Personal Information Manager}, being developed by the 
 
137
   `OSAFoundation <http://www.osafoundation.org/>`_.
 
138
 
 
139
* `matplotlib <http://matplotlib.sourceforge.net/>`_
 
140
 
 
141
        A 2D plotting library.
 
142
 
 
143
* `IPython <http://ipython.scipy.org/moin/>`_
 
144
 
 
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>`_.
 
146
    
 
147
* `Elisa - the Fluendo Mediacenter <http://elisa.fluendo.com/>`_    
 
148
    
 
149
    Elisa is an open source cross-platform media center solution designed to be simple for people not particularly familiar with computers.
149
150
 
150
151
 
151
152
Getting Started
154
155
The outstanding feature of using ConfigObj is simplicity. Most functions can be
155
156
performed with single line commands.
156
157
 
 
158
 
157
159
Reading a Config File
158
160
---------------------
159
161
 
194
196
 
195
197
    {-coloring}
196
198
 
 
199
 
197
200
Writing a Config File
198
201
---------------------
199
202
 
243
246
    Keywords and section names can only be strings [#]_. Attempting to set
244
247
    anything else will raise a ``ValueError``.
245
248
 
 
249
 
246
250
Config Files
247
251
------------
248
252
 
304
308
 
305
309
    {-coloring}
306
310
 
 
311
 
307
312
infile
308
313
------
309
314
 
327
332
  ``filename`` attribute of your ConfigObj will be ``None``. All keys must be
328
333
  strings. In this case, the order of values and sections is arbitrary.
329
334
 
 
335
 
330
336
options
331
337
-------
332
338
 
354
360
    values are not parsed for lists.
355
361
        
356
362
        If ``list_values = False`` then single line values are not quoted or
357
 
        unqouted when reading and writing.
 
363
        unquoted when reading and writing.
358
364
 
359
365
    Changing this value affects whether single line values will be quoted or 
360
366
    not when writing.
380
386
    default.
381
387
 
382
388
    You can set this attribute to change whether string interpolation is done
383
 
    when values are fetched. See the interpolation_ section for more details.
 
389
    when values are fetched. See the `String Interpolation`_ section for more details.
384
390
 
385
391
* 'configspec': ``None``
386
392
 
410
416
    non-string value [#]_ will raise a ``TypeError`` (no type conversion is
411
417
    done by validation).
412
418
 
413
 
* 'indent_type': ``' '``
 
419
* 'indent_type': ``'    '``
414
420
 
415
 
    Indentation is not significant; it can however be present in the output
416
 
    config. Allowable values are: ``''`` (no indentation), ``' '`` (indentation
417
 
    with spaces, fixed at four per level), or ``'\t'`` (indentation with tabs,
418
 
    one tab per level).
 
421
    Indentation is not significant; it can however be present in the input and
 
422
    output config. Any combination of tabs and spaces may be used: the string
 
423
    will be repeated for each level of indentation. Typical values are: ``''``
 
424
    (no indentation), ``'    '`` (indentation with four spaces, the default),
 
425
    ``'\t'`` (indentation with one tab).
419
426
 
420
427
    If this option is not specified, and the ConfigObj is initialised with a
421
428
    dictionary, the indentation used in the output is the default one, that is,
422
 
    spaces.
 
429
    four spaces.
423
430
 
424
431
    If this option is not specified, and the ConfigObj is initialised with a
425
432
    list of lines or a file, the indentation used in the first indented line is
458
465
 
459
466
    ``default_encoding``, if specified, is the encoding used to decode byte
460
467
    strings in the **ConfigObj** before writing. If this is ``None``, then
461
 
    the Python default encoding (``sys.defaultencoding`` - usually ascii) is
 
468
    the Python default encoding (``sys.defaultencoding`` - usually ASCII) is
462
469
    used.
463
470
    
464
471
    For most Western European users, a value of ``latin-1`` is sensible.
468
475
    Any characters in byte-strings that can't be decoded using the
469
476
    ``default_encoding`` will raise a ``UnicodeDecodeError``.
470
477
 
 
478
* 'unrepr': ``False``
 
479
 
 
480
    The ``unrepr`` option reads and writes files in a different mode. This
 
481
    allows you to store and retrieve the basic Python data-types using config
 
482
    files.
 
483
    
 
484
    This uses Python syntax for lists and quoting. See `unrepr mode`_ for the
 
485
    full details.
 
486
 
 
487
* 'write_empty_values': ``False`` 
 
488
 
 
489
    If ``write_empty_values`` is ``True``, empty strings are written as
 
490
    empty values. See `Empty Values`_ for more details.
 
491
 
471
492
 
472
493
Methods
473
494
-------
478
499
 
479
500
In addition, the following `Section Methods`_ may be useful :
480
501
 
481
 
* *encode*
482
 
* *decode*
483
 
* *walk*
484
 
* *merge*
485
 
* *dict* 
486
 
* *as_bool*
487
 
* *as_float*
488
 
* *as_int*
 
502
* 'restore_default'
 
503
* 'restore_defaults'
 
504
* 'walk'
 
505
* 'merge'
 
506
* 'dict'
 
507
* 'as_bool'
 
508
* 'as_float'
 
509
* 'as_int'
489
510
 
490
511
Read about Sections_ for details of all the methods.
491
512
 
498
519
    
499
520
    You would typically use this to create a default ConfigObj and then merge
500
521
    in user settings. This way users only need to specify values that are
501
 
    different from the default.
 
522
    different from the default. You can use configspecs and validation to
 
523
    achieve the same thing of course.
502
524
    
503
525
 
504
526
The public methods available on ConfigObj are :
505
527
 
506
528
* 'write'
507
529
* 'validate'
 
530
* 'reset'
 
531
* 'reload'
 
532
 
508
533
 
509
534
write
510
535
~~~~~
534
559
'final_comment'. Comment lines and inline comments are written with each
535
560
key/value.
536
561
 
 
562
 
537
563
validate
538
564
~~~~~~~~
539
565
 
540
566
::
541
567
 
542
 
    validate(validator, preserve_errors=False)
 
568
    validate(validator, preserve_errors=False, copy=False)
543
569
 
544
570
.. raw:: html
545
571
 
555
581
    test = config.validate(val)
556
582
    if test == True:
557
583
        print 'Succeeded.'
558
 
 
559
584
    {-coloring}
560
585
 
561
586
The validate method uses the `validate 
563
588
validation.
564
589
    
565
590
This method validates the ConfigObj against the configspec. By doing type
566
 
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
567
592
the config *data* to your application (in the types it expects it to be).
568
593
 
569
594
If the ``configspec`` attribute of the ConfigObj is ``None``, it raises a
581
606
 
582
607
.. hint::
583
608
 
584
 
    If your ConfigObj is only comprised of basic data types, then you can use
585
 
    a function from the ConfigPersist.py_ module to auto-generate your
586
 
    configspec.
 
609
    The system of configspecs can seem confusing at first, but is actually
 
610
    quite simple and powerful. For a concrete example of how to use it, you may
 
611
    find this blog entry helpful :
 
612
    `Transforming Values with ConfigObj <http://www.voidspace.org.uk/python/weblog/arch_d7_2006_03_04.shtml#e257>`_.
 
613
 
 
614
 
 
615
The ``copy`` parameter fills in missing values from the configspec (default
 
616
values), *without* marking the values as defaults. It also causes comments to
 
617
be copied from the configspec into the config file. This allows you to use a
 
618
configspec to create default config files. (Normally default values aren't
 
619
written out by the ``write`` method.)
 
620
 
 
621
As of ConfigObj 4.3.0 you can also pass in a ConfigObj instance as your
 
622
configspec. This is especially useful if you need to specify the encoding of
 
623
your configspec file. When you read your configspec file, you *must* specify
 
624
``list_values=False``.
 
625
 
 
626
.. raw:: html
 
627
 
 
628
    {+coloring}
 
629
    from configobj import ConfigObj
 
630
    configspec = ConfigObj(configspecfilename, encoding='UTF8',
 
631
                           list_values=False)
 
632
    config = ConfigObj(filename, configspec=configspec)
 
633
    {-coloring}
587
634
    
588
 
    See `ConfigObj for Data Persistence`_.
589
 
 
590
635
 
591
636
Return Value
592
637
############
658
703
Writing invalid default values is a *guaranteed* way of confusing your users.
659
704
Default values **must** pass the check.
660
705
 
 
706
 
661
707
Mentioning Repeated Sections
662
708
############################
663
709
 
698
744
 
699
745
    {-coloring}
700
746
 
 
747
 
 
748
Mentioning copy Mode
 
749
####################
 
750
 
 
751
As discussed in `Mentioning Default Values`_, you can use a configspec to
 
752
supply default values. These are marked in the ConfigObj instance as defaults,
 
753
and *not* written out by the ``write`` mode. This means that your users only
 
754
need to supply values that are different from the defaults.
 
755
 
 
756
This can be inconvenient if you *do* want to write out the default values,
 
757
for example to write out a default config file.
 
758
 
 
759
If you set ``copy=True`` when you call validate, then no values are marked as
 
760
defaults. In addition, all comments from the configspec are copied into
 
761
your ConfigObj instance. You can then call ``write`` to create your config
 
762
file.
701
763
    
 
764
There is a limitation with this. In order to allow `String Interpolation`_ to work
 
765
within configspecs, ``DEFAULT`` sections are not processed by
 
766
validation; even in copy mode.
 
767
 
 
768
 
 
769
reload
 
770
~~~~~~
 
771
 
 
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).
 
775
 
 
776
If the ConfigObj does not have a filename attribute pointing to a file, then a ``ReloadError`` 
 
777
will be raised.
 
778
 
 
779
 
 
780
reset
 
781
~~~~~
 
782
 
 
783
This method takes no arguments and doesn't return anything. It restores a ConfigObj
 
784
instance to a freshly created state.
 
785
 
 
786
 
702
787
Attributes
703
788
----------
704
789
 
713
798
* list_values
714
799
* encoding
715
800
* default_encoding
 
801
* unrepr
 
802
* write_empty_values
 
803
* newlines
716
804
 
717
805
.. note::
718
806
 
726
814
* create_empty
727
815
* file_error
728
816
 
729
 
interpolate
730
 
~~~~~~~~~~~
 
817
 
 
818
interpolation
 
819
~~~~~~~~~~~~~
731
820
 
732
821
ConfigObj can perform string interpolation in a *similar* way to
733
 
``ConfigParser``. See the interpolation_ section for full details.
 
822
``ConfigParser``. See the `String Interpolation`_ section for full details.
734
823
 
735
 
If ``interpolate`` is set to ``False``, then interpolation is *not* done when
 
824
If ``interpolation`` is set to ``False``, then interpolation is *not* done when
736
825
you fetch values.
737
826
 
 
827
 
738
828
stringify
739
829
~~~~~~~~~
740
830
 
745
835
If stringify is unset (``False``) then attempting to set a value to a non
746
836
string (or a list of strings) will raise a ``TypeError``.
747
837
 
 
838
 
748
839
BOM
749
840
~~~
750
841
 
757
848
 
758
849
For UTF16 encodings, a BOM is *always* written.
759
850
 
 
851
 
760
852
initial_comment
761
853
~~~~~~~~~~~~~~~
762
854
 
767
859
 
768
860
The write method puts these lines before it starts writing out the members.
769
861
 
 
862
 
770
863
final_comment
771
864
~~~~~~~~~~~~~
772
865
 
778
871
The ``write`` method puts these lines after it finishes writing out the
779
872
members.
780
873
 
 
874
 
781
875
list_values
782
876
~~~~~~~~~~~
783
877
 
805
899
        ``list_values=False``. This means that files written by **ConfigObj**
806
900
        *could* now be incompatible - and need the quotes removing by hand.
807
901
 
 
902
 
808
903
encoding
809
904
~~~~~~~~
810
905
 
818
913
~~~~~~~~~~~~~~~~
819
914
 
820
915
If encoding is set, any byte-strings in your ConfigObj instance (keys or
821
 
members) will first be decoded to unicode using the encoding specified by the
 
916
members) will first be decoded to Unicode using the encoding specified by the
822
917
``default_encoding`` attribute. This ensures that the output is in the encoding
823
918
specified.
824
919
 
825
920
If this value is ``None`` then ``sys.defaultencoding`` is used instead.
826
921
 
 
922
 
 
923
unrepr
 
924
~~~~~~
 
925
 
 
926
Another boolean value. If this is set, then ``repr(value)`` is used to write
 
927
values. This writes values in a slightly different way to the normal ConfigObj
 
928
file syntax.
 
929
 
 
930
This preserves basic Python data-types when read back in. See `unrepr mode`_
 
931
for more details.
 
932
 
 
933
 
 
934
write_empty_values
 
935
~~~~~~~~~~~~~~~~~~
 
936
 
 
937
Also boolean. If set, values that are an empty string (``''``) are written as
 
938
empty values. See `Empty Values`_ for more details.
 
939
 
 
940
 
 
941
newlines
 
942
~~~~~~~~
 
943
 
 
944
When a config file is read, ConfigObj records the type of newline separators in the
 
945
file and uses this separator when writing. It defaults to ``None``, and ConfigObj
 
946
uses the system default (``os.sep``) if write is called without newlines having
 
947
been set.
 
948
 
 
949
 
827
950
The Config File Format
828
951
======================
829
952
 
940
1063
 
941
1064
    {+coloring}
942
1065
 
943
 
    {
 
1066
    ConfigObj({
944
1067
        'keyword1': 'value1',
945
1068
        'keyword2': 'value2',
946
1069
        'section 1': {
963
1086
                'keyword2': 'value2',
964
1087
            },
965
1088
        },
966
 
    }
 
1089
    })
967
1090
 
968
1091
    {-coloring}
969
1092
 
970
1093
Sections are ordered: note how the structure of the resulting ConfigObj is in
971
1094
the same order as the original file.
972
1095
 
 
1096
.. note::
 
1097
 
 
1098
    In ConfigObj 4.3.0 *empty values* became valid syntax. They are read as the
 
1099
    empty string. There is also an option/attribute (``write_empty_values``) to
 
1100
    allow the writing of these.
 
1101
    
 
1102
    This is mainly to support 'legacy' config files, written from other
 
1103
    applications. This is documented under `Empty Values`_.
 
1104
    
 
1105
    `unrepr mode`_ introduces *another* syntax variation, used for storing
 
1106
    basic Python datatypes in config files. {sm;:-)}
 
1107
 
 
1108
 
973
1109
Sections
974
1110
========
975
1111
 
1035
1171
 
1036
1172
* 'values'
1037
1173
 
 
1174
 
1038
1175
Section Attributes
1039
1176
------------------
1040
1177
 
1064
1201
    Setting any of these values in the section removes them from the defaults
1065
1202
    list.
1066
1203
 
 
1204
* default_values
 
1205
 
 
1206
    This attribute is a dictionary mapping keys to the default values for the
 
1207
    keys. By default it is an empty dictionary and is populated when you
 
1208
    validate the ConfigObj.
 
1209
 
1067
1210
* scalars, sections
1068
1211
 
1069
1212
    These attributes are normal lists, representing the order that members,
1115
1258
 
1116
1259
    See the validation_ section for full details of how to write configspecs.
1117
1260
 
 
1261
 
1118
1262
Section Methods
1119
1263
---------------
1120
1264
 
1213
1357
    
1214
1358
        In ConfigObj 4.1.0, this method was called ``istrue``. That method is
1215
1359
        now deprecated and will issue a warning when used. It will go away
1216
 
        in the next release.
 
1360
        in a future release.
1217
1361
        
1218
1362
* **as_int**
1219
1363
 
1231
1375
    
1232
1376
    It raises a ``ValueError`` if the conversion can't be done.
1233
1377
    
 
1378
* **restore_default**
 
1379
 
 
1380
    ``restore_default(key)``
 
1381
    
 
1382
    Restore (and return) the default value for the specified key.
 
1383
    
 
1384
    This method will only work for a ConfigObj that was created
 
1385
    with a configspec and has been validated.
 
1386
    
 
1387
    If there is no default value for this key, ``KeyError`` is raised.
 
1388
 
 
1389
* **restore_defaults**
 
1390
    
 
1391
    ``restore_defaults()``
 
1392
 
 
1393
    Recursively restore default values to all members
 
1394
    that have them.
 
1395
    
 
1396
    This method will only work for a ConfigObj that was created
 
1397
    with a configspec and has been validated.
 
1398
    
 
1399
    It doesn't delete or modify entries without default values.
 
1400
 
 
1401
 
1234
1402
Walking a Section
1235
1403
-----------------
1236
1404
 
1409
1577
    #
1410
1578
    cfg.walk(transform, call_on_sections=True)
1411
1579
    print cfg
1412
 
    {'CLIENT1key1': 'CLIENT1value1', 'CLIENT1key2': 'CLIENT1value2', 
 
1580
    ConfigObj({'CLIENT1key1': 'CLIENT1value1', 'CLIENT1key2': 'CLIENT1value2', 
1413
1581
    'CLIENT1key3': 'CLIENT1value3', 
1414
1582
    'CLIENT1section1': {'CLIENT1key1': 'CLIENT1value1', 
1415
1583
        'CLIENT1key2': 'CLIENT1value2', 'CLIENT1key3': 'CLIENT1value3'}, 
1416
1584
    'CLIENT1section2': {'CLIENT1key1': 'CLIENT1value1', 
1417
1585
        'CLIENT1key2': 'CLIENT1value2', 'CLIENT1key3': 'CLIENT1value3', 
1418
1586
        'CLIENT1section1': {'CLIENT1key1': 'CLIENT1value1', 
1419
 
            'CLIENT1key2': 'CLIENT1value2', 'CLIENT1key3': 'CLIENT1value3'}}}
 
1587
            'CLIENT1key2': 'CLIENT1value2', 'CLIENT1key3': 'CLIENT1value3'}}})
1420
1588
            
1421
1589
    {-coloring}
1422
1590
 
1445
1613
    (in a configspec), a ``RepeatSectionError`` will be raised.
1446
1614
 
1447
1615
Number 5 (which is actually two different types of exceptions) is documented
1448
 
    in interpolation_.
 
1616
    in `String Interpolation`_.
1449
1617
 
1450
1618
Number 6 is explained in the validation_ section.
1451
1619
 
1474
1642
 
1475
1643
* ``ConfigspecError``
1476
1644
 
1477
 
    An error occured whilst parsing a configspec.
 
1645
    An error occurred whilst parsing a configspec.
 
1646
 
 
1647
* ``UnreprError``
 
1648
 
 
1649
    An error occurred when parsing a value in `unrepr mode`_.
 
1650
    
 
1651
* ``ReloadError``
 
1652
 
 
1653
    ``reload`` was called on a ConfigObj instance that doesn't have a valid 
 
1654
    filename attribute.
1478
1655
 
1479
1656
When parsing a configspec, ConfigObj will stop on the first error it
1480
1657
encounters.  It will raise a ``ConfigspecError``. This will have an ``error``
1481
1658
attribute, which is the actual error that was raised.
1482
1659
 
1483
 
Behavior when parsing a config file depends on the option ``raise_errors``.
 
1660
Behaviour when parsing a config file depends on the option ``raise_errors``.
1484
1661
If ConfigObj encounters an error while parsing a config file:
1485
1662
 
1486
1663
    If ``raise_errors=True`` then ConfigObj will raise the appropriate error
1489
1666
    If ``raise_errors=False`` (the default) then parsing will continue to the
1490
1667
    end and *all* errors will be collected.
1491
1668
 
1492
 
In the second case a ``ConfigObjError`` is raised after parsing has stopped.
1493
 
The error raised has a ``config`` attribute, which is the parts of the
1494
 
ConfigObj that parsed successfully. It also has an attribute ``errors``, which
1495
 
is a list of *all* the errors raised. Each entry in the list is an instance of
1496
 
the appropriate error type. Each one has the following attributes (useful for
1497
 
delivering a sensible error message to your user) :
 
1669
If ``raise_errors`` is False and multiple errors are found a ``ConfigObjError``
 
1670
is raised. The error raised has a ``config`` attribute, which is the parts of
 
1671
the ConfigObj that parsed successfully. It also has an attribute ``errors``,
 
1672
which is a list of *all* the errors raised. Each entry in the list is an
 
1673
instance of the appropriate error type. Each one has the following attributes
 
1674
(useful for delivering a sensible error message to your user) :
1498
1675
 
1499
1676
* ``line``: the original line that caused the error.
1500
1677
 
1502
1679
 
1503
1680
* ``message``: the error message that accompanied the error.
1504
1681
 
 
1682
If only one error is found, then that error is re-raised. The error still has
 
1683
the ``config`` and ``errors`` attributes. This means that your error handling
 
1684
code can be the same whether one error is raised in parsing , or several.
 
1685
 
 
1686
It also means that in the most common case (a single error) a useful error
 
1687
message will be raised.
 
1688
 
1505
1689
.. note::
1506
1690
 
1507
1691
    One wrongly written line could break the basic structure of your config
1513
1697
Validation
1514
1698
==========
1515
1699
 
 
1700
.. hint::
 
1701
 
 
1702
    The system of configspecs can seem confusing at first, but is actually
 
1703
    quite simple and powerful. For a concrete example of how to use it, you may
 
1704
    find this blog entry helpful :
 
1705
    `Transforming Values with ConfigObj <http://www.voidspace.org.uk/python/weblog/arch_d7_2006_03_04.shtml#e257>`_.
 
1706
 
1516
1707
Validation is done through a combination of the configspec_ and a ``Validator``
1517
1708
object. For this you need *validate.py* [#]_. See downloading_ if you don't
1518
1709
have a copy.
1531
1722
application configuration (boolean, integers, floats, etc) and the text format
1532
1723
of your config file.
1533
1724
 
 
1725
 
1534
1726
configspec
1535
1727
----------
1536
1728
 
1577
1769
    In order to allow this, checks in the 'DEFAULT' section (of the root level
1578
1770
    of your configspec) are *not* used.
1579
1771
 
 
1772
If you need to specify the encoding of your configspec, then you can pass in a
 
1773
ConfigObj instance as your configspec. When you read your configspec file, you
 
1774
*must* specify ``list_values=False``.
 
1775
 
 
1776
.. raw:: html
 
1777
 
 
1778
    {+coloring}
 
1779
    from configobj import ConfigObj
 
1780
    configspec = ConfigObj(configspecfilename, encoding='UTF8',
 
1781
        list_values=False)
 
1782
    config = ConfigObj(filename, configspec=configspec)
 
1783
    {-coloring}
 
1784
 
1580
1785
.. _validate.py documentation: http://www.voidspace.org.uk/python/validate.html
1581
1786
 
 
1787
 
1582
1788
Type Conversion
1583
1789
---------------
1584
1790
 
1593
1799
set the stringify_ attribute to ``False``. If this is the case, attempting to
1594
1800
set a value to a non-string will raise an error.
1595
1801
 
 
1802
 
1596
1803
Default Values
1597
1804
--------------
1598
1805
 
1670
1877
sub-sections. Defaults work in the normal way in repeated sections.
1671
1878
 
1672
1879
 
 
1880
Copy Mode
 
1881
---------
 
1882
 
 
1883
Because you can specify default values in your configspec, you can use
 
1884
ConfigObj to write out default config files for your application.
 
1885
 
 
1886
However, normally values supplied from a default in a configspec are *not*
 
1887
written out by the ``write`` method.
 
1888
 
 
1889
To do this, you need to specify ``copy=True`` when you call validate. As well
 
1890
as not marking values as default, all the comments in the configspec file
 
1891
will be copied into your ConfigObj instance.
 
1892
 
 
1893
.. raw:: html
 
1894
 
 
1895
    {+coloring}
 
1896
    from configobj import ConfigObj
 
1897
    from validate import Validator
 
1898
    vdt = Validator()
 
1899
    config = ConfigObj(configspec='default.ini')
 
1900
    config.filename = 'new_default.ini'
 
1901
    config.validate(vdt, copy=True)
 
1902
    config.write()
 
1903
    {-coloring}
 
1904
 
 
1905
 
1673
1906
Validation and Interpolation
1674
1907
----------------------------
1675
1908
 
1683
1916
overwritten. If validation changes type - the value has to be overwritten, and
1684
1917
any interpolation references are lost {sm;:-(}.
1685
1918
 
 
1919
 
1686
1920
SimpleVal
1687
1921
---------
1688
1922
 
1734
1968
    {-coloring}
1735
1969
 
1736
1970
 
1737
 
Interpolation
1738
 
=============
 
1971
Empty values
 
1972
============
 
1973
 
 
1974
Many config files from other applications allow empty values. As of version
 
1975
4.3.0, ConfigObj will read these as an empty string.
 
1976
 
 
1977
A new option/attribute has been added (``write_empty_values``) to allow
 
1978
ConfigObj to write empty strings as empty values.
 
1979
 
 
1980
.. raw:: html
 
1981
 
 
1982
    {+coloring}
 
1983
    from configobj import ConfigObj
 
1984
    cfg = '''
 
1985
        key =
 
1986
        key2 = # a comment
 
1987
    '''.splitlines()
 
1988
    config = ConfigObj(cfg)
 
1989
    print config
 
1990
    ConfigObj({'key': '', 'key2': ''})
 
1991
    
 
1992
    config.write_empty_values = True
 
1993
    for line in config.write():
 
1994
        print line
 
1995
    
 
1996
    key = 
 
1997
    key2 =     # a comment
 
1998
    {-coloring}
 
1999
 
 
2000
 
 
2001
unrepr mode
 
2002
===========
 
2003
 
 
2004
The ``unrepr`` option allows you to store and retrieve the basic Python
 
2005
data-types using config files. It has to use a slightly different syntax to
 
2006
normal ConfigObj files. Unsurprisingly it uses Python syntax.
 
2007
 
 
2008
This means that lists are different (they are surrounded by square brackets),
 
2009
and strings *must* be quoted.
 
2010
 
 
2011
The types that ``unrepr`` can work with are :
 
2012
 
 
2013
    | strings, lists tuples
 
2014
    | None, True, False
 
2015
    | dictionaries, integers, floats
 
2016
    | longs and complex numbers
 
2017
    
 
2018
You can't store classes, types or instances.
 
2019
 
 
2020
``unrepr`` uses ``repr(object)`` to write out values, so it currently *doesn't*
 
2021
check that you are writing valid objects. If you attempt to read an unsupported
 
2022
value, ConfigObj will raise a ``configobj.UnknownType`` exception.
 
2023
 
 
2024
Values that are triple quoted cased. The triple quotes are removed *before*
 
2025
converting. This means that you can use triple quotes to write dictionaries
 
2026
over several lines in your config files. They won't be written like this
 
2027
though.
 
2028
 
 
2029
If you are writing config files by hand, for use with ``unrepr``, you should
 
2030
be aware of the following differences from normal ConfigObj syntax :
 
2031
 
 
2032
    | List : ``['A List', 'With', 'Strings']``
 
2033
    | Strings : ``"Must be quoted."``
 
2034
    | Backslash : ``"The backslash must be escaped \\"``
 
2035
 
 
2036
These all follow normal Python syntax.
 
2037
 
 
2038
In unrepr mode *inline comments* are not saved. This is because lines are
 
2039
parsed using the `compiler package <http://docs.python.org/lib/compiler.html>`_
 
2040
which discards comments.
 
2041
 
 
2042
 
 
2043
String Interpolation
 
2044
====================
1739
2045
 
1740
2046
ConfigObj allows string interpolation *similar* to the way ``ConfigParser``
1741
 
 
1742
 
You specify a value to be substituted by including ``%(name)s`` in the value.
1743
 
 
1744
 
Interpolation checks first the 'DEFAULT' sub-section of the current section to
1745
 
see if ``name`` is the key to a value. ('name' is case sensitive).
1746
 
 
1747
 
If it doesn't find it, next it checks the 'DEFAULT' section of the parent
1748
 
section, last it checks the 'DEFAULT' section of the main section.
1749
 
 
1750
 
If the value specified isn't found then a ``MissingInterpolationOption`` error
1751
 
is raised (a subclass of ``ConfigObjError``).
 
2047
or ``string.Template`` work. The value of the ``interpolation`` attribute
 
2048
determines which style of interpolation you want to use. Valid values are
 
2049
"ConfigParser" or "Template" (case-insensitive, so "configparser" and
 
2050
"template" will also work). For backwards compatibility reasons, the value
 
2051
``True`` is also a valid value for the ``interpolation`` attribute, and
 
2052
will select ``ConfigParser``-style interpolation. At some undetermined point
 
2053
in the future, that default *may* change to ``Template``-style interpolation.
 
2054
 
 
2055
For ``ConfigParser``-style interpolation, you specify a value to be
 
2056
substituted by including ``%(name)s`` in the value.
 
2057
 
 
2058
For ``Template``-style interpolation, you specify a value to be substituted
 
2059
by including ``${cl}name{cr}`` in the value. Alternately, if 'name' is a valid
 
2060
Python identifier (i.e., is composed of nothing but alphanumeric characters,
 
2061
plus the underscore character), then the braces are optional and the value
 
2062
can be written as ``$name``.
 
2063
 
 
2064
Note that ``ConfigParser``-style interpolation and ``Template``-style
 
2065
interpolation are mutually exclusive; you cannot have a configuration file
 
2066
that's a mix of one or the other. Pick one and stick to it. ``Template``-style
 
2067
interpolation is simpler to read and write by hand, and is recommended if
 
2068
you don't have a particular reason to use ``ConfigParser``-style.
 
2069
 
 
2070
Interpolation checks first the current section to see if ``name`` is the key
 
2071
to a value. ('name' is case sensitive).
 
2072
 
 
2073
If it doesn't find it, next it checks the 'DEFAULT' sub-section of the current
 
2074
section.
 
2075
 
 
2076
If it still doesn't find it, it moves on to check the parent section and the
 
2077
parent section's 'DEFAULT' subsection, and so on all the way up to the main
 
2078
section.
 
2079
 
 
2080
If the value specified isn't found in any of these locations, then a
 
2081
``MissingInterpolationOption`` error is raised (a subclass of
 
2082
``ConfigObjError``).
1752
2083
 
1753
2084
If it is found then the returned value is also checked for substitutions. This
1754
2085
allows you to make up compound values (for example directory paths) that use
1755
2086
more than one default value. It also means it's possible to create circular
1756
 
references. If after ten replacements there are still values to substitute, an
1757
 
``InterpolationDepthError`` is raised.
 
2087
references. If there are any circular references which would cause an infinite
 
2088
interpolation loop, an ``InterpolationLoopError`` is raised.
1758
2089
 
1759
2090
Both of these errors are subclasses of ``InterpolationError``, which is a
1760
2091
subclass of ``ConfigObjError``.
1806
2137
failed.
1807
2138
 
1808
2139
``flatten_errors`` is an example function that turns a results dictionary into
1809
 
a flat list, that only contains vaues that *failed*.
 
2140
a flat list, that only contains values that *failed*.
1810
2141
 
1811
2142
``cfg`` is the ConfigObj instance being checked, ``res`` is the results
1812
2143
dictionary returned by ``validate``.
1863
2194
 
1864
2195
    {-coloring}
1865
2196
 
1866
 
Backwards Compatibility
1867
 
=======================
1868
 
 
1869
 
There have been a lot of changes since ConfigObj 3. The core parser is now
1870
 
based on regular expressions, and is a lot faster and smaller. There is now no
1871
 
difference in the way we treat flat files and non-flatfiles, that is, no empty
1872
 
sections. This means some of the code can be a lot simpler, less code does
1873
 
more of the work [#]_.
1874
 
 
1875
 
There have been other simplifications: for example we only have eight options
1876
 
instead of seventeen.
1877
 
 
1878
 
Most config files created for ConfigObj 3 will be read with no changes and many
1879
 
programs will work without having to alter code. Some of the changes do break
1880
 
backwards compatibility: for example, code that uses the previous options will
1881
 
now raise an error. It should be very easy to fix these, though.
1882
 
 
1883
 
Below is a list of all the changes that affect backwards compatibility. This
1884
 
doesn't include details of method signatures that have changed, because almost
1885
 
all of them have.
1886
 
 
1887
 
Incompatible Changes
1888
 
--------------------
1889
 
 
1890
 
(I have removed a lot of needless complications: this list is probably not
1891
 
conclusive, many option/attribute/method names have changed.)
1892
 
 
1893
 
Case sensitive.
1894
 
 
1895
 
The only valid divider is '='.
1896
 
 
1897
 
Line continuations with ``\`` removed.
1898
 
 
1899
 
No recursive lists in values.
1900
 
 
1901
 
No empty sections.
1902
 
 
1903
 
No distinction between flatfiles and non flatfiles.
1904
 
 
1905
 
Change in list syntax: use commas to indicate list, not parentheses (square
1906
 
brackets and parentheses are no longer recognised as lists).
1907
 
 
1908
 
';' is no longer valid for comments, and no multiline comments.
1909
 
 
1910
 
No attribute-style access to values.
1911
 
 
1912
 
Empty values not allowed: use '' or "".
1913
 
 
1914
 
In ConfigObj 3, setting a non-flatfile member to ``None`` would initialise it
1915
 
as an empty section.
1916
 
 
1917
 
The escape entities '&mjf-lf;' and '&mjf-quot;' have gone, replaced by triple
1918
 
quote, multiple line values.
1919
 
 
1920
 
The ``newline``, ``force_return``, and ``default`` options have gone.
1921
 
 
1922
 
``fileerror`` and ``createempty`` options have become ``file_error`` and
1923
 
``create_empty``.
1924
 
 
1925
 
Partial configspecs (for specifying the order members should be written out,
1926
 
and which should be present) have gone. The configspec is no longer used to
1927
 
specify order for the ``write`` method.
1928
 
 
1929
 
Exceeding the maximum depth of recursion in string interpolation now raises an
1930
 
error ``InterpolationDepthError``.
1931
 
 
1932
 
Specifying a value for interpolation which doesn't exist now raises a
1933
 
``MissingInterpolationOption`` error (instead of merely being ignored).
1934
 
 
1935
 
The ``writein`` method has been removed.
1936
 
 
1937
 
The comments attribute is now a list (``inline_comments`` equates to the old
1938
 
comments attribute).
1939
2197
 
1940
2198
ConfigObj 3
1941
 
-----------
 
2199
===========
1942
2200
 
1943
2201
ConfigObj 3 is now deprecated in favour of ConfigObj 4. I can fix bugs in
1944
2202
ConfigObj 3 if needed, though.
1960
2218
Particularly thanks to Nicola Larosa for help on the config file spec, the
1961
2219
validation system and the doctests.
1962
2220
 
1963
 
*validate.py* was originally written by Michael Foord and `Mark Andrews`_.
 
2221
*validate.py* was originally written by Michael Foord and Mark Andrews.
1964
2222
 
1965
2223
Thanks to others for input and bugfixes.
1966
2224
 
1974
2232
Of course if it does, let us know and we'll fix the problem so it doesn't
1975
2233
happen to anyone else {sm;:-)}. ::
1976
2234
 
1977
 
    Copyright (c) 2004 - 2006, Michael Foord & Nicola Larosa
 
2235
    Copyright (c) 2004 - 2008, Michael Foord & Nicola Larosa
1978
2236
    All rights reserved.
1979
2237
 
1980
2238
    Redistribution and use in source and binary forms, with or without
2014
2272
TODO
2015
2273
====
2016
2274
 
2017
 
Fix any bugs (and resolvable issues).
2018
 
 
2019
 
Do an example for the 'walk' which removes uniform indentation in multiline
2020
 
values.
2021
 
 
2022
 
When initialising a section from a ConfigObj *or* an ``OrderedDictionary``
2023
 
we could preserve ordering.
2024
 
 
2025
 
Add an *odict* method which returns an ``OrderedDictionary``.
 
2275
Better support for configuration from multiple files, including tracking
 
2276
*where* the original file came from and writing changes to the correct
 
2277
file.
 
2278
 
 
2279
Make ``newline`` an option (as well as an attribute) ?
 
2280
 
 
2281
``UTF16`` encoded files, when returned as a list of lines, will have the
 
2282
BOM at the start of every line. Should this be removed from all but the
 
2283
first line ?
 
2284
 
 
2285
Option to set warning type for unicode decode ? (Defaults to strict).
 
2286
 
 
2287
A method to optionally remove uniform indentation from multiline values.
 
2288
(do as an example of using ``walk`` - along with string-escape)
 
2289
 
 
2290
Should the results dictionary from validate be an ordered dictionary if
 
2291
`odict <http://www.voidspace.org.uk/python/odict.html>`_ is available ?
 
2292
 
 
2293
Implement some of the sequence methods (which include slicing) from the
 
2294
newer ``odict`` ?
 
2295
 
 
2296
Preserve line numbers of values (and possibly the original text of each value).
2026
2297
 
2027
2298
 
2028
2299
ISSUES
2033
2304
    Please file any bug reports to `Michael Foord`_ or the **ConfigObj**
2034
2305
    `Mailing List`_.
2035
2306
 
2036
 
You can't have a keyword with the same name as a section (in the same section).
2037
 
They are both dictionary keys, so they would overlap.
2038
 
 
2039
 
Interpolation checks first the 'DEFAULT' sub-section of the current section,
2040
 
next it checks the 'DEFAULT' section of the parent section, last it checks the
2041
 
'DEFAULT' section of the main section.
2042
 
 
2043
 
Logically a 'DEFAULT' section should apply to all subsections of the *same
2044
 
parent*: this means that checking the 'DEFAULT' sub-section in the *current
2045
 
section* is not necessarily logical ?
2046
 
 
2047
 
Does it matter that we don't support the ':' divider, which is supported by
2048
 
``ConfigParser`` ?
2049
 
 
2050
 
String interpolation and validation don't play well together. See 
2051
 
`Validation and Interpolation`_.
2052
 
 
2053
 
Validation is no longer done on the 'DEFAULT' section (on the root level). This
2054
 
allows interpolation from within your configspec - but also prevents you
2055
 
validating the 'DEFAULT' section.
 
2307
There is currently no way to specify the encoding of a configspec file.
 
2308
 
 
2309
When using ``copy`` mode for validation, it won't copy ``DEFAULT``
 
2310
sections. This is so that you *can* use interpolation in configspec
 
2311
files.
 
2312
 
 
2313
``validate`` doesn't report *extra* values or sections.
 
2314
 
 
2315
You can't have a keyword with the same name as a section (in the same
 
2316
section). They are both dictionary keys - so they would overlap.
 
2317
 
 
2318
ConfigObj doesn't quote and unquote values if ``list_values=False``.
 
2319
This means that leading or trailing whitespace in values will be lost when
 
2320
writing. (Unless you manually quote).
 
2321
 
 
2322
Interpolation checks first the current section, then the 'DEFAULT' subsection
 
2323
of the current section, before moving on to the current section's parent and
 
2324
so on up the tree.
 
2325
 
 
2326
Does it matter that we don't support the ':' divider, which is supported
 
2327
by ``ConfigParser`` ?
 
2328
 
 
2329
String interpolation and validation don't play well together. When
 
2330
validation changes type it sets the value. This will correctly fetch the
 
2331
value using interpolation - but then overwrite the interpolation reference.
 
2332
If the value is unchanged by validation (it's a string) - but other types
 
2333
will be.
2056
2334
 
2057
2335
 
2058
2336
CHANGELOG
2059
2337
=========
2060
2338
 
2061
2339
This is an abbreviated changelog showing the major releases up to version 4.
2062
 
From version 4 it lists all releases and changes. *More* data on individual
2063
 
changes may be found in the source code.
 
2340
From version 4 it lists all releases and changes.
 
2341
 
 
2342
 
 
2343
2008/02/05 - Version 4.5.2
 
2344
--------------------------
 
2345
 
 
2346
Distribution updated to include version 0.3.2 of validate_. This means that
 
2347
``None`` as a default value win configspecs works.
 
2348
 
 
2349
 
 
2350
2008/02/05 - Version 4.5.1
 
2351
--------------------------
 
2352
 
 
2353
Distribution updated to include version 0.3.1 of validate_. This means that
 
2354
Unicode configspecs now work.
 
2355
 
 
2356
 
 
2357
2008/02/05 - Version 4.5.0
 
2358
--------------------------
 
2359
 
 
2360
ConfigObj will now guarantee that files will be written terminated with a
 
2361
newline.
 
2362
 
 
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 
 
2365
faster to import.
 
2366
 
 
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.
 
2372
 
 
2373
BUGFIX: Proper quoting of keys, values and list values that contain hashes 
 
2374
(when writing).  When ``list_values=False``, values containing hashes are 
 
2375
triple quoted.
 
2376
 
 
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.
 
2380
 
 
2381
BUGFIX: Files are read in with 'rb' mode, so that native/non-native line endings work!
 
2382
 
 
2383
Minor efficiency improvement in ``unrepr`` mode.
 
2384
 
 
2385
Added missing docstrings for some overidden dictionary methods.
 
2386
 
 
2387
Added the ``reset`` method. This restores a ConfigObj to a freshly created state.
 
2388
 
 
2389
Removed old CHANGELOG file.
 
2390
 
 
2391
 
 
2392
2007/02/04 - Version 4.4.0
 
2393
--------------------------
 
2394
 
 
2395
Official release of 4.4.0
 
2396
 
 
2397
 
 
2398
2006/12/17 - Version 4.3.3-alpha4
 
2399
---------------------------------
 
2400
 
 
2401
By Nicola Larosa
 
2402
 
 
2403
Allowed arbitrary indentation in the ``indent_type`` parameter, removed the
 
2404
``NUM_INDENT_SPACES`` and ``MAX_INTERPOL_DEPTH`` (a leftover) constants,
 
2405
added indentation tests (including another docutils workaround, sigh), updated
 
2406
the documentation.
 
2407
 
 
2408
By Michael Foord
 
2409
 
 
2410
Made the import of ``compiler`` conditional so that ``ConfigObj`` can be used
 
2411
with `IronPython <http://www.codeplex.com/IronPython>`_.
 
2412
 
 
2413
 
 
2414
2006/12/17 - Version 4.3.3-alpha3
 
2415
---------------------------------
 
2416
 
 
2417
By Nicola Larosa
 
2418
 
 
2419
Added a missing ``self.`` in the _handle_comment method and a related test,
 
2420
per Sourceforge bug #1523975.
 
2421
 
 
2422
 
 
2423
2006/12/09 - Version 4.3.3-alpha2
 
2424
---------------------------------
 
2425
 
 
2426
By Nicola Larosa
 
2427
 
 
2428
Changed interpolation search strategy, based on this patch by Robin Munn:
 
2429
http://sourceforge.net/mailarchive/message.php?msg_id=17125993
 
2430
 
 
2431
 
 
2432
2006/12/09 - Version 4.3.3-alpha1
 
2433
---------------------------------
 
2434
 
 
2435
By Nicola Larosa
 
2436
 
 
2437
Added Template-style interpolation, with tests, based on this patch by
 
2438
Robin Munn: http://sourceforge.net/mailarchive/message.php?msg_id=17125991
 
2439
(awful archives, bad Sourceforge, bad).
 
2440
 
 
2441
 
 
2442
2006/06/04 - Version 4.3.2
 
2443
--------------------------
 
2444
 
 
2445
Changed error handling, if parsing finds a single error then that error will
 
2446
be re-raised. That error will still have an ``errors`` and a ``config``
 
2447
attribute.
 
2448
 
 
2449
Fixed bug where '\\n' terminated files could be truncated.
 
2450
 
 
2451
Bugfix in ``unrepr`` mode, it couldn't handle '#' in values. (Thanks to
 
2452
Philippe Normand for the report.)
 
2453
 
 
2454
As a consequence of this fix, ConfigObj doesn't now keep inline comments in
 
2455
``unrepr`` mode. This is because the parser in the `compiler package`_
 
2456
doesn't keep comments. {sm;:-)}
 
2457
 
 
2458
Error messages are now more useful. They tell you the number of parsing errors
 
2459
and the line number of the first error. (In the case of multiple errors.)
 
2460
 
 
2461
Line numbers in exceptions now start at 1, not 0.
 
2462
 
 
2463
Errors in ``unrepr`` mode are now handled the same way as in the normal mode.
 
2464
The errors stored will be an ``UnreprError``.
 
2465
 
 
2466
 
 
2467
2006/04/29 - Version 4.3.1
 
2468
--------------------------
 
2469
 
 
2470
Added ``validate.py`` back into ``configobj.zip``. (Thanks to Stewart
 
2471
Midwinter)
 
2472
 
 
2473
Updated to `validate.py`_ 0.2.2.
 
2474
 
 
2475
Preserve tuples when calling the ``dict`` method. (Thanks to Gustavo Niemeyer.)
 
2476
 
 
2477
Changed ``__repr__`` to return a string that contains ``ConfigObj({ ... })``.
 
2478
 
 
2479
Change so that an options dictionary isn't modified by passing it to ConfigObj.
 
2480
(Thanks to Artarious.)
 
2481
 
 
2482
Added ability to handle negative integers in ``unrepr``. (Thanks to Kevin
 
2483
Dangoor.)
 
2484
 
 
2485
 
 
2486
2006/03/24 - Version 4.3.0
 
2487
--------------------------
 
2488
 
 
2489
Moved the tests and the CHANGELOG (etc) into a separate file. This has reduced
 
2490
the size of ``configobj.py`` by about 40%.
 
2491
 
 
2492
Added the ``unrepr`` mode to reading and writing config files. Thanks to Kevin
 
2493
Dangoor for this suggestion.
 
2494
 
 
2495
Empty values are now valid syntax. They are read as an empty string ``''``.
 
2496
(``key =``, or ``key = # comment``.)
 
2497
 
 
2498
``validate`` now honours the order of the configspec.
 
2499
 
 
2500
Added the ``copy`` mode to validate. Thanks to Louis Cordier for this
 
2501
suggestion.
 
2502
 
 
2503
Fixed bug where files written on windows could be given ``'\r\r\n'`` line
 
2504
terminators.
 
2505
 
 
2506
Fixed bug where last occurring comment line could be interpreted as the
 
2507
final comment if the last line isn't terminated.
 
2508
 
 
2509
Fixed bug where nested list values would be flattened when ``write`` is
 
2510
called. Now sub-lists have a string representation written instead.
 
2511
 
 
2512
Deprecated ``encode`` and ``decode`` methods instead.
 
2513
 
 
2514
You can now pass in a ConfigObj instance as a configspec (remember to read
 
2515
the configspec file using ``list_values=False``).
 
2516
 
 
2517
Sorted footnotes in the docs.
 
2518
 
2064
2519
 
2065
2520
2006/02/16 - Version 4.2.0
2066
2521
--------------------------
2068
2523
Removed ``BOM_UTF8`` from ``__all__``.
2069
2524
 
2070
2525
The ``BOM`` attribute has become a boolean. (Defaults to ``False``.) It is
2071
 
*only* ``True`` for the ``UTF16`` encoding.
 
2526
*only* ``True`` for the ``UTF16/UTF8`` encodings.
2072
2527
 
2073
2528
File like objects no longer need a ``seek`` attribute.
2074
2529
 
2086
2541
written out at the start of the file. (It will normally only be ``True`` if
2087
2542
the utf8 BOM was found when the file was read.)
2088
2543
 
 
2544
Thanks to Aaron Bentley for help and testing on the unicode issues.
 
2545
 
2089
2546
File paths are *not* converted to absolute paths, relative paths will
2090
2547
remain relative as the ``filename`` attribute.
2091
2548
 
2096
2553
 
2097
2554
Added ``as_int`` and ``as_float``.
2098
2555
 
 
2556
 
2099
2557
2005/12/14 - Version 4.1.0
2100
2558
--------------------------
2101
2559
 
2114
2572
 
2115
2573
Also use the new list syntax in validate_ 0.2.1. (For configspecs).
2116
2574
 
 
2575
 
2117
2576
2005/12/02 - Version 4.0.2
2118
2577
--------------------------
2119
2578
 
2145
2604
 
2146
2605
Obscure typo/bug fixed in ``write``. Wouldn't have affected anyone though.
2147
2606
 
 
2607
 
2148
2608
2005/09/09 - Version 4.0.0 beta 5
2149
2609
---------------------------------
2150
2610
 
2154
2614
 
2155
2615
Fixed bug with commas in comments. (matched as a list value)
2156
2616
 
 
2617
 
2157
2618
2005/09/07 - Version 4.0.0 beta 4
2158
2619
---------------------------------
2159
2620
 
2164
2625
 
2165
2626
Changed the mailing list address.
2166
2627
 
 
2628
 
2167
2629
2005/08/28 - Version 4.0.0 beta 3
2168
2630
---------------------------------
2169
2631
 
2170
2632
Interpolation is switched off before writing out files.
2171
2633
 
2172
2634
Fixed bug in handling ``StringIO`` instances. (Thanks to report from
2173
 
"Gustavo Niemeyer" <gustavo@niemeyer.net>)
 
2635
Gustavo Niemeyer.)
2174
2636
 
2175
2637
Moved the doctests from the ``__init__`` method to a separate function.
2176
2638
(For the sake of IDE calltips).
2177
2639
 
 
2640
 
2178
2641
2005/08/25 - Version 4.0.0 beta 2
2179
2642
---------------------------------
2180
2643
 
2181
2644
Amendments to *validate.py*.
2182
2645
 
2183
 
Official release.
 
2646
First public release.
 
2647
 
2184
2648
 
2185
2649
2005/08/21 - Version 4.0.0 beta 1
2186
2650
---------------------------------
2203
2667
 
2204
2668
Improved error handling.
2205
2669
 
2206
 
Plus lots of other improvements {sm;:grin:}.
 
2670
Plus lots of other improvements. {sm;:grin:}
 
2671
 
2207
2672
 
2208
2673
2004/05/24 - Version 3.0.0
2209
2674
--------------------------
2256
2721
 
2257
2722
Charmap is now incorporated into ConfigObj.
2258
2723
 
 
2724
 
2259
2725
2004/03/14 - Version 2.0.0 beta
2260
2726
-------------------------------
2261
2727
 
2265
2731
The config object now behaves like a dictionary.
2266
2732
 
2267
2733
I've completely broken the interface, but I don't think anyone was really
2268
 
 using it anyway.
 
2734
using it anyway.
2269
2735
 
2270
 
This new version is much more 'classy' {sm;:wink:}
 
2736
This new version is much more 'classy'. {sm;:wink:}
2271
2737
 
2272
2738
It will also read straight from/to a filename and completely parse a config
2273
2739
file without you *having* to supply a config spec.
2277
2743
No longer has getval and setval methods: use normal dictionary methods, or add
2278
2744
and delete.
2279
2745
 
 
2746
 
2280
2747
2004/01/29 - Version 1.0.5
2281
2748
--------------------------
2282
2749
 
2288
2755
 
2289
2756
A couple of bugs have been fixed.
2290
2757
 
 
2758
 
2291
2759
Origins
2292
2760
-------
2293
2761
 
2294
2762
ConfigObj originated in a set of functions for reading config files in the
2295
 
atlantibots_ project. The original functions were written by Rob McNeur...
 
2763
`atlantibots <http://www.voidspace.org.uk/atlantibots/>`_ project. The original
 
2764
functions were written by Rob McNeur.
2296
2765
 
2297
 
.. _atlantibots: http://www.voidspace.org.uk/atlantibots
2298
2766
 
2299
2767
----------
2300
2768
 
 
2769
 
2301
2770
Footnotes
2302
2771
=========
2303
2772
 
2304
 
.. [#] 253 of them, at the time of writing.
2305
 
 
2306
2773
.. [#] And if you discover any bugs, let us know. We'll fix them quickly.
2307
2774
 
2308
2775
.. [#] If you specify a filename that doesn't exist, ConfigObj will assume you
2309
2776
    are creating a new one. See the *create_empty* and *file_error* options_.
2310
2777
 
2311
 
.. [#] They can be byte strings ('ordinary' strings) or Unicode.
 
2778
.. [#] They can be byte strings (*ordinary* strings) or Unicode.
 
2779
 
 
2780
.. [#] Except we don't support the RFC822 style line continuations, nor ':' as
 
2781
    a divider.
2312
2782
 
2313
2783
.. [#] This is a change in ConfigObj 4.2.0. Note that ConfigObj doesn't call
2314
2784
    the seek method of any file like object you pass in. You may want to call
2315
2785
    ``file_object.seek(0)`` yourself, first.
2316
2786
 
2317
 
.. [#] Except we don't support the RFC822 style line continuations, nor ':' as
2318
 
    a divider.
2319
 
 
2320
 
.. [#] For a file object that will depend what mode it was opened with. You
2321
 
    can read *and* write to a ``StringIO`` instance, but not always to a
2322
 
    ``cStringIO`` instance.
2323
 
 
2324
2787
.. [#] A side effect of this is that it enables you to copy a ConfigObj :
2325
2788
 
2326
2789
    .. raw:: html
2335
2798
 
2336
2799
    The order of values and sections will not be preserved, though.
2337
2800
 
 
2801
.. [#] Other than lists of strings.
 
2802
 
2338
2803
.. [#] The exception is if it detects a ``UTF16`` encoded file which it
2339
2804
    must decode before parsing.
2340
2805
     
2341
 
.. [#] Other than lists of strings.
2342
 
 
2343
 
.. [#] The method signature in the API docs will show that this method takes
 
2806
.. [#] The method signature shows that this method takes
2344
2807
    two arguments. The second is the section to be written. This is because the
2345
2808
    ``write`` method is called recursively.
2346
2809
 
2355
2818
 
2356
2819
.. [#] Minimum required version of *validate.py* 0.2.0 .
2357
2820
 
2358
 
.. [#] There's nothing to stop you decoding the whole config file to Unicode
2359
 
    *first*.
2360
 
 
2361
 
.. [#] It also makes ConfigObj a lot simpler to *use*.
2362
2821
 
2363
2822
.. note::
2364
2823
 
2366
2825
    textmacros module and the PySrc CSS stuff. See
2367
2826
    http://www.voidspace.org.uk/python/firedrop2/textmacros.shtml
2368
2827
 
 
2828
 
2369
2829
.. raw:: html
2370
2830
 
2371
2831
    <div align="center">
2372
 
        <a href="http://sourceforge.net/donate/index.php?group_id=123265">
2373
 
            <img src="http://images.sourceforge.net/images/project-support.jpg" width="88" height="32" border="0" alt="Support This Project" /> 
2374
 
        </a>
2375
 
        <a href="http://sourceforge.net">
2376
 
            <img src="http://sourceforge.net/sflogo.php?group_id=123265&amp;type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" />
2377
 
        </a>
2378
 
        <br />
2379
 
        <a href="http://www.python.org">
2380
 
            <img src="images/powered_by_python.jpg" width="602" height="186" border="0" />
2381
 
        </a><br /><br />
2382
 
        <a href="http://www.opensource.org">
2383
 
            <img src="images/osi-certified-120x100.gif" width="120" height="100" border="0" />
2384
 
            <br /><strong>Certified Open Source</strong>
2385
 
        </a>
2386
 
        <br /><br />
2387
 
        <script type="text/javascript" language="JavaScript">var site="s16atlantibots"</script>
2388
 
        <script type="text/javascript" language="JavaScript1.2" src="http://s16.sitemeter.com/js/counter.js?site=s16atlantibots"></script>
2389
 
        <noscript>
2390
 
            <a href="http://s16.sitemeter.com/stats.asp?site=s16atlantibots">
2391
 
                <img src="http://s16.sitemeter.com/meter.asp?site=s16atlantibots" alt="Site Meter" border=0 />
2392
 
            </a>
2393
 
        </noscript>
 
2832
        <p>
 
2833
            <a href="http://www.python.org">
 
2834
                <img src="images/new_python.gif" width="100" height="103" border="0" 
 
2835
                    alt="Powered by Python" />
 
2836
            </a>
 
2837
            <a href="http://sourceforge.net">
 
2838
                <img src="http://sourceforge.net/sflogo.php?group_id=123265&amp;type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" />
 
2839
            </a>
 
2840
            <a href="http://www.opensource.org">
 
2841
                <img src="images/osi-certified-120x100.gif" width="120" height="100" border="0"
 
2842
                    alt="Certified Open Source"/>
 
2843
            </a>
 
2844
        </p>
 
2845
        <p>
 
2846
            <a href="http://www.voidspace.org.uk/python/index.shtml">
 
2847
                <img src="images/pythonbanner.gif" width="468" height="60" 
 
2848
                alt="Python on Voidspace" border="0" />
 
2849
            </a>
 
2850
        </p>
 
2851
 
2394
2852
    </div>
2395
2853
 
2396
2854
.. _listquote: http://www.voidspace.org.uk/python/modules.shtml#listquote
2397
 
.. _Michael Foord: http://www.voidspace.org.uk/index2.shtml
 
2855
.. _Michael Foord: http://www.voidspace.org.uk/python/weblog/index.shtml
2398
2856
.. _Nicola Larosa: http://www.teknico.net
2399
 
.. _Mark Andrews: http://www.la-la.com