Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
beat.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
beat
beat.core
Commits
f2dc73bd
Commit
f2dc73bd
authored
Mar 20, 2019
by
Samuel GAIST
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[schema] Import simplejson as json to make it easy to swap
parent
7392340e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
beat/core/schema/__init__.py
beat/core/schema/__init__.py
+8
-8
No files found.
beat/core/schema/__init__.py
View file @
f2dc73bd
...
...
@@ -41,7 +41,7 @@ import collections
import
pkg_resources
import
six
import
simplejson
import
simplejson
as
json
import
jsonschema
...
...
@@ -55,7 +55,7 @@ def maybe_load_json(s):
with
open
(
s
,
"rt"
)
as
f
:
return
maybe_load_json
(
f
)
else
:
return
simple
json
.
loads
(
s
,
object_pairs_hook
=
collections
.
OrderedDict
)
return
json
.
loads
(
s
,
object_pairs_hook
=
collections
.
OrderedDict
)
# if it is a 'file-like' object
if
hasattr
(
s
,
"read"
):
...
...
@@ -94,7 +94,7 @@ def load_schema(schema_name, version=1):
with
open
(
fname
,
"rb"
)
as
f
:
data
=
f
.
read
().
decode
()
schema
=
simple
json
.
loads
(
data
)
schema
=
json
.
loads
(
data
)
basedir
=
os
.
path
.
realpath
(
os
.
path
.
dirname
(
fname
))
resolver
=
jsonschema
.
RefResolver
(
"file://"
+
basedir
+
"/"
,
schema
)
...
...
@@ -118,7 +118,7 @@ def validate(schema_name, data):
try:
cleaned_data, error_list = validate('toolchain', '/to/my/file.json')
except
simple
json.JSONDecodeError as e:
except json.JSONDecodeError as e:
print(e)
...
...
@@ -133,12 +133,12 @@ def validate(schema_name, data):
If ``data`` is a string and represents a valid filesystem path, the
relevant file will be opened and read as with
:py:func:`
simple
json.load``. Otherwise, it will be considered to be
:py:func:`json.load``. Otherwise, it will be considered to be
string containing a valid JSON structure that will be loaded as with
:py:func:`
simple
json.loads`.
:py:func:`json.loads`.
Note that if the file is opened and read internally using
:py:func:`
simple
json.load`, exceptions may be thrown by that subsystem,
:py:func:`json.load`, exceptions may be thrown by that subsystem,
concerning the file structure. Consult the manual page for
:py:mod:`simplejson` for details.
...
...
@@ -157,7 +157,7 @@ def validate(schema_name, data):
try
:
data
=
maybe_load_json
(
data
)
except
simple
json
.
JSONDecodeError
as
e
:
except
json
.
JSONDecodeError
as
e
:
return
data
,
[
"invalid JSON code: %s"
%
str
(
e
)]
# handles the schema version
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment