Show More
@@ -116,11 +116,23 b' extendeddateformats = defaultdateformats' | |||
|
116 | 116 | class SignalInterrupt(Exception): |
|
117 | 117 | """Exception raised on SIGTERM and SIGHUP.""" |
|
118 | 118 | |
|
119 | # like SafeConfigParser but with case-sensitive keys | |
|
119 | # differences from SafeConfigParser: | |
|
120 | # - case-sensitive keys | |
|
121 | # - allows values that are not strings (this means that you may not | |
|
122 | # be able to save the configuration to a file) | |
|
120 | 123 | class configparser(ConfigParser.SafeConfigParser): |
|
121 | 124 | def optionxform(self, optionstr): |
|
122 | 125 | return optionstr |
|
123 | 126 | |
|
127 | def set(self, section, option, value): | |
|
128 | return ConfigParser.ConfigParser.set(self, section, option, value) | |
|
129 | ||
|
130 | def _interpolate(self, section, option, rawval, vars): | |
|
131 | if not isinstance(rawval, basestring): | |
|
132 | return rawval | |
|
133 | return ConfigParser.SafeConfigParser._interpolate(self, section, | |
|
134 | option, rawval, vars) | |
|
135 | ||
|
124 | 136 | def cachefunc(func): |
|
125 | 137 | '''cache the result of function calls''' |
|
126 | 138 | # XXX doesn't handle keywords args |
@@ -1,5 +1,6 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 | import ConfigParser | |
|
3 | 4 | from mercurial import ui, util, commands |
|
4 | 5 | |
|
5 | 6 | testui = ui.ui() |
@@ -70,3 +71,21 b' try:' | |||
|
70 | 71 | except util.Abort, inst: |
|
71 | 72 | print inst |
|
72 | 73 | print "---" |
|
74 | ||
|
75 | cp = util.configparser() | |
|
76 | cp.add_section('foo') | |
|
77 | cp.set('foo', 'bar', 'baz') | |
|
78 | try: | |
|
79 | # should fail - keys are case-sensitive | |
|
80 | cp.get('foo', 'Bar') | |
|
81 | except ConfigParser.NoOptionError, inst: | |
|
82 | print inst | |
|
83 | ||
|
84 | def function(): | |
|
85 | pass | |
|
86 | ||
|
87 | cp.add_section('hook') | |
|
88 | # values that aren't strings should work | |
|
89 | cp.set('hook', 'commit', function) | |
|
90 | f = cp.get('hook', 'commit') | |
|
91 | print "f %s= function" % (f == function and '=' or '!') |
General Comments 0
You need to be logged in to leave comments.
Login now