- infile = open(fname, 'rt')
- content = infile.read()
- infile.close()
-
+ possible_encodings = []
+ for encoding in (
+ bookmark.charset,
+ sys.getfilesystemencoding(),
+ 'utf-8',
+ ):
+ if encoding and encoding not in possible_encodings:
+ possible_encodings.append(encoding)
+ content = e = None
+ infile = open(fname, 'rb')
+ try:
+ content = infile.read()
+ except Exception as e:
+ content = None
+ finally:
+ infile.close()
+
+ if content is None:
+ e = str(e)
+ return (
+ 'ERROR: ' + e,
+ None, None, None, None
+ )