Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
beat
beat.core
Commits
f2dc73bd
Commit
f2dc73bd
authored
6 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[schema] Import simplejson as json to make it easy to swap
parent
7392340e
No related branches found
No related tags found
1 merge request
!64
Factorize simplejson
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/core/schema/__init__.py
+8
-8
8 additions, 8 deletions
beat/core/schema/__init__.py
with
8 additions
and
8 deletions
beat/core/schema/__init__.py
+
8
−
8
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
...
...
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