Show More
@@ -116,11 +116,23 b' extendeddateformats = defaultdateformats' | |||||
116 | class SignalInterrupt(Exception): |
|
116 | class SignalInterrupt(Exception): | |
117 | """Exception raised on SIGTERM and SIGHUP.""" |
|
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 | class configparser(ConfigParser.SafeConfigParser): |
|
123 | class configparser(ConfigParser.SafeConfigParser): | |
121 | def optionxform(self, optionstr): |
|
124 | def optionxform(self, optionstr): | |
122 | return optionstr |
|
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 | def cachefunc(func): |
|
136 | def cachefunc(func): | |
125 | '''cache the result of function calls''' |
|
137 | '''cache the result of function calls''' | |
126 | # XXX doesn't handle keywords args |
|
138 | # XXX doesn't handle keywords args |
@@ -1,5 +1,6 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 |
|
2 | |||
|
3 | import ConfigParser | |||
3 | from mercurial import ui, util, commands |
|
4 | from mercurial import ui, util, commands | |
4 |
|
5 | |||
5 | testui = ui.ui() |
|
6 | testui = ui.ui() | |
@@ -70,3 +71,21 b' try:' | |||||
70 | except util.Abort, inst: |
|
71 | except util.Abort, inst: | |
71 | print inst |
|
72 | print inst | |
72 | print "---" |
|
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 '!') |
@@ -43,3 +43,5 b" bad interpolation variable reference '%(" | |||||
43 | Error in configuration section [interpolation] parameter 'value5': |
|
43 | Error in configuration section [interpolation] parameter 'value5': | |
44 | '%' must be followed by '%' or '(', found: '%bad2' |
|
44 | '%' must be followed by '%' or '(', found: '%bad2' | |
45 | --- |
|
45 | --- | |
|
46 | No option 'Bar' in section: 'foo' | |||
|
47 | f == function |
General Comments 0
You need to be logged in to leave comments.
Login now