From b58ade97bde0f26271ebbccf6959bfc5a30a88d2 Mon Sep 17 00:00:00 2001 From: Ludovico Cavedon Date: Sat, 12 Jun 2010 16:34:16 -0700 Subject: Imported Upstream version 0.4 --- iniparse/ini.py | 49 ++----------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) (limited to 'iniparse/ini.py') diff --git a/iniparse/ini.py b/iniparse/ini.py index f0e7ec2..408354d 100644 --- a/iniparse/ini.py +++ b/iniparse/ini.py @@ -45,7 +45,6 @@ import re from ConfigParser import DEFAULTSECT, ParsingError, MissingSectionHeaderError import config -import compat class LineType(object): line = None @@ -352,7 +351,7 @@ class INISection(config.ConfigNamespace): value = re.sub('\n+', '\n', value) return value - def __getitem__(self, key): + def _getitem(self, key): if key == '__name__': return self._lines[-1].name if self._optionxform: key = self._optionxform(key) @@ -474,7 +473,7 @@ class INIConfig(config.ConfigNamespace): _optionxform = _make_xform_property('_optionxform', 'optionxform') _sectionxform = _make_xform_property('_sectionxform', 'optionxform') - def __getitem__(self, key): + def _getitem(self, key): if key == DEFAULTSECT: return self._defaults if self._sectionxform: key = self._sectionxform(key) @@ -642,47 +641,3 @@ class INIConfig(config.ConfigNamespace): raise exc -def tidy(cfg): - """Clean up blank lines. - - This functions makes the configuration look clean and - handwritten - consecutive empty lines and empty lines at - the start of the file are removed, and one is guaranteed - to be at the end of the file. - """ - - if isinstance(cfg, compat.RawConfigParser): - cfg = cfg.data - cont = cfg._data.contents - i = 1 - while i < len(cont): - if isinstance(cont[i], LineContainer): - tidy_section(cont[i]) - i += 1 - elif (isinstance(cont[i-1], EmptyLine) and - isinstance(cont[i], EmptyLine)): - del cont[i] - else: - i += 1 - - # Remove empty first line - if cont and isinstance(cont[0], EmptyLine): - del cont[0] - - # Ensure a last line - if cont and not isinstance(cont[-1], EmptyLine): - cont.append(EmptyLine()) - -def tidy_section(lc): - cont = lc.contents - i = 1 - while i < len(cont): - if (isinstance(cont[i-1], EmptyLine) and - isinstance(cont[i], EmptyLine)): - del cont[i] - else: - i += 1 - - # Remove empty first line - if len(cont) > 1 and isinstance(cont[1], EmptyLine): - del cont[1] -- cgit v1.2.3