ui.py: move common code out of config and configbool
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Tue, 10 Oct 2006 18:43:20 -0300
changeset 3341 a7cec14c9b40
parent 3340 929d04962115
child 3342 4eeb79b4da30
ui.py: move common code out of config and configbool
mercurial/ui.py
--- a/mercurial/ui.py	Tue Oct 10 18:43:20 2006 -0300
+++ b/mercurial/ui.py	Tue Oct 10 18:43:20 2006 -0300
@@ -87,12 +87,13 @@
     def setconfig(self, section, name, val):
         self.overlay[(section, name)] = val
 
-    def config(self, section, name, default=None):
+    def _config(self, section, name, default, funcname):
         if self.overlay.has_key((section, name)):
             return self.overlay[(section, name)]
         if self.cdata.has_option(section, name):
             try:
-                return self.cdata.get(section, name)
+                func = getattr(self.cdata, funcname)
+                return func(section, name)
             except ConfigParser.InterpolationError, inst:
                 raise util.Abort(_("Error in configuration section [%s] "
                                    "parameter '%s':\n%s")
@@ -100,7 +101,13 @@
         if self.parentui is None:
             return default
         else:
-            return self.parentui.config(section, name, default)
+            return self.parentui._config(section, name, default, funcname)
+
+    def config(self, section, name, default=None):
+        return self._config(section, name, default, 'get')
+
+    def configbool(self, section, name, default=False):
+        return self._config(section, name, default, 'getboolean')
 
     def configlist(self, section, name, default=None):
         """Return a list of comma/space separated strings"""
@@ -111,21 +118,6 @@
             result = result.replace(",", " ").split()
         return result
 
-    def configbool(self, section, name, default=False):
-        if self.overlay.has_key((section, name)):
-            return self.overlay[(section, name)]
-        if self.cdata.has_option(section, name):
-            try:
-                return self.cdata.getboolean(section, name)
-            except ConfigParser.InterpolationError, inst:
-                raise util.Abort(_("Error in configuration section [%s] "
-                                   "parameter '%s':\n%s")
-                                 % (section, name, inst))
-        if self.parentui is None:
-            return default
-        else:
-            return self.parentui.configbool(section, name, default)
-
     def has_config(self, section):
         '''tell whether section exists in config.'''
         return self.cdata.has_section(section)