[diffoscope] 01/01: readers: Convert bytes to str in the right place
Ximin Luo
infinity0 at debian.org
Wed Sep 20 16:28:55 CEST 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository diffoscope.
commit 8c92a267c8079c8a9179738987852826a32591d9
Author: Ximin Luo <infinity0 at debian.org>
Date: Wed Sep 20 16:28:39 2017 +0200
readers: Convert bytes to str in the right place
---
diffoscope/readers/__init__.py | 4 +++-
diffoscope/readers/json.py | 5 +++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/diffoscope/readers/__init__.py b/diffoscope/readers/__init__.py
index 9f5bdf9..8064fce 100644
--- a/diffoscope/readers/__init__.py
+++ b/diffoscope/readers/__init__.py
@@ -17,12 +17,14 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
+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):
diff --git a/diffoscope/readers/json.py b/diffoscope/readers/json.py
index e088bca..22c966f 100644
--- a/diffoscope/readers/json.py
+++ b/diffoscope/readers/json.py
@@ -18,7 +18,6 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
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)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list