From e254cdf344ed0a466661b319dc019f2400ad12f3 Mon Sep 17 00:00:00 2001 From: Greg Noel Date: Sat, 17 Apr 2010 13:16:00 +0000 Subject: http://scons.tigris.org/issues/show_bug.cgi?id=2345 Fix the 'assignment to True or False' and the '__getitem__ not supported for exception classes' deprecation warnings. --- QMTest/TestCmd.py | 2 +- QMTest/TestSCons.py | 8 +++---- src/engine/SCons/Builder.py | 2 +- src/engine/SCons/Defaults.py | 3 ++- src/engine/SCons/Script/Main.py | 2 +- src/engine/SCons/WarningsTests.py | 2 +- src/engine/SCons/compat/_scons_builtins.py | 32 ++++++++++++++-------------- src/engine/SCons/compat/_scons_subprocess.py | 7 ------ src/script/scons-time.py | 13 ++++------- test/Deprecated/Options/BoolOption.py | 4 ++-- test/Deprecated/Options/PackageOption.py | 4 ++-- test/Deprecated/Options/help.py | 4 ++-- test/NodeOps.py | 7 ------ test/Variables/BoolVariable.py | 4 ++-- test/Variables/PackageVariable.py | 4 ++-- test/Variables/help.py | 4 ++-- 16 files changed, 41 insertions(+), 61 deletions(-) diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 1568b0d..1dff4a6 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -765,7 +765,7 @@ class Popen(subprocess.Popen): try: written = os.write(self.stdin.fileno(), input) except OSError, why: - if why[0] == errno.EPIPE: #broken pipe + if why.args[0] == errno.EPIPE: #broken pipe return self._close('stdin') raise diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py index a4e9c86..561dcda 100644 --- a/QMTest/TestSCons.py +++ b/QMTest/TestSCons.py @@ -24,12 +24,10 @@ import sys import time try: - x = True + True except NameError: - True = not 0 - False = not 1 -else: - del x + exec('True = not 0') + exec('False = not 1') from TestCommon import * from TestCommon import __all__ diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 1d20a4f..6317a44 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -170,7 +170,7 @@ class DictCmdGenerator(SCons.Util.Selector): try: ret = SCons.Util.Selector.__call__(self, env, source, ext) except KeyError, e: - raise UserError("Ambiguous suffixes after environment substitution: %s == %s == %s" % (e[0], e[1], e[2])) + raise UserError("Ambiguous suffixes after environment substitution: %s == %s == %s" % (e.args[0], e.args[1], e.args[2])) if ret is None: raise UserError("While building `%s' from `%s': Don't know how to build from a source file with suffix `%s'. Expected a suffix in this list: %s." % \ (repr(list(map(str, target))), repr(list(map(str, source))), ext, repr(self.keys()))) diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index cc2e0a0..ece6d59 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -223,7 +223,8 @@ def mkdir_func(dest): os.makedirs(str(entry)) except os.error, e: p = str(entry) - if (e[0] == errno.EEXIST or (sys.platform=='win32' and e[0]==183)) \ + if (e.args[0] == errno.EEXIST or + (sys.platform=='win32' and e.args[0]==183)) \ and os.path.isdir(str(entry)): pass # not an error if already exists else: diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index 7a8f698..7b58594 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -594,7 +594,7 @@ def _scons_internal_warning(e): *current call stack* rather than sys.exc_info() to get our stack trace. This is used by the warnings framework to print warnings.""" filename, lineno, routine, dummy = find_deepest_user_frame(traceback.extract_stack()) - sys.stderr.write("\nscons: warning: %s\n" % e[0]) + sys.stderr.write("\nscons: warning: %s\n" % e.args[0]) sys.stderr.write('File "%s", line %d, in %s\n' % (filename, lineno, routine)) def _scons_internal_error(): diff --git a/src/engine/SCons/WarningsTests.py b/src/engine/SCons/WarningsTests.py index 83e11fc..92c1419 100644 --- a/src/engine/SCons/WarningsTests.py +++ b/src/engine/SCons/WarningsTests.py @@ -29,7 +29,7 @@ import SCons.Warnings class TestOutput: def __call__(self, x): - args = x[0] + args = x.args[0] if len(args) == 1: args = args[0] self.out = str(args) diff --git a/src/engine/SCons/compat/_scons_builtins.py b/src/engine/SCons/compat/_scons_builtins.py index 012d6c2..59be7af 100644 --- a/src/engine/SCons/compat/_scons_builtins.py +++ b/src/engine/SCons/compat/_scons_builtins.py @@ -62,6 +62,22 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import builtins try: + False +except NameError: + # Pre-2.2 Python has no False keyword. + exec('builtins.False = not 1') + # Assign to False in this module namespace so it shows up in pydoc output. + #False = False + +try: + True +except NameError: + # Pre-2.2 Python has no True keyword. + exec('builtins.True = not 0') + # Assign to True in this module namespace so it shows up in pydoc output. + #True = True + +try: all except NameError: # Pre-2.5 Python has no all() function. @@ -122,22 +138,6 @@ except NameError: builtins.dict = dict try: - False -except NameError: - # Pre-2.2 Python has no False keyword. - builtins.False = not 1 - # Assign to False in this module namespace so it shows up in pydoc output. - #False = False - -try: - True -except NameError: - # Pre-2.2 Python has no True keyword. - builtins.True = not 0 - # Assign to True in this module namespace so it shows up in pydoc output. - #True = True - -try: file except NameError: # Pre-2.2 Python has no file() function. diff --git a/src/engine/SCons/compat/_scons_subprocess.py b/src/engine/SCons/compat/_scons_subprocess.py index bdcae63..97eb498 100644 --- a/src/engine/SCons/compat/_scons_subprocess.py +++ b/src/engine/SCons/compat/_scons_subprocess.py @@ -433,13 +433,6 @@ except KeyboardInterrupt: except: MAXFD = 256 -# True/False does not exist on 2.2.0 -try: - False -except NameError: - False = 0 - True = 1 - try: isinstance(1, int) except TypeError: diff --git a/src/script/scons-time.py b/src/script/scons-time.py index d85dc8e..5f3d515 100644 --- a/src/script/scons-time.py +++ b/src/script/scons-time.py @@ -45,16 +45,11 @@ import tempfile import time try: - False + True, False except NameError: - # Pre-2.2 Python has no False keyword. - False = not 1 - -try: - True -except NameError: - # Pre-2.2 Python has no True keyword. - True = not 0 + # Pre-2.2 Python has no True or False keyword. + exec('True = not 0') + exec('False = not 1') try: sorted diff --git a/test/Deprecated/Options/BoolOption.py b/test/Deprecated/Options/BoolOption.py index d99544f..0955d87 100644 --- a/test/Deprecated/Options/BoolOption.py +++ b/test/Deprecated/Options/BoolOption.py @@ -31,8 +31,8 @@ Test the BoolOption canned Option type. try: True, False except NameError: - True = (0 == 0) - False = (0 != 0) + exec('True = (0 == 0)') + exec('False = (0 != 0)') import TestSCons diff --git a/test/Deprecated/Options/PackageOption.py b/test/Deprecated/Options/PackageOption.py index b9f0400..3d15de0 100644 --- a/test/Deprecated/Options/PackageOption.py +++ b/test/Deprecated/Options/PackageOption.py @@ -33,8 +33,8 @@ import os.path try: True, False except NameError: - True = (0 == 0) - False = (0 != 0) + exec('True = (0 == 0)') + exec('False = (0 != 0)') import TestSCons diff --git a/test/Deprecated/Options/help.py b/test/Deprecated/Options/help.py index 9e9adee..0b7226b 100644 --- a/test/Deprecated/Options/help.py +++ b/test/Deprecated/Options/help.py @@ -34,8 +34,8 @@ import re try: True, False except NameError: - True = (0 == 0) - False = (0 != 0) + exec('True = (0 == 0)') + exec('False = (0 != 0)') str_True = str(True) str_False = str(False) diff --git a/test/NodeOps.py b/test/NodeOps.py index 6de7d09..5062b72 100644 --- a/test/NodeOps.py +++ b/test/NodeOps.py @@ -121,13 +121,6 @@ sconscript = r""" import os Import('*') -import __builtin__ -try: - __builtin__.True -except AttributeError: - __builtin__.True = 1 - __builtin__.False = 0 - def mycopy(env, source, target): open(str(target[0]),'w').write(open(str(source[0]),'r').read()) diff --git a/test/Variables/BoolVariable.py b/test/Variables/BoolVariable.py index 37130c0..e3ebabd 100644 --- a/test/Variables/BoolVariable.py +++ b/test/Variables/BoolVariable.py @@ -33,8 +33,8 @@ import os.path try: True, False except NameError: - True = (0 == 0) - False = (0 != 0) + exec('True = (0 == 0)') + exec('False = (0 != 0)') import TestSCons diff --git a/test/Variables/PackageVariable.py b/test/Variables/PackageVariable.py index 6ad7fc1..172d5e4 100644 --- a/test/Variables/PackageVariable.py +++ b/test/Variables/PackageVariable.py @@ -33,8 +33,8 @@ import os.path try: True, False except NameError: - True = (0 == 0) - False = (0 != 0) + exec('True = (0 == 0)') + exec('False = (0 != 0)') import TestSCons diff --git a/test/Variables/help.py b/test/Variables/help.py index 0a0a969..6776327 100644 --- a/test/Variables/help.py +++ b/test/Variables/help.py @@ -33,8 +33,8 @@ import os.path try: True, False except NameError: - True = (0 == 0) - False = (0 != 0) + exec('True = (0 == 0)') + exec('False = (0 != 0)') str_True = str(True) str_False = str(False) -- cgit v0.12