[Reproducible-commits] [debbindiff] 02/03: Try both encodings if they differ
Reiner Herrmann
reiner at reiner-h.de
Sun Jul 12 11:00:41 UTC 2015
This is an automated email from the git hooks/post-receive script.
deki-guest pushed a commit to branch master
in repository debbindiff.
commit 5664ec2517dcc5367c6e9c094ac598d8f8dfb059
Author: Reiner Herrmann <reiner at reiner-h.de>
Date: Sun Jul 12 12:21:23 2015 +0200
Try both encodings if they differ
Closes: #785777
---
debbindiff/comparators/__init__.py | 10 ++++++----
debbindiff/comparators/text.py | 7 +++++--
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index bcd456d..8f79006 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -78,11 +78,13 @@ def compare_unknown(path1, path2, source=None):
if mime_type1.startswith('text/') and mime_type2.startswith('text/'):
encodings1 = re.findall(r'; charset=([^ ]+)', mime_type1)
encodings2 = re.findall(r'; charset=([^ ]+)', mime_type2)
- if len(encodings1) > 0 and encodings1 == encodings2:
+ encoding = None
+ encoding2 = None
+ if len(encodings1) > 0:
encoding = encodings1[0]
- else:
- encoding = None
- return compare_text_files(path1, path2, encoding, source)
+ if len(encodings2) > 0 and encodings1 != encodings2:
+ encoding2 = encodings2[0]
+ return compare_text_files(path1, path2, encoding, source, encoding2)
return compare_binary_files(path1, path2, source)
diff --git a/debbindiff/comparators/text.py b/debbindiff/comparators/text.py
index 591da20..3f07769 100644
--- a/debbindiff/comparators/text.py
+++ b/debbindiff/comparators/text.py
@@ -22,12 +22,15 @@ from debbindiff.comparators.binary import compare_binary_files
from debbindiff.difference import Difference
-def compare_text_files(path1, path2, encoding=None, source=None):
+def compare_text_files(path1, path2, encoding=None, source=None, encoding2=None):
if encoding is None:
encoding = 'utf-8'
+ if encoding2 is None:
+ encoding2 = encoding
+
try:
file1 = codecs.open(path1, 'r', encoding=encoding)
- file2 = codecs.open(path2, 'r', encoding=encoding)
+ file2 = codecs.open(path2, 'r', encoding=encoding2)
return Difference.from_file(file1, file2, path1, path2, source)
except (LookupError, UnicodeDecodeError):
# unknown or misdetected encoding
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git
More information about the Reproducible-commits
mailing list