):
if encoding and encoding not in possible_encodings:
possible_encodings.append(encoding)
- content = None
- for encoding in possible_encodings:
- infile = open(fname, 'rt', encoding=encoding)
- try:
- content = infile.read()
- except UnicodeDecodeError:
- infile.close()
- continue
- else:
- break
+ 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: File encoding was not recognized',
+ 'ERROR: ' + e,
None, None, None, None
)
return None, None, None, headers, content