Skip to content

Commit 3b6946a

Browse files
committed
try harder to read files with right encoding
1 parent b816a0a commit 3b6946a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pygccxml/parser/declarations_cache.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ def file_signature( filename ):
2323
# - This change allows duplicate autogenerated files to be recognized
2424
#return os.path.getmtime( source )
2525
sig = hashlib.md5()
26-
f = open(filename,'r')
27-
sig.update(f.read().encode('utf-8'))
26+
try:
27+
# try default encoding first
28+
f = open(filename, 'r', encoding='utf-8')
29+
buf = f.read()
30+
except UnicodeDecodeError:
31+
# otherwise, try another common encoding
32+
f.close()
33+
f = open(filename, 'r', encoding='iso8859-1')
34+
buf = f.read()
35+
sig.update(buf.encode('utf-8'))
2836
f.close()
2937
return sig.hexdigest()
3038

0 commit comments

Comments
 (0)