Python idioms for iterating over a line and closing it have improved,
and we should keep up.
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <npower@samba.org>
exitcode = 0
open_tests = {}
- while fh:
- l = fh.readline()
- if l == "":
- break
+ for l in fh:
parts = l.split(None, 1)
if not len(parts) == 2 or not l.startswith(parts[0]):
msg_ops.output_msg(l)
reason = ""
# reason may be specified in next lines
terminated = False
- while fh:
- l = fh.readline()
- if l == "":
- break
+ for l in fh:
msg_ops.control_msg(l)
if l == "]\n":
terminated = True
files.append(name)
for filename in files:
- f = open(filename, 'r')
- try:
+ with open(filename, 'r') as f:
for l in f:
l = l.strip()
if l == "" or l[0] == "#":
ret[regex.strip()] = reason.strip()
else:
ret[l] = None
- finally:
- f.close()
+
return ret