Commit 8c92a267 authored by Ximin Luo's avatar Ximin Luo

readers: Convert bytes to str in the right place

parent ad8ab31c
......@@ -17,12 +17,14 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <>.
import codecs
from .json import JSONReaderV1
def load_diff_from_path(path):
with open(path, 'rb') as fp:
return load_diff(fp, path)
return load_diff(codecs.getreader('utf-8')(fp), path)
def load_diff(fp, path):
......@@ -18,7 +18,6 @@
# along with diffoscope. If not, see <>.
import json
import codecs
from ..difference import Difference
from ..presenters.json import JSON_FORMAT_MAGIC
......@@ -28,7 +27,9 @@ from .utils import UnrecognizedFormatError
class JSONReaderV1(object):
def load(self, fp, fn):
raw = json.load(codecs.getreader('utf-8')(fp))
# fp should be a str-stream not a bytes-stream. If you need to pass in
# a bytes-stream, wrap it in codecs.getreader('utf-8')(fp)
raw = json.load(fp)
if JSON_FORMAT_MAGIC not in raw or raw[JSON_FORMAT_MAGIC] != 1:
raise UnrecognizedFormatError(
"Magic not found in JSON: {}".format(JSON_FORMAT_MAGIC)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment