summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorGreg Ward <greg@gerg.ca>2015-04-21 00:21:21 (GMT)
committerGreg Ward <greg@gerg.ca>2015-04-21 00:21:21 (GMT)
commit4d9d2563f51edad448a960d9490a6f56ac733735 (patch)
tree732ccd1c3bded6c2b25b942c7f55c5cc685dab1e /Misc
parentd19458ac51633cac979b7c7b9439ea89f179c8c8 (diff)
downloadcpython-4d9d2563f51edad448a960d9490a6f56ac733735.zip
cpython-4d9d2563f51edad448a960d9490a6f56ac733735.tar.gz
cpython-4d9d2563f51edad448a960d9490a6f56ac733735.tar.bz2
#17445: difflib: add diff_bytes(), to compare bytes rather than str
Some applications (e.g. traditional Unix diff, version control systems) neither know nor care about the encodings of the files they are comparing. They are textual, but to the diff utility they are just bytes. This worked fine under Python 2, because all of the hardcoded strings in difflib.py are ASCII, so could safely be combined with old-style u'' strings. But it stopped working in 3.x. The solution is to use surrogate escapes for a lossless bytes->str->bytes roundtrip. That means {unified,context}_diff() can continue to just handle strings without worrying about bytes. Callers who have to deal with bytes will need to change to using diff_bytes(). Use case: Mercurial's test runner uses difflib to compare current hg output with known good output. But Mercurial's output is just bytes, since it can contain: * file contents (arbitrary unknown encoding) * filenames (arbitrary unknown encoding) * usernames and commit messages (usually UTF-8, but not guaranteed because old versions of Mercurial did not enforce it) * user messages (locale encoding) Since the output of any given hg command can include text in multiple encodings, it is hopeless to try to treat it as decodable Unicode text. It's just bytes, all the way down. This is an elaboration of a patch by Terry Reedy.
Diffstat (limited to 'Misc')
-rw-r--r--Misc/NEWS4
1 files changed, 4 insertions, 0 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 5e31bd0..7277617 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -195,6 +195,10 @@ Library
- Issue #23310: Fix MagicMock's initializer to work with __methods__, just
like configure_mock(). Patch by Kasia Jachim.
+- Issue #17445: add difflib.diff_bytes() to support comparison of
+ byte strings (fixes a regression from Python 2).
+
+
Build
-----