comparison mercurial/ui.py @ 30927:8fa3ab6221b9

ui: rewrite configint in terms of configwith
author Bryan O'Sullivan <bryano@fb.com>
date Sun, 12 Feb 2017 21:44:55 -0800
parents 120682fce099
children f61c5680a862
comparison
equal deleted inserted replaced
30926:120682fce099 30927:8fa3ab6221b9
451 7 451 7
452 >>> u.setconfig(s, 'invalid', 'somevalue') 452 >>> u.setconfig(s, 'invalid', 'somevalue')
453 >>> u.configint(s, 'invalid') 453 >>> u.configint(s, 'invalid')
454 Traceback (most recent call last): 454 Traceback (most recent call last):
455 ... 455 ...
456 ConfigError: foo.invalid is not an integer ('somevalue') 456 ConfigError: foo.invalid is not a valid integer ('somevalue')
457 """ 457 """
458 458
459 v = self.config(section, name, None, untrusted) 459 return self.configwith(int, section, name, default, 'integer',
460 if v is None: 460 untrusted)
461 return default
462 try:
463 return int(v)
464 except ValueError:
465 raise error.ConfigError(_("%s.%s is not an integer ('%s')")
466 % (section, name, v))
467 461
468 def configbytes(self, section, name, default=0, untrusted=False): 462 def configbytes(self, section, name, default=0, untrusted=False):
469 """parse a configuration element as a quantity in bytes 463 """parse a configuration element as a quantity in bytes
470 464
471 Units can be specified as b (bytes), k or kb (kilobytes), m or 465 Units can be specified as b (bytes), k or kb (kilobytes), m or