Skip to content
Snippets Groups Projects
Commit 8c92a267 authored by Ximin Luo's avatar Ximin Luo
Browse files

readers: Convert bytes to str in the right place

parent ad8ab31c
No related branches found
No related tags found
No related merge requests found
...@@ -17,12 +17,14 @@ ...@@ -17,12 +17,14 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>. # along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import codecs
from .json import JSONReaderV1 from .json import JSONReaderV1
def load_diff_from_path(path): def load_diff_from_path(path):
with open(path, 'rb') as fp: 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): def load_diff(fp, path):
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>. # along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import json import json
import codecs
from ..difference import Difference from ..difference import Difference
from ..presenters.json import JSON_FORMAT_MAGIC from ..presenters.json import JSON_FORMAT_MAGIC
...@@ -28,7 +27,9 @@ from .utils import UnrecognizedFormatError ...@@ -28,7 +27,9 @@ from .utils import UnrecognizedFormatError
class JSONReaderV1(object): class JSONReaderV1(object):
def load(self, fp, fn): 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: if JSON_FORMAT_MAGIC not in raw or raw[JSON_FORMAT_MAGIC] != 1:
raise UnrecognizedFormatError( raise UnrecognizedFormatError(
"Magic not found in JSON: {}".format(JSON_FORMAT_MAGIC) "Magic not found in JSON: {}".format(JSON_FORMAT_MAGIC)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment