Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Converter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
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
XCG
Odoo modules
Converter
Commits
da9a0fe039b6
Commit
da9a0fe039b6
authored
2 years ago
by
Houzefa Abbasbhay
Browse files
Options
Downloads
Patches
Plain Diff
``jsonschema`` ➔ ``fastjsonschema``
parent
c23bed64ca21
No related branches found
Branches containing commit
Tags
13.0.3.2.0
Tags containing commit
3 merge requests
!37
Merge 15.0 (15.0.3.2.0 with fastjsonschema)
,
!36
Merge 13.0 (13.0.3.2.0 with fastjsonschema)
,
!34
``jsonschema`` ➔ ``fastjsonschema``
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
NEWS.rst
+5
-0
5 additions, 0 deletions
NEWS.rst
__manifest__.py
+2
-2
2 additions, 2 deletions
__manifest__.py
model.py
+1
-3
1 addition, 3 deletions
model.py
requirements
+1
-1
1 addition, 1 deletion
requirements
validate.py
+17
-44
17 additions, 44 deletions
validate.py
with
26 additions
and
50 deletions
NEWS.rst
+
5
−
0
View file @
da9a0fe0
...
...
@@ -2,6 +2,9 @@
History
*******
13.0.3.2.0
==========
Export constants from ``.base``.
Used by other modules; these exports got removed when I replaced an ``import *`` earlier.
...
...
@@ -5,6 +8,8 @@
Export constants from ``.base``.
Used by other modules; these exports got removed when I replaced an ``import *`` earlier.
``jsonschema`` ➔ ``fastjsonschema``.
13.0.3.1.0
==========
...
...
This diff is collapsed.
Click to expand it.
__manifest__.py
+
2
−
2
View file @
da9a0fe0
...
...
@@ -21,7 +21,7 @@
{
"
name
"
:
"
Converter
"
,
"
license
"
:
"
AGPL-3
"
,
"
version
"
:
"
13.0.3.
1
.0
"
,
"
version
"
:
"
13.0.3.
2
.0
"
,
"
category
"
:
"
Hidden
"
,
"
author
"
:
"
XCG Consulting
"
,
"
website
"
:
"
https://odoo.consulting/
"
,
...
...
@@ -29,5 +29,5 @@
"
data
"
:
[],
"
installable
"
:
True
,
# These dependencies are in the "requirements" file.
"
external_dependencies
"
:
{
"
python
"
:
[
"
jsonschema
"
]},
"
external_dependencies
"
:
{
"
python
"
:
[
"
fast
jsonschema
"
]},
}
This diff is collapsed.
Click to expand it.
model.py
+
1
−
3
View file @
da9a0fe0
...
...
@@ -34,8 +34,6 @@
)
from
.validate
import
VALIDATION_SKIP
,
VALIDATION_STRICT
,
Validator
import
jsonschema
_logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -96,7 +94,7 @@
if
self
.
validation
!=
VALIDATION_SKIP
and
self
.
_jsonschema
is
not
None
:
try
:
self
.
validator
.
validate
(
self
.
_jsonschema
,
message_data
)
except
jsonschema
.
exceptions
.
ValidationError
as
exception
:
except
Exception
as
exception
:
_logger
.
warning
(
"
Validation failed
"
,
exc_info
=
1
)
if
self
.
validation
==
VALIDATION_STRICT
:
raise
exception
...
...
This diff is collapsed.
Click to expand it.
requirements
+
1
−
1
View file @
da9a0fe0
# Used by converter module
jsonschema
==3.2.0
fast
jsonschema
This diff is collapsed.
Click to expand it.
validate.py
+
17
−
44
View file @
da9a0fe0
...
...
@@ -19,9 +19,8 @@
##############################################################################
import
json
import
math
import
os
from
typing
import
NoReturn
import
odoo.addons
...
...
@@ -23,9 +22,9 @@
import
os
from
typing
import
NoReturn
import
odoo.addons
import
jsonschema
import
fast
jsonschema
VALIDATION_SKIP
=
"
skip
"
VALIDATION_SOFT
=
"
soft
"
...
...
@@ -47,5 +46,4 @@
self
.
repository
=
repository
# exemple "https://annonces-legales.fr/xbus/schemas/v1/{}.schema.json"
self
.
default_url_pattern
=
default_url_pattern
self
.
schemastore
=
{}
self
.
validators
=
{}
...
...
@@ -51,5 +49,4 @@
self
.
validators
=
{}
self
.
search_path
=
"
not initialized, please call initialize()
"
self
.
initialized
=
False
self
.
encoding
=
"
UTF-8
"
...
...
@@ -57,6 +54,9 @@
repo_module_basepath
=
os
.
path
.
dirname
(
getattr
(
odoo
.
addons
,
self
.
repository_module_name
).
__file__
)
# Read local schema definitions.
schemas
=
{}
schema_search_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
repo_module_basepath
,
self
.
repository
)
)
...
...
@@ -60,12 +60,10 @@
schema_search_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
repo_module_basepath
,
self
.
repository
)
)
self
.
search_path
=
schema_search_path
for
root
,
_dirs
,
files
in
os
.
walk
(
self
.
search_path
):
for
root
,
_dirs
,
files
in
os
.
walk
(
schema_search_path
):
for
fname
in
files
:
fpath
=
os
.
path
.
join
(
root
,
fname
)
if
fpath
.
endswith
((
"
.json
"
,)):
with
open
(
fpath
,
"
r
"
,
encoding
=
self
.
encoding
)
as
schema_fd
:
schema
=
json
.
load
(
schema_fd
)
if
"
$id
"
in
schema
:
...
...
@@ -66,9 +64,18 @@
for
fname
in
files
:
fpath
=
os
.
path
.
join
(
root
,
fname
)
if
fpath
.
endswith
((
"
.json
"
,)):
with
open
(
fpath
,
"
r
"
,
encoding
=
self
.
encoding
)
as
schema_fd
:
schema
=
json
.
load
(
schema_fd
)
if
"
$id
"
in
schema
:
self
.
schemastore
[
schema
[
"
$id
"
]]
=
schema
schemas
[
schema
[
"
$id
"
]]
=
schema
# Prepare validators for each schema. We add an HTTPS handler that
# points back to our schema definition cache built above.
for
schema_id
,
schema
in
schemas
.
items
():
self
.
validators
[
schema_id
]
=
fastjsonschema
.
compile
(
schema
,
handlers
=
{
"
https
"
:
lambda
uri
:
schemas
[
uri
]},
use_default
=
False
,
)
self
.
initialized
=
True
...
...
@@ -73,6 +80,6 @@
self
.
initialized
=
True
def
validate
(
self
,
schema_id
,
doc
)
->
NoReturn
:
def
validate
(
self
,
schema_id
,
payload
)
->
NoReturn
:
if
not
self
.
initialized
:
raise
NotInitialized
(
"
please call the initialize() method
"
)
...
...
@@ -76,38 +83,4 @@
if
not
self
.
initialized
:
raise
NotInitialized
(
"
please call the initialize() method
"
)
uri
=
"
file://{}/{}.schema.json
"
.
format
(
self
.
search_path
,
schema_id
)
validator
=
self
.
validators
.
get
(
uri
)
if
validator
is
None
:
schema
=
self
.
schemastore
[
self
.
default_url_pattern
.
format
(
schema_id
)
]
resolver
=
jsonschema
.
RefResolver
(
uri
,
schema
,
self
.
schemastore
)
validator
=
jsonschema
.
Draft7Validator
(
schema
,
resolver
=
resolver
)
self
.
validators
[
uri
]
=
validator
validator
.
validate
(
doc
)
def
multiple_of
(
validator
,
db
,
instance
,
schema
):
"""
Fix rounding which fails when comparing e.g. 66.6 vs 0.01
"""
if
not
validator
.
is_type
(
instance
,
"
number
"
):
return
if
isinstance
(
db
,
float
):
quotient
=
instance
/
db
failed
=
not
math
.
isclose
(
round
(
quotient
),
quotient
)
else
:
failed
=
instance
%
db
if
failed
:
yield
jsonschema
.
ValidationError
(
"
%r is not a multiple of %r
"
%
(
instance
,
db
)
)
# Fix rounding which fails when comparing e.g. 66.6 vs 0.01
jsonschema
.
Draft7Validator
.
VALIDATORS
[
"
multipleOf
"
]
=
multiple_of
self
.
validators
[
self
.
default_url_pattern
.
format
(
schema_id
)](
payload
)
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