Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
eic_tools
Spack
Commits
10591fb8
Commit
10591fb8
authored
8 years ago
by
Sergey Kosukhin
Committed by
Todd Gamblin
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Json loader now returns str objects instead of unicode. (#2524)
parent
607f4e7b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/spack/spack/util/spack_json.py
+22
-2
22 additions, 2 deletions
lib/spack/spack/util/spack_json.py
with
22 additions
and
2 deletions
lib/spack/spack/util/spack_json.py
+
22
−
2
View file @
10591fb8
...
@@ -37,9 +37,11 @@
...
@@ -37,9 +37,11 @@
def
load
(
stream
):
def
load
(
stream
):
"""
Spack JSON needs to be ordered to support specs.
"""
"""
Spack JSON needs to be ordered to support specs.
"""
if
isinstance
(
stream
,
basestring
):
if
isinstance
(
stream
,
basestring
):
return
json
.
loads
(
stream
)
return
_byteify
(
json
.
loads
(
stream
,
object_hook
=
_byteify
),
ignore_dicts
=
True
)
else
:
else
:
return
json
.
load
(
stream
)
return
_byteify
(
json
.
load
(
stream
,
object_hook
=
_byteify
),
ignore_dicts
=
True
)
def
dump
(
data
,
stream
=
None
):
def
dump
(
data
,
stream
=
None
):
...
@@ -50,7 +52,25 @@ def dump(data, stream=None):
...
@@ -50,7 +52,25 @@ def dump(data, stream=None):
return
json
.
dump
(
data
,
stream
,
**
_json_dump_args
)
return
json
.
dump
(
data
,
stream
,
**
_json_dump_args
)
def
_byteify
(
data
,
ignore_dicts
=
False
):
# if this is a unicode string, return its string representation
if
isinstance
(
data
,
unicode
):
return
data
.
encode
(
'
utf-8
'
)
# if this is a list of values, return list of byteified values
if
isinstance
(
data
,
list
):
return
[
_byteify
(
item
,
ignore_dicts
=
True
)
for
item
in
data
]
# if this is a dictionary, return dictionary of byteified keys and values
# but only if we haven't already byteified it
if
isinstance
(
data
,
dict
)
and
not
ignore_dicts
:
return
dict
((
_byteify
(
key
,
ignore_dicts
=
True
),
_byteify
(
value
,
ignore_dicts
=
True
))
for
key
,
value
in
data
.
iteritems
())
# if it's anything else, return it in its original form
return
data
class
SpackJSONError
(
spack
.
error
.
SpackError
):
class
SpackJSONError
(
spack
.
error
.
SpackError
):
"""
Raised when there are issues with JSON parsing.
"""
"""
Raised when there are issues with JSON parsing.
"""
def
__init__
(
self
,
msg
,
yaml_error
):
def
__init__
(
self
,
msg
,
yaml_error
):
super
(
SpackJSONError
,
self
).
__init__
(
msg
,
str
(
yaml_error
))
super
(
SpackJSONError
,
self
).
__init__
(
msg
,
str
(
yaml_error
))
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