summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Holth <dholth@fastmail.fm>2016-06-15 23:46:00 (GMT)
committerDaniel Holth <dholth@fastmail.fm>2016-06-15 23:46:00 (GMT)
commitf8fbe351d2677bc2e4e3094e905c579825c1582a (patch)
tree64e0c20decc566367ec34ed6fcd13a368532512d
parent88958d1f4beae35315b26ec1b32b38eeb41946f8 (diff)
downloadSCons-f8fbe351d2677bc2e4e3094e905c579825c1582a.zip
SCons-f8fbe351d2677bc2e4e3094e905c579825c1582a.tar.gz
SCons-f8fbe351d2677bc2e4e3094e905c579825c1582a.tar.bz2
wrap several frequently-used open() calls in with statements
-rw-r--r--src/engine/SCons/Node/FS.py4
-rw-r--r--src/engine/SCons/Node/__init__.py3
-rw-r--r--src/engine/SCons/Scanner/C.py5
3 files changed, 6 insertions, 6 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index d19afa9..71511b5 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -1211,9 +1211,9 @@ class FS(LocalFS):
def getcwd(self):
if hasattr(self, "_cwd"):
- return self._cwd
+ return self._cwd
else:
- return "<no cwd>"
+ return "<no cwd>"
def chdir(self, dir, change_os_dir=0):
"""Change the current working directory for lookups.
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index e714172..51762a3 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -214,7 +214,8 @@ def get_contents_file(node):
return ''
fname = node.rfile().get_abspath()
try:
- contents = open(fname, "rb").read()
+ with open(fname, "rb") as fp:
+ contents = fp.read()
except EnvironmentError as e:
if not e.filename:
e.filename = fname
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py
index 3b34b88..c2e50a6 100644
--- a/src/engine/SCons/Scanner/C.py
+++ b/src/engine/SCons/Scanner/C.py
@@ -58,12 +58,11 @@ class SConsCPPScanner(SCons.cpp.PreProcessor):
return result
def read_file(self, file):
try:
- fp = open(str(file.rfile()))
+ with open(str(file.rfile())) as fp:
+ return fp.read()
except EnvironmentError as e:
self.missing.append((file, self.current_file))
return ''
- else:
- return fp.read()
def dictify_CPPDEFINES(env):
cppdefines = env.get('CPPDEFINES', {})