comparison configmix/config.py @ 384:8c3aaa894089

Implemented Configuration.getfirstintvarl_s(), .getfirstboolvar_s() and .getfirstfloatvarl_s()
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 10 Nov 2021 01:53:50 +0100
parents 5c72da46b8ae
children 4beeb291926d
comparison
equal deleted inserted replaced
383:5c72da46b8ae 384:8c3aaa894089
273 if isinstance(s, self._TEXTTYPE): 273 if isinstance(s, self._TEXTTYPE):
274 return int(s, 0) 274 return int(s, 0)
275 else: 275 else:
276 return s 276 return s
277 277
278 def getfirstintvarl_s(self, *paths, **kwds):
279 """Get a (possibly substituted) variable and coerce text to a
280 number.
281
282 """
283 s = self.getfirstvarl_s(*paths, **kwds)
284 if isinstance(s, self._TEXTTYPE):
285 return int(s, 0)
286 else:
287 return s
288
278 def getintvar_s(self, varname, default=_MARKER): 289 def getintvar_s(self, varname, default=_MARKER):
279 """Get a (possibly substituted) variable and coerce text to a 290 """Get a (possibly substituted) variable and coerce text to a
280 number. 291 number.
281 292
282 """ 293 """
301 """Get a (possibly substituted) variable and convert text to a 312 """Get a (possibly substituted) variable and convert text to a
302 boolean 313 boolean
303 314
304 """ 315 """
305 s = self.getvarl_s(*path, **kwds) 316 s = self.getvarl_s(*path, **kwds)
317 if isinstance(s, self._TEXTTYPE):
318 sl = s.strip().lower()
319 if sl not in self._BOOL_CVT:
320 raise ValueError("Not a boolean: %r" % s)
321 return self._BOOL_CVT[sl]
322 else:
323 return s
324
325 def getfirstboolvarl_s(self, *paths, **kwds):
326 """Get a (possibly substituted) variable and convert text to a
327 boolean
328
329 """
330 s = self.getfirstvarl_s(*paths, **kwds)
306 if isinstance(s, self._TEXTTYPE): 331 if isinstance(s, self._TEXTTYPE):
307 sl = s.strip().lower() 332 sl = s.strip().lower()
308 if sl not in self._BOOL_CVT: 333 if sl not in self._BOOL_CVT:
309 raise ValueError("Not a boolean: %r" % s) 334 raise ValueError("Not a boolean: %r" % s)
310 return self._BOOL_CVT[sl] 335 return self._BOOL_CVT[sl]
349 """Get a (possibly substituted) variable and convert text to a 374 """Get a (possibly substituted) variable and convert text to a
350 float 375 float
351 376
352 """ 377 """
353 s = self.getvarl_s(*path, **kwds) 378 s = self.getvarl_s(*path, **kwds)
379 if isinstance(s, self._TEXTTYPE):
380 return float(s)
381 else:
382 return s
383
384 def getfirstfloatvarl_s(self, *path, **kwds):
385 """Get a (possibly substituted) variable and convert text to a
386 float
387
388 """
389 s = self.getfirstvarl_s(*path, **kwds)
354 if isinstance(s, self._TEXTTYPE): 390 if isinstance(s, self._TEXTTYPE):
355 return float(s) 391 return float(s)
356 else: 392 else:
357 return s 393 return s
358 394