From fb9fe3a8d09595c9d0568f7dc403bb70db08ebbe Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Fri, 13 Sep 2013 15:28:22 +0200 Subject: [PATCH] [entropy.tools] istextfile: catch OSError and IOError exceptions --- lib/entropy/tools.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/entropy/tools.py b/lib/entropy/tools.py index 06ccc5d28..07febe3b4 100644 --- a/lib/entropy/tools.py +++ b/lib/entropy/tools.py @@ -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):