summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Util.py
diff options
context:
space:
mode:
authorGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 (GMT)
committerGreg Noel <GregNoel@tigris.org>2010-03-27 07:39:52 (GMT)
commit59ed0a109bf5add2efcef459080837b11066c6fb (patch)
treefff879b4f9676a72e16c0f7b4dd969f050038b4f /src/engine/SCons/Util.py
parent00a3188193ba1feef927cf18e7f5fc20ad71b848 (diff)
downloadSCons-59ed0a109bf5add2efcef459080837b11066c6fb.zip
SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.gz
SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.bz2
http://scons.tigris.org/issues/show_bug.cgi?id=2329
Applied a number of idiomatic changes. Uses of the 'sort()' method were converted into calls of 'sorted()' when possible and the sorted() expression was inserted into a subsequent statement whenever that made sense. The statement 'while 1:' was changed to 'while True:'. Names from the 'types' module (e.g., 'types.FooType') were converted to the equivalent build-in type (e.g., 'foo'). Comparisons between types were changed to use 'isinstance()'.
Diffstat (limited to 'src/engine/SCons/Util.py')
-rw-r--r--src/engine/SCons/Util.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index a373863..f8bac89 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -42,11 +42,14 @@ from UserString import UserString
# Don't "from types import ..." these because we need to get at the
# types module later to look for UnicodeType.
-DictType = types.DictType
+DictType = dict
InstanceType = types.InstanceType
-ListType = types.ListType
-StringType = types.StringType
-TupleType = types.TupleType
+ListType = list
+StringType = str
+TupleType = tuple
+try: unicode
+except NameError: UnicodeType = None
+else: UnicodeType = unicode
def dictify(keys, values, result={}):
for k, v in zip(keys, values):
@@ -343,7 +346,7 @@ except TypeError:
t = type(obj)
return t is TupleType
- if hasattr(types, 'UnicodeType'):
+ if UnicodeType is not None:
def is_String(obj):
t = type(obj)
return t is StringType \
@@ -398,8 +401,7 @@ except TypeError:
# to_String_for_signature() will use a for_signature() method if the
# specified object has one.
#
- if hasattr(types, 'UnicodeType'):
- UnicodeType = types.UnicodeType
+ if UnicodeType is not None:
def to_String(s):
if isinstance(s, UserString):
t = type(s.data)
@@ -595,15 +597,15 @@ def _semi_deepcopy_dict(x):
# Doesn't seem like we need to, but we'll comment it just in case.
copy[key] = semi_deepcopy(val)
return copy
-d[types.DictionaryType] = _semi_deepcopy_dict
+d[dict] = _semi_deepcopy_dict
def _semi_deepcopy_list(x):
return list(map(semi_deepcopy, x))
-d[types.ListType] = _semi_deepcopy_list
+d[list] = _semi_deepcopy_list
def _semi_deepcopy_tuple(x):
return tuple(map(semi_deepcopy, x))
-d[types.TupleType] = _semi_deepcopy_tuple
+d[tuple] = _semi_deepcopy_tuple
def _semi_deepcopy_inst(x):
if hasattr(x, '__semi_deepcopy__'):
@@ -1220,8 +1222,7 @@ def unique(s):
# sort functions in all languages or libraries, so this approach
# is more effective in Python than it may be elsewhere.
try:
- t = list(s)
- t.sort()
+ t = sorted(s)
except TypeError:
pass # move on to the next method
else:
@@ -1291,7 +1292,7 @@ class LogicalLines:
def readline(self):
result = []
- while 1:
+ while True:
line = self.fileobj.readline()
if not line:
break
@@ -1304,7 +1305,7 @@ class LogicalLines:
def readlines(self):
result = []
- while 1:
+ while True:
line = self.readline()
if not line:
break
@@ -1545,7 +1546,7 @@ else:
def MD5filesignature(fname, chunksize=65536):
m = hashlib.md5()
f = open(fname, "rb")
- while 1:
+ while True:
blck = f.read(chunksize)
if not blck:
break