##// END OF EJS Templates
parsebool: create new function and use it for config parsing
Augie Fackler -
r12087:a88a4720 default
parent child Browse files
Show More
@@ -9,9 +9,6 b' from i18n import _'
9 9 import errno, getpass, os, socket, sys, tempfile, traceback
10 10 import config, util, error
11 11
12 _booleans = {'1': True, 'yes': True, 'true': True, 'on': True,
13 '0': False, 'no': False, 'false': False, 'off': False}
14
15 12 class ui(object):
16 13 def __init__(self, src=None):
17 14 self._buffers = []
@@ -149,10 +146,11 b' class ui(object):'
149 146 return default
150 147 if isinstance(v, bool):
151 148 return v
152 if v.lower() not in _booleans:
149 b = util.parsebool(v)
150 if b is None:
153 151 raise error.ConfigError(_("%s.%s not a boolean ('%s')")
154 152 % (section, name, v))
155 return _booleans[v.lower()]
153 return b
156 154
157 155 def configlist(self, section, name, default=None, untrusted=False):
158 156 """Return a list of comma/space separated strings"""
@@ -1435,3 +1435,13 b' def getport(port):'
1435 1435 return socket.getservbyname(port)
1436 1436 except socket.error:
1437 1437 raise Abort(_("no port number associated with service '%s'") % port)
1438
1439 _booleans = {'1': True, 'yes': True, 'true': True, 'on': True,
1440 '0': False, 'no': False, 'false': False, 'off': False}
1441
1442 def parsebool(s):
1443 """Parse s into a boolean.
1444
1445 If s is not a valid boolean, returns None.
1446 """
1447 return _booleans.get(s.lower(), None)
General Comments 0
You need to be logged in to leave comments. Login now