# HG changeset patch # User Alexis S. L. Carvalho # Date 1171000106 7200 # Node ID 3fef134832d895b87fcf1a4c55b601fd0b086735 # Parent 5b1f663ef86d68ce11d70de8e5ab61d93341a18c allow values that aren't strings in util.configparser diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -116,11 +116,23 @@ extendeddateformats = defaultdateformats class SignalInterrupt(Exception): """Exception raised on SIGTERM and SIGHUP.""" -# like SafeConfigParser but with case-sensitive keys +# differences from SafeConfigParser: +# - case-sensitive keys +# - allows values that are not strings (this means that you may not +# be able to save the configuration to a file) class configparser(ConfigParser.SafeConfigParser): def optionxform(self, optionstr): return optionstr + def set(self, section, option, value): + return ConfigParser.ConfigParser.set(self, section, option, value) + + def _interpolate(self, section, option, rawval, vars): + if not isinstance(rawval, basestring): + return rawval + return ConfigParser.SafeConfigParser._interpolate(self, section, + option, rawval, vars) + def cachefunc(func): '''cache the result of function calls''' # XXX doesn't handle keywords args diff --git a/tests/test-ui-config b/tests/test-ui-config --- a/tests/test-ui-config +++ b/tests/test-ui-config @@ -1,5 +1,6 @@ #!/usr/bin/env python +import ConfigParser from mercurial import ui, util, commands testui = ui.ui() @@ -70,3 +71,21 @@ try: except util.Abort, inst: print inst print "---" + +cp = util.configparser() +cp.add_section('foo') +cp.set('foo', 'bar', 'baz') +try: + # should fail - keys are case-sensitive + cp.get('foo', 'Bar') +except ConfigParser.NoOptionError, inst: + print inst + +def function(): + pass + +cp.add_section('hook') +# values that aren't strings should work +cp.set('hook', 'commit', function) +f = cp.get('hook', 'commit') +print "f %s= function" % (f == function and '=' or '!') diff --git a/tests/test-ui-config.out b/tests/test-ui-config.out --- a/tests/test-ui-config.out +++ b/tests/test-ui-config.out @@ -43,3 +43,5 @@ bad interpolation variable reference '%( Error in configuration section [interpolation] parameter 'value5': '%' must be followed by '%' or '(', found: '%bad2' --- +No option 'Bar' in section: 'foo' +f == function