Thu, 20 Oct 2016 18:55:14 +0200
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
5255
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a ConfigParser wrapper for Python 2 to provide the |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | dictionary like interface of the Python 3 variant. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | from __future__ import unicode_literals |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | try: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | from configparser import ConfigParser as E5ConfigParser |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | except ImportError: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | # Py2 part with the compatibility wrapper class |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | import itertools |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | from ConfigParser import SafeConfigParser, DEFAULTSECT |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | class E5ConfigParser(SafeConfigParser): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | Class implementing a wrapper of the ConfigParser class implementing |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | dictionary like special methods. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | def __getitem__(self, key): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | Special method to get a section. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | @param key name of the section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | @type str |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | @return section for the given key |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | @rtype dict |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | @exception KeyError raised if a non-existent key is given |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | if key == DEFAULTSECT: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | return self._defaults |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | elif self.has_section(key): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | return self._sections[key] |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | else: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | raise KeyError(key) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | def __setitem__(self, key, values): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | Special method to set the values of a section. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | @param key name of the section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | @type str |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | @param values value for the section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | @type dict |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | # To conform with the mapping protocol, overwrites existing values |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | # in the section. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | if key == DEFAULTSECT: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | self._defaults.clear() |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | elif self.has_section(key): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | self._sections[key].clear() |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | else: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | self.add_section(key) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | for subkey, value in values.items(): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | subkey = self.optionxform(str(subkey)) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | if value is not None: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | value = str(value) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | self.set(key, subkey, value) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | def __delitem__(self, key): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | Special method to delete a section. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | @param key name of the section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | @type str |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | @exception ValueError raised to indicate non-removal of the |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | default section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | @exception KeyError raised to indicate a non-existent section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | if key == DEFAULTSECT: |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | raise ValueError("Cannot remove the default section.") |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | if not self.has_section(key): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | raise KeyError(key) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | self.remove_section(key) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | def __contains__(self, key): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | Special method to test, if a section is contained in the config. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | @param key name of the section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | @type str |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | @return flag indicating containment |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | @rtype bool |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | return key == DEFAULTSECT or self.has_section(key) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | def __len__(self): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | Special method get the number of sections of the config. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | @return number of sections |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | @rtype int |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | return len(self._sections) + 1 # the default section |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | def __iter__(self): |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | Special method to return an iterator of the section names starting |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | with the default section. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | @return iterator of the section names contained in the config |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | @rtype iterator of str |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | """ |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | return itertools.chain((DEFAULTSECT,), self._sections.keys()) |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | if __name__ == "__main__": |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | # This is some test code. |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | import sys |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | c = E5ConfigParser() |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | c["DEFAULT"] = {'ServerAliveInterval': '45', |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | 'Compression': 'yes', |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | 'CompressionLevel': '9'} |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | c['bitbucket.org'] = {} |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | c['bitbucket.org']['User'] = 'hg' |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | c['topsecret.server.com'] = {} |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | topsecret = c['topsecret.server.com'] |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | topsecret['Port'] = '50022' |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | topsecret['ForwardX11'] = 'no' |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | c['DEFAULT']['ForwardX11'] = 'yes' |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | |
5fc76ccd369e
Added a config parser class to implement the dictionary interface for the Python 2 config parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | c.write(sys.stdout) |