Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 12087:a88a4720c2f0
parsebool: create new function and use it for config parsing
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Sat, 28 Aug 2010 21:50:35 -0500 |
parents | dba2db7a7c28 |
children | 1f71dffabc53 |
line wrap: on
line diff
--- a/mercurial/util.py Sat Aug 28 21:49:53 2010 -0500 +++ b/mercurial/util.py Sat Aug 28 21:50:35 2010 -0500 @@ -1435,3 +1435,13 @@ return socket.getservbyname(port) except socket.error: raise Abort(_("no port number associated with service '%s'") % port) + +_booleans = {'1': True, 'yes': True, 'true': True, 'on': True, + '0': False, 'no': False, 'false': False, 'off': False} + +def parsebool(s): + """Parse s into a boolean. + + If s is not a valid boolean, returns None. + """ + return _booleans.get(s.lower(), None)