Skip to content

Commit

Permalink
Don't directly use private parts of ConfigParser from MyConfigParser.
Browse files Browse the repository at this point in the history
  • Loading branch information
stump committed Oct 7, 2010
1 parent 63fbe90 commit 69601f9
Showing 1 changed file with 23 additions and 38 deletions.
61 changes: 23 additions & 38 deletions src/Config.py
Expand Up @@ -36,9 +36,9 @@
logUndefinedGets = 0

class MyConfigParser(RawConfigParser):
def _writeSection(self, fp, sectionName, sectionDict):
def _writeSection(self, fp, sectionName, sectionItems):
fp.write("[%s]\n" % sectionName)
for key, value in sorted(sectionDict.iteritems()):
for key, value in sorted(sectionItems):
if key != "__name__":
fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
fp.write("\n")
Expand All @@ -48,45 +48,30 @@ def write(self, fp, type = 0):
return self.writeController(fp)
elif type == 2:
return self.writePlayer(fp)
if self._defaults:
self._writeSection(fp, DEFAULTSECT, self._defaults)
sections = sorted(self._sections)
for section in sections:
if section == "theme":
continue
elif section == "controller":
continue
elif section == "player":
continue
self._writeSection(fp, section, self._sections[section])

if self.defaults():
self._writeSection(fp, DEFAULTSECT, self.defaults().items())
for section in sorted(self.sections()):
if section not in ("theme", "controller", "player"):
self._writeSection(fp, section, self.items(section))

def writeTheme(self, fp):
if self._defaults:
self._writeSection(fp, DEFAULTSECT, self._defaults)
sections = sorted(self._sections)
for section in sections:
if section != "theme":
continue
self._writeSection(fp, section, self._sections[section])

if self.defaults():
self._writeSection(fp, DEFAULTSECT, self.defaults().items())
if self.has_section('theme'):
self._writeSection(fp, 'theme', self.items('theme'))

def writeController(self, fp):
if self._defaults:
self._writeSection(fp, DEFAULTSECT, self._defaults)
sections = sorted(self._sections)
for section in sections:
if section != "controller":
continue
self._writeSection(fp, section, self._sections[section])

if self.defaults():
self._writeSection(fp, DEFAULTSECT, self.defaults().items())
if self.has_section('controller'):
self._writeSection(fp, 'controller', self.items('controller'))

def writePlayer(self, fp):
if self._defaults:
self._writeSection(fp, DEFAULTSECT, self._defaults)
sections = sorted(self._sections)
for section in sections:
if section != "player":
continue
self._writeSection(fp, section, self._sections[section])

if self.defaults():
self._writeSection(fp, DEFAULTSECT, self.defaults().items())
if self.has_section('player'):
self._writeSection(fp, 'player', self.items('player'))

class Option:
"""A prototype configuration key."""
def __init__(self, **args):
Expand Down

0 comments on commit 69601f9

Please sign in to comment.