Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
FFDN
isp-format
Commits
fffa78ed
Commit
fffa78ed
authored
Oct 18, 2020
by
keoma
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'to-python3' into 'master'
to python3 See merge request
!1
parents
3f751cc1
fe115822
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
29 deletions
+31
-29
ispformat/__init__.py
ispformat/__init__.py
+1
-1
ispformat/bin/isp-format-validator
ispformat/bin/isp-format-validator
+6
-6
ispformat/validator/__init__.py
ispformat/validator/__init__.py
+1
-2
ispformat/validator/schemavalidator.py
ispformat/validator/schemavalidator.py
+22
-20
setup.py
setup.py
+1
-0
No files found.
ispformat/__init__.py
View file @
fffa78ed
__version__
=
'0.
2
.0'
__version__
=
'0.
3
.0'
ispformat/bin/isp-format-validator
View file @
fffa78ed
#!/usr/bin/env python
2
#!/usr/bin/env python
3
# -*- coding: utf-8 -*-
import
sys
...
...
@@ -6,13 +6,13 @@ import json
from
ispformat.validator
import
validate_isp
if
len
(
sys
.
argv
)
==
2
:
j
=
json
.
load
(
open
(
sys
.
argv
[
1
]))
errs
=
list
(
validate_isp
(
j
))
j
=
json
.
load
(
open
(
sys
.
argv
[
1
]))
errs
=
list
(
validate_isp
(
j
))
if
errs
:
for
e
in
errs
:
print
e
print
(
e
)
else
:
print
"All clear"
print
(
"All clear"
)
else
:
print
"Usage: validator.py file-name.json"
print
(
"Usage: validator.py file-name.json"
)
ispformat/validator/__init__.py
View file @
fffa78ed
from
ispformat.validator.schemavalidator
import
*
from
ispformat.validator.schemavalidator
import
*
\ No newline at end of file
ispformat/validator/schemavalidator.py
View file @
fffa78ed
...
...
@@ -3,7 +3,7 @@
import
ispformat.schema
as
_schema
from
jsonschema
import
Draft4Validator
,
RefResolver
,
draft4_format_checker
from
jsonschema.exceptions
import
RefResolutionError
,
ValidationError
from
urlparse
import
urlsplit
from
url
lib.
parse
import
urlsplit
class
MyRefResolver
(
RefResolver
):
...
...
@@ -12,12 +12,12 @@ class MyRefResolver(RefResolver):
raise
RefResolutionError
(
"Refusing to resolve remote URI: '{}'"
.
format
(
uri
))
geojson_allowed_types
=
(
'Polygon'
,
'MultiPolygon'
)
geojson_allowed_types
=
(
'Polygon'
,
'MultiPolygon'
)
def
validate_geojson_type
(
d
):
"""
Make sure a geojson dict only contains allowed geometry types
"""
type_
=
d
.
get
(
'type'
)
type_
=
d
.
get
(
'type'
)
if
type_
not
in
geojson_allowed_types
:
return
False
return
True
...
...
@@ -35,7 +35,7 @@ def validate_geojson(geodict):
format_checker
=
draft4_format_checker
,
)
for
err
in
v
.
iter_errors
(
geodict
):
for
_
in
v
.
iter_errors
(
geodict
):
return
False
if
not
validate_geojson_type
(
geodict
):
...
...
@@ -44,18 +44,18 @@ def validate_geojson(geodict):
return
True
def
validate_isp
(
jdict
):
def
validate_isp
(
jdict
:
dict
):
"""
Validate a json-object against the isp json-schema
"""
if
not
'version'
in
jdict
:
if
'version'
not
in
jdict
:
raise
ValidationError
(
u
'version is a required property'
)
try
:
schema
=
_schema
.
versions
[
jdict
[
'version'
]]
schema
=
_schema
.
versions
[
jdict
[
'version'
]]
except
(
AttributeError
,
TypeError
,
KeyError
):
raise
ValidationError
(
u
'version %r unsupported'
%
jdict
[
'version'
])
raise
ValidationError
(
u
'version %r unsupported'
%
jdict
[
'version'
])
v
=
Draft4Validator
(
v
=
Draft4Validator
(
schema
,
resolver
=
MyRefResolver
.
from_schema
(
schema
,
store
=
_schema
.
deps_for_version
(
jdict
[
'version'
])),
format_checker
=
draft4_format_checker
,
...
...
@@ -66,7 +66,7 @@ def validate_isp(jdict):
def
is_valid_url
(
u
):
try
:
pu
=
urlsplit
(
u
)
pu
=
urlsplit
(
u
)
except
:
return
False
if
pu
.
scheme
not
in
(
''
,
'http'
,
'https'
):
...
...
@@ -76,35 +76,37 @@ def validate_isp(jdict):
return
True
if
'website'
in
jdict
and
not
is_valid_url
(
jdict
[
'website'
]):
yield
ValidationError
(
u
'%r must be an absolute HTTP URL'
%
u
'website'
,
yield
ValidationError
(
u
'%r must be an absolute HTTP URL'
%
u
'website'
,
instance
=
jdict
[
u
'website'
],
schema
=
schema
[
u
'properties'
][
u
'website'
],
path
=
[
u
'website'
],
schema_path
=
[
u
'properties'
,
u
'website'
,
u
'description'
],
validator
=
u
'validate_url'
,
validator_value
=
jdict
[
'website'
])
if
'logoURL'
in
jdict
and
not
is_valid_url
(
jdict
[
'logoURL'
]):
yield
ValidationError
(
u
'%r must be an absolute HTTP URL'
%
u
'logoURL'
,
yield
ValidationError
(
u
'%r must be an absolute HTTP URL'
%
u
'logoURL'
,
instance
=
jdict
[
u
'logoURL'
],
schema
=
schema
[
u
'properties'
][
u
'logoURL'
],
path
=
[
u
'logoURL'
],
schema_path
=
[
u
'properties'
,
u
'logoURL'
,
u
'description'
],
validator
=
u
'validate_url'
,
validator_value
=
jdict
[
'logoURL'
])
sch
=
schema
[
u
'properties'
][
u
'otherWebsites'
][
u
'patternProperties'
][
u
'^.+$'
]
for
name
,
url
in
jdict
.
get
(
'otherWebsites'
,
{}).
iter
items
():
sch
=
schema
[
u
'properties'
][
u
'otherWebsites'
][
u
'patternProperties'
][
u
'^.+$'
]
for
name
,
url
in
jdict
.
get
(
'otherWebsites'
,
{}).
items
():
if
is_valid_url
(
url
):
continue
yield
ValidationError
(
u
'%r must be an absolute HTTP URL'
%
name
,
instance
=
url
,
schema
=
sch
,
path
=
[
u
'otherWebsite'
,
name
],
schema_path
=
[
u
'properties'
,
u
'otherWebsites'
,
u
'patternProperties'
,
u
'^.+$'
,
'description'
],
validator
=
u
'validate_url'
,
validator_value
=
url
)
yield
ValidationError
(
u
'%r must be an absolute HTTP URL'
%
name
,
instance
=
url
,
schema
=
sch
,
path
=
[
u
'otherWebsite'
,
name
],
schema_path
=
[
u
'properties'
,
u
'otherWebsites'
,
u
'patternProperties'
,
u
'^.+$'
,
'description'
],
validator
=
u
'validate_url'
,
validator_value
=
url
)
for
i
,
ca
in
enumerate
(
jdict
.
get
(
'coveredAreas'
,
[])):
area
=
ca
.
get
(
'area'
)
area
=
ca
.
get
(
'area'
)
if
area
and
validate_geojson_type
(
area
):
continue
elif
not
area
:
continue
yield
ValidationError
(
u
'GeoJSON can only contain the following types: %s'
%
repr
(
geojson_allowed_types
),
u
'GeoJSON can only contain the following types: %s'
%
repr
(
geojson_allowed_types
),
instance
=
ca
,
schema
=
schema
[
u
'definitions'
][
u
'coveredArea'
][
u
'properties'
][
u
'area'
],
path
=
[
'coveredAreas'
,
i
,
'area'
],
schema_path
=
[
u
'properties'
,
u
'coveredAreas'
,
u
'items'
,
u
'properties'
,
u
'area'
],
...
...
setup.py
View file @
fffa78ed
...
...
@@ -30,6 +30,7 @@ setup(
'Programming Language :: Python'
,
'Programming Language :: Python :: 2.6'
,
'Programming Language :: Python :: 2.7'
,
'Programming Language :: Python :: 3.7'
,
'Topic :: Internet :: WWW/HTTP'
,
],
install_requires
=
[
...
...
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