11"""
2- Parse INI files.
2+ Inirama is a python module that parses INI files.
33
4+ .. include:: ../README.rst
5+ :start-line: 5
6+ :end-line: 12
7+
8+ :copyright: 2013 by Kirill Klenov.
9+ :license: BSD, see LICENSE for more details.
410"""
5- from __future__ import absolute_import
11+ from __future__ import unicode_literals , print_function
612
713import io
814import re
915import logging
1016from collections import MutableMapping
1117try :
1218 from collections import OrderedDict
13- except ImportError as e :
19+ except ImportError :
1420 from ordereddict import OrderedDict
1521
1622
17- __version__ = '0.2.9 '
23+ __version__ = '0.4.0 '
1824__project__ = 'Inirama'
1925__author__ = "Kirill Klenov <[email protected] >" 2026__license__ = "BSD"
@@ -183,9 +189,33 @@ def __getitem__(self, name):
183189
184190
185191class Namespace (object ):
192+ """ Default class for parsing INI.
193+
194+ :param **default_items: Default items for default section.
195+
196+ Usage
197+ -----
198+
199+ ::
200+
201+ from inirama import Namespace
186202
203+ ns = Namespace()
204+ ns.read('config.ini')
205+
206+ print ns['section']['key']
207+
208+ ns['other']['new'] = 'value'
209+ ns.write('new_config.ini')
210+
211+ """
212+ #: Name of default section (:attr:`~inirama.Namespace.default`)
187213 default_section = 'DEFAULT'
214+
215+ #: Dont raise any exception on file reading erorrs
188216 silent_read = True
217+
218+ #: Class for generating sections
189219 section_type = Section
190220
191221 def __init__ (self , ** default_items ):
@@ -201,6 +231,11 @@ def default(self):
201231
202232 def read (self , * files , ** params ):
203233 """ Read and parse INI files.
234+
235+ :param *files: Files for reading
236+ :param **params: Params for parsing
237+
238+ Set `update=False` for prevent values redefinition.
204239 """
205240 for f in files :
206241 try :
@@ -214,7 +249,7 @@ def read(self, *files, **params):
214249
215250 def write (self , f ):
216251 """
217- Write self as INI file.
252+ Write namespace as INI file.
218253
219254 :param f: File object or path to file.
220255 """
@@ -233,7 +268,10 @@ def write(self, f):
233268 f .close ()
234269
235270 def parse (self , source , update = True , ** params ):
236- """ Parse INI source.
271+ """ Parse INI source as string.
272+
273+ :param source: Source of INI
274+ :param update: Replace alredy defined items
237275 """
238276 scanner = INIScanner (source )
239277 scanner .scan ()
@@ -266,7 +304,23 @@ def __repr__(self):
266304
267305
268306class InterpolationNamespace (Namespace ):
307+ """ That implements the interpolation feature.
308+
309+ ::
310+
311+ from inirama import InterpolationNamespace
312+
313+ ns = InterpolationNamespace()
314+ ns.parse('''
315+ [main]
316+ test = value
317+ foo = bar {test}
318+ more_deep = wow {foo}
319+ ''')
320+ print ns['main']['more_deep'] # wow bar value
321+
322+ """
269323
270324 section_type = InterpolationSection
271325
272- # lint_ignore=W0201,R0924,F0401
326+ # lint_ignore=W0201,R0924
0 commit comments