Commit 016308cb authored by Iustin Pop's avatar Iustin Pop

Simplify utils.ReadFile

The documentation for file objects' read method states that if the size
is "negative or ommitted", all data is read; thus we can simplify it to
have size=-1 by default and not have the if test.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 310fbb64
......@@ -1226,21 +1226,18 @@ def EnsureDirs(dirs):
raise errors.GenericError("%s is not a directory" % dir_name)
def ReadFile(file_name, size=None):
def ReadFile(file_name, size=-1):
"""Reads a file.
@type size: None or int
@param size: Read at most size bytes
@type size: int
@param size: Read at most size bytes (if negative, entire file)
@rtype: str
@return: the (possibly partial) content of the file
"""
f = open(file_name, "r")
try:
if size is None:
return f.read()
else:
return f.read(size)
return f.read(size)
finally:
f.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment