You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the contents of a diff file in a bytes object in Python 3. I tried feeding it to PatchSet but it complained:
is_source_filename = RE_SOURCE_FILENAME.match(line)
builtins.TypeError: cannot use a string pattern on a bytes-like object
I had to decode it and now it works, but I'm concerned whether the decoding could fail sometimes if there is binary content. It'll be nice if unidiff would accept the diff in binary form instead of me having to decode.
You don't usually have a unified diff for binary data, right? The unified diff format makes sense for text files, which could be encoded using different encodings, yes, but to parse it unidiff will need the decoded string (and the encoding is not something you can easily guess, that's why it is a param when parsing a diff file).
Makes sense? In any case I agree I could take a look what happens when diffing binary data.
Activity
matiasb commentedon May 20, 2017
You don't usually have a unified diff for binary data, right? The unified diff format makes sense for text files, which could be encoded using different encodings, yes, but to parse it unidiff will need the decoded string (and the encoding is not something you can easily guess, that's why it is a param when parsing a diff file).
Makes sense? In any case I agree I could take a look what happens when diffing binary data.
Merge pull request #137 from matiasb/review/12-bytes-input
matiasb commentedon Jul 18, 2026
Related changes implemented by #137