diff options
Diffstat (limited to 'src/engine/SCons/Variables')
-rw-r--r-- | src/engine/SCons/Variables/BoolVariable.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Variables/EnumVariable.py | 20 | ||||
-rw-r--r-- | src/engine/SCons/Variables/ListVariable.py | 25 | ||||
-rw-r--r-- | src/engine/SCons/Variables/PackageVariable.py | 11 | ||||
-rw-r--r-- | src/engine/SCons/Variables/VariablesTests.py | 18 | ||||
-rw-r--r-- | src/engine/SCons/Variables/__init__.py | 22 |
6 files changed, 46 insertions, 54 deletions
diff --git a/src/engine/SCons/Variables/BoolVariable.py b/src/engine/SCons/Variables/BoolVariable.py index c1a20e3..6bc66bb 100644 --- a/src/engine/SCons/Variables/BoolVariable.py +++ b/src/engine/SCons/Variables/BoolVariable.py @@ -38,8 +38,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" __all__ = ['BoolVariable',] -import string - import SCons.Errors __true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' ) @@ -57,7 +55,7 @@ def _text2bool(val): This is usable as 'converter' for SCons' Variables. """ - lval = string.lower(val) + lval = val.lower() if lval in __true_strings: return True if lval in __false_strings: return False raise ValueError("Invalid value for boolean option: %s" % val) diff --git a/src/engine/SCons/Variables/EnumVariable.py b/src/engine/SCons/Variables/EnumVariable.py index b8f30bf..71302ee 100644 --- a/src/engine/SCons/Variables/EnumVariable.py +++ b/src/engine/SCons/Variables/EnumVariable.py @@ -41,7 +41,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" __all__ = ['EnumVariable',] -import string import SCons.Errors @@ -80,24 +79,21 @@ def EnumVariable(key, help, default, allowed_values, map={}, ignorecase=0): given 'map'-dictionary (unmapped input values are returned unchanged). """ - help = '%s (%s)' % (help, string.join(allowed_values, '|')) + help = '%s (%s)' % (help, '|'.join(allowed_values)) # define validator if ignorecase >= 1: - validator = lambda key, val, env, vals=allowed_values: \ - _validator(key, string.lower(val), env, vals) + validator = lambda key, val, env: \ + _validator(key, val.lower(), env, allowed_values) else: - validator = lambda key, val, env, vals=allowed_values: \ - _validator(key, val, env, vals) + validator = lambda key, val, env: \ + _validator(key, val, env, allowed_values) # define converter if ignorecase == 2: - converter = lambda val, map=map: \ - string.lower(map.get(string.lower(val), val)) + converter = lambda val: map.get(val.lower(), val).lower() elif ignorecase == 1: - converter = lambda val, map=map: \ - map.get(string.lower(val), val) + converter = lambda val: map.get(val.lower(), val) else: - converter = lambda val, map=map: \ - map.get(val, val) + converter = lambda val: map.get(val, val) return (key, help, default, validator, converter) # Local Variables: diff --git a/src/engine/SCons/Variables/ListVariable.py b/src/engine/SCons/Variables/ListVariable.py index 521fa4f..36b530a 100644 --- a/src/engine/SCons/Variables/ListVariable.py +++ b/src/engine/SCons/Variables/ListVariable.py @@ -46,6 +46,7 @@ Usage example: # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -54,7 +55,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" __all__ = ['ListVariable',] -import string import UserList import SCons.Util @@ -62,7 +62,7 @@ import SCons.Util class _ListVariable(UserList.UserList): def __init__(self, initlist=[], allowedElems=[]): - UserList.UserList.__init__(self, filter(None, initlist)) + UserList.UserList.__init__(self, [_f for _f in initlist if _f]) self.allowedElems = allowedElems[:] self.allowedElems.sort() @@ -85,7 +85,7 @@ class _ListVariable(UserList.UserList): if self.data == self.allowedElems: return 'all' else: - return string.join(self, ',') + return ','.join(self) def prepare_to_store(self): return self.__str__() @@ -97,12 +97,12 @@ def _converter(val, allowedElems, mapdict): elif val == 'all': val = allowedElems else: - val = filter(None, string.split(val, ',')) - val = map(lambda v, m=mapdict: m.get(v, v), val) - notAllowed = filter(lambda v, aE=allowedElems: not v in aE, val) + val = [_f for _f in val.split(',') if _f] + val = [mapdict.get(v, v) for v in val] + notAllowed = [v for v in val if not v in allowedElems] if notAllowed: raise ValueError("Invalid value(s) for option: %s" % - string.join(notAllowed, ',')) + ','.join(notAllowed)) return _ListVariable(val, allowedElems) @@ -122,15 +122,14 @@ def ListVariable(key, help, default, names, map={}): A 'package list' option may either be 'all', 'none' or a list of package names (separated by space). """ - names_str = 'allowed names: %s' % string.join(names, ' ') + names_str = 'allowed names: %s' % ' '.join(names) if SCons.Util.is_List(default): - default = string.join(default, ',') - help = string.join( - (help, '(all|none|comma-separated list of names)', names_str), - '\n ') + default = ','.join(default) + help = '\n '.join( + (help, '(all|none|comma-separated list of names)', names_str)) return (key, help, default, None, #_validator, - lambda val, elems=names, m=map: _converter(val, elems, m)) + lambda val: _converter(val, names, map)) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Variables/PackageVariable.py b/src/engine/SCons/Variables/PackageVariable.py index 294a398..440d0f6 100644 --- a/src/engine/SCons/Variables/PackageVariable.py +++ b/src/engine/SCons/Variables/PackageVariable.py @@ -54,8 +54,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" __all__ = ['PackageVariable',] -import string - import SCons.Errors __enable_strings = ('1', 'yes', 'true', 'on', 'enable', 'search') @@ -64,7 +62,7 @@ __disable_strings = ('0', 'no', 'false', 'off', 'disable') def _converter(val): """ """ - lval = string.lower(val) + lval = val.lower() if lval in __enable_strings: return True if lval in __disable_strings: return False #raise ValueError("Invalid value for boolean option: %s" % val) @@ -95,11 +93,10 @@ def PackageVariable(key, help, default, searchfunc=None): A 'package list' option may either be 'all', 'none' or a list of package names (seperated by space). """ - help = string.join( - (help, '( yes | no | /path/to/%s )' % key), - '\n ') + help = '\n '.join( + (help, '( yes | no | /path/to/%s )' % key)) return (key, help, default, - lambda k, v, e, f=searchfunc: _validator(k,v,e,f), + lambda k, v, e: _validator(k,v,e,searchfunc), _converter) # Local Variables: diff --git a/src/engine/SCons/Variables/VariablesTests.py b/src/engine/SCons/Variables/VariablesTests.py index 493d69f..4fa0879 100644 --- a/src/engine/SCons/Variables/VariablesTests.py +++ b/src/engine/SCons/Variables/VariablesTests.py @@ -41,8 +41,10 @@ class Environment: self.dict[key] = value def __getitem__(self, key): return self.dict[key] + def __contains__(self, key): + return self.dict.__contains__(key) def has_key(self, key): - return self.dict.has_key(key) + return key in self.dict def check(key, value, env): @@ -253,7 +255,7 @@ class VariablesTestCase(unittest.TestCase): env = Environment() opts.Update(env, {}) - assert not env.has_key('ANSWER') + assert 'ANSWER' not in env # Test that a default value of None is all right. test = TestSCons.TestSCons() @@ -267,7 +269,7 @@ class VariablesTestCase(unittest.TestCase): env = Environment() opts.Update(env, {}) - assert not env.has_key('ANSWER') + assert 'ANSWER' not in env def test_args(self): """Test updating an Environment with arguments overridden""" @@ -527,12 +529,12 @@ B 42 54 b - alpha test ['B'] env = Environment() opts.Update(env, {'ANSWER' : 'answer'}) - assert env.has_key('ANSWER') + assert 'ANSWER' in env env = Environment() opts.Update(env, {'ANSWERALIAS' : 'answer'}) - assert env.has_key('ANSWER') and not env.has_key('ANSWERALIAS') + assert 'ANSWER' in env and 'ANSWERALIAS' not in env # test alias as a list opts = SCons.Variables.Variables() @@ -545,12 +547,12 @@ B 42 54 b - alpha test ['B'] env = Environment() opts.Update(env, {'ANSWER' : 'answer'}) - assert env.has_key('ANSWER') + assert 'ANSWER' in env env = Environment() opts.Update(env, {'ANSWERALIAS' : 'answer'}) - assert env.has_key('ANSWER') and not env.has_key('ANSWERALIAS') + assert 'ANSWER' in env and 'ANSWERALIAS' not in env @@ -652,7 +654,7 @@ if __name__ == "__main__": UnknownVariablesTestCase ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Variables/__init__.py b/src/engine/SCons/Variables/__init__.py index b1a2288..27f694f 100644 --- a/src/engine/SCons/Variables/__init__.py +++ b/src/engine/SCons/Variables/__init__.py @@ -26,11 +26,11 @@ customizable variables to an SCons build. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string import sys import SCons.Environment @@ -108,7 +108,7 @@ class Variables: """ Returns the keywords for the options """ - return map(lambda o: o.key, self.options) + return [o.key for o in self.options] def Add(self, key, help="", default=None, validator=None, converter=None, **kw): """ @@ -124,7 +124,7 @@ class Variables: """ if SCons.Util.is_List(key) or type(key) == type(()): - apply(self._do_add, key) + self._do_add(*key) return if not SCons.Util.is_String(key) or \ @@ -149,7 +149,7 @@ class Variables: ) """ for o in optlist: - apply(self._do_add, o) + self._do_add(*o) def Update(self, env, args=None): @@ -203,7 +203,7 @@ class Variables: # Call the convert functions: for option in self.options: - if option.converter and values.has_key(option.key): + if option.converter and option.key in values: value = env.subst('${%s}'%option.key) try: try: @@ -216,7 +216,7 @@ class Variables: # Finally validate the values: for option in self.options: - if option.validator and values.has_key(option.key): + if option.validator and option.key in values: option.validator(option.key, env.subst('${%s}'%option.key), env) def UnknownVariables(self): @@ -285,26 +285,26 @@ class Variables: if sort: options = self.options[:] - options.sort(lambda x,y,func=sort: func(x.key,y.key)) + options.sort(lambda x,y: sort(x.key,y.key)) else: options = self.options def format(opt, self=self, env=env): - if env.has_key(opt.key): + if opt.key in env: actual = env.subst('${%s}' % opt.key) else: actual = None return self.FormatVariableHelpText(env, opt.key, opt.help, opt.default, actual, opt.aliases) - lines = filter(None, map(format, options)) + lines = [_f for _f in map(format, options) if _f] - return string.join(lines, '') + return ''.join(lines) format = '\n%s: %s\n default: %s\n actual: %s\n' format_ = '\n%s: %s\n default: %s\n actual: %s\n aliases: %s\n' def FormatVariableHelpText(self, env, key, help, default, actual, aliases=[]): # Don't display the key name itself as an alias. - aliases = filter(lambda a, k=key: a != k, aliases) + aliases = [a for a in aliases if a != key] if len(aliases)==0: return self.format % (key, help, default, actual) else: |