diff options
5 files changed, 18 insertions, 21 deletions
diff --git a/components/script/dom/bindings/codegen/BindingGen.py b/components/script/dom/bindings/codegen/BindingGen.py index f4d4fcdae2a..810f52db566 100644 --- a/components/script/dom/bindings/codegen/BindingGen.py +++ b/components/script/dom/bindings/codegen/BindingGen.py @@ -39,9 +39,8 @@ def main(): webIDLFile = os.path.normpath(args[2]) # Load the parsing results - f = open('ParserResults.pkl', 'rb') - parserData = cPickle.load(f) - f.close() + with open('ParserResults.pkl', 'rb') as f: + parserData = cPickle.load(f) # Create the configuration data. config = Configuration(configFile, parserData) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index cd3ee9baacb..b4ed22fb447 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -41,18 +41,16 @@ def replaceFileIfChanged(filename, newContents): # oldFileContents = "" # try: - # oldFile = open(filename, 'rb') - # oldFileContents = ''.join(oldFile.readlines()) - # oldFile.close() + # with open(filename, 'rb') as oldFile: + # oldFileContents = ''.join(oldFile.readlines()) # except: # pass # if newContents == oldFileContents: # return False - f = open(filename, 'wb') - f.write(newContents) - f.close() + with open(filename, 'wb') as f: + f.write(newContents) return True diff --git a/components/script/dom/bindings/codegen/GenerateCSS2PropertiesWebIDL.py b/components/script/dom/bindings/codegen/GenerateCSS2PropertiesWebIDL.py index 55303f6c55b..37cde2702c5 100644 --- a/components/script/dom/bindings/codegen/GenerateCSS2PropertiesWebIDL.py +++ b/components/script/dom/bindings/codegen/GenerateCSS2PropertiesWebIDL.py @@ -18,9 +18,8 @@ for [prop, pref] in propList: props += " [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs), prop) -idlFile = open(sys.argv[1], "r") -idlTemplate = idlFile.read() -idlFile.close() +with open(sys.argv[1], "r") as idlFile: + idlTemplate = idlFile.read() print ("/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */\n\n" + string.Template(idlTemplate).substitute({"props": props})) diff --git a/components/script/dom/bindings/codegen/GlobalGen.py b/components/script/dom/bindings/codegen/GlobalGen.py index 1bebc213e38..b3ed1e25b12 100644 --- a/components/script/dom/bindings/codegen/GlobalGen.py +++ b/components/script/dom/bindings/codegen/GlobalGen.py @@ -47,16 +47,14 @@ def main(): parser = WebIDL.Parser(options.cachedir) for filename in fileList: fullPath = os.path.normpath(os.path.join(baseDir, filename)) - f = open(fullPath, 'rb') - lines = f.readlines() - f.close() + with open(fullPath, 'rb') as f: + lines = f.readlines() parser.parse(''.join(lines), fullPath) parserResults = parser.finish() # Write the parser results out to a pickle. - resultsFile = open('ParserResults.pkl', 'wb') - cPickle.dump(parserResults, resultsFile, -1) - resultsFile.close() + with open('ParserResults.pkl', 'wb') as resultsFile: + cPickle.dump(parserResults, resultsFile, -1) # Load the configuration. config = Configuration(configFile, parserResults) diff --git a/python/servo/command_base.py b/python/servo/command_base.py index 5beff5d4111..caca72799b8 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -73,7 +73,8 @@ class CommandBase(object): config_path = path.join(context.topdir, ".servobuild") if path.exists(config_path): - self.config = toml.loads(open(config_path).read()) + with open(config_path) as f: + self.config = toml.loads(f.read()) else: self.config = {} @@ -121,14 +122,16 @@ class CommandBase(object): def rust_snapshot_path(self): if self._rust_snapshot_path is None: filename = path.join(self.context.topdir, "rust-snapshot-hash") - snapshot_hash = open(filename).read().strip() + with open(filename) as f: + snapshot_hash = f.read().strip() self._rust_snapshot_path = "%s-%s" % (snapshot_hash, host_triple()) return self._rust_snapshot_path def cargo_build_id(self): if self._cargo_build_id is None: filename = path.join(self.context.topdir, "cargo-nightly-build") - self._cargo_build_id = open(filename).read().strip() + with open(filename) as f: + self._cargo_build_id = f.read().strip() return self._cargo_build_id def get_target_dir(self): |