summaryrefslogtreecommitdiff
path: root/iniparse/ini.py
diff options
context:
space:
mode:
authorLudovico Cavedon <cavedon@debian.org>2010-06-12 16:34:16 -0700
committerLudovico Cavedon <cavedon@debian.org>2010-06-12 16:34:16 -0700
commitf4eca607761d95cbaae2199e5393aa3fc58749a6 (patch)
tree11384cda2b30fd594b2c95a827c1368b85487809 /iniparse/ini.py
parenta26d8b27322da433c092876bde1f9e96dafa3519 (diff)
parentb58ade97bde0f26271ebbccf6959bfc5a30a88d2 (diff)
Merge commit 'upstream/0.4'
Diffstat (limited to 'iniparse/ini.py')
-rw-r--r--iniparse/ini.py49
1 files changed, 2 insertions, 47 deletions
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]