Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 373:0c65aac81807
Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 11 Jul 2021 17:08:06 +0200 |
| parents | 4ee53f6fcac1 |
| children | 4d7ad20cb8f9 |
comparison
equal
deleted
inserted
replaced
| 372:ac3e3cd6faae | 373:0c65aac81807 |
|---|---|
| 219 if isinstance(s, self._TEXTTYPE): | 219 if isinstance(s, self._TEXTTYPE): |
| 220 return int(s, 0) | 220 return int(s, 0) |
| 221 else: | 221 else: |
| 222 return s | 222 return s |
| 223 | 223 |
| 224 def getfirstintvar_s(self, *varnames, **kwds): | |
| 225 """Get a (possibly substituted) variable and coerce text to a | |
| 226 number. | |
| 227 | |
| 228 """ | |
| 229 s = self.getfirstvar_s(*varnames, **kwds) | |
| 230 if isinstance(s, self._TEXTTYPE): | |
| 231 return int(s, 0) | |
| 232 else: | |
| 233 return s | |
| 234 | |
| 224 def getboolvarl_s(self, *names, **kwds): | 235 def getboolvarl_s(self, *names, **kwds): |
| 225 """Get a (possibly substituted) variable and convert text to a | 236 """Get a (possibly substituted) variable and convert text to a |
| 226 boolean | 237 boolean |
| 227 | 238 |
| 228 """ | 239 """ |
| 239 """Get a (possibly substituted) variable and convert text to a | 250 """Get a (possibly substituted) variable and convert text to a |
| 240 boolean | 251 boolean |
| 241 | 252 |
| 242 """ | 253 """ |
| 243 s = self.getvar_s(varname, default=default) | 254 s = self.getvar_s(varname, default=default) |
| 255 if isinstance(s, self._TEXTTYPE): | |
| 256 sl = s.strip().lower() | |
| 257 if sl not in self._BOOL_CVT: | |
| 258 raise ValueError("Not a boolean: %r" % s) | |
| 259 return self._BOOL_CVT[sl] | |
| 260 else: | |
| 261 return s | |
| 262 | |
| 263 def getfirstboolvar_s(self, *varnames, **kwds): | |
| 264 """Get a (possibly substituted) variable and convert text to a | |
| 265 boolean | |
| 266 | |
| 267 """ | |
| 268 s = self.getfirstvar_s(*varnames, **kwds) | |
| 244 if isinstance(s, self._TEXTTYPE): | 269 if isinstance(s, self._TEXTTYPE): |
| 245 sl = s.strip().lower() | 270 sl = s.strip().lower() |
| 246 if sl not in self._BOOL_CVT: | 271 if sl not in self._BOOL_CVT: |
| 247 raise ValueError("Not a boolean: %r" % s) | 272 raise ValueError("Not a boolean: %r" % s) |
| 248 return self._BOOL_CVT[sl] | 273 return self._BOOL_CVT[sl] |
