[entropy.tools] istextfile: catch OSError and IOError exceptions

This commit is contained in:
Fabio Erculiani
2013-09-13 15:28:22 +02:00
parent 8e70eb0c17
commit fb9fe3a8d0

View File

@@ -1885,8 +1885,11 @@ def istextfile(filename, blocksize = 512):
@return: True, if text file
@rtype: bool
"""
with open(filename, "r") as f:
r = istext(f.read(blocksize))
try:
with open(filename, "r") as f:
r = istext(f.read(blocksize))
except (OSError, IOError):
return False
return r
def istext(mystring):