Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
diffoscope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reproducible Builds
diffoscope
Commits
8c92a267
Commit
8c92a267
authored
7 years ago
by
Ximin Luo
Browse files
Options
Downloads
Patches
Plain Diff
readers: Convert bytes to str in the right place
parent
ad8ab31c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diffoscope/readers/__init__.py
+3
-1
3 additions, 1 deletion
diffoscope/readers/__init__.py
diffoscope/readers/json.py
+3
-2
3 additions, 2 deletions
diffoscope/readers/json.py
with
6 additions
and
3 deletions
diffoscope/readers/__init__.py
+
3
−
1
View file @
8c92a267
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
diffoscope/readers/json.py
+
3
−
2
View file @
8c92a267
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment