Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
xml-validation
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
Container registry
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
vaclab
xml-validation
Commits
a0362116
Commit
a0362116
authored
3 years ago
by
Rolf Niepraschk
Browse files
Options
Downloads
Plain Diff
Merge branch 'test'
parents
7eb54a2f
e28e5412
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
config.json
+1
-3
1 addition, 3 deletions
config.json
server.py
+17
-10
17 additions, 10 deletions
server.py
templates/html/validation.html
+0
-2
0 additions, 2 deletions
templates/html/validation.html
utils.py
+36
-30
36 additions, 30 deletions
utils.py
with
54 additions
and
45 deletions
config.json
+
1
−
3
View file @
a0362116
...
...
@@ -4,8 +4,6 @@
"port"
:
5005
},
"xsd"
:{
"filename"
:
"dcc.xsd"
,
"externalBaseURL"
:
"https://ptb.de/dcc/"
,
"localPath"
:
"./xsd-local/"
"releases"
:
"https://www.ptb.de/dcc/releases.json"
}
}
This diff is collapsed.
Click to expand it.
server.py
+
17
−
10
View file @
a0362116
...
...
@@ -3,11 +3,13 @@ from flask_cors import CORS
import
utils
as
utils
from
trans
import
Trans
from
datetime
import
datetime
import
subprocess
import
subprocess
,
json
from
pprint
import
pprint
config
=
utils
.
get_config_dict
()
releases_dict
=
utils
.
get_releases_dict
(
config
[
'
xsd
'
][
'
releases
'
])
versions
=
utils
.
get_versions
(
releases_dict
)
app
=
Flask
(
__name__
)
CORS
(
app
)
trans
=
Trans
()
...
...
@@ -46,30 +48,33 @@ def update():
@app.route
(
'
/validate
'
,
methods
=
[
'
POST
'
])
def
validate
():
app
.
logger
.
debug
(
'
hit validate
'
)
x
v
=
request
.
args
.
get
(
'
v
'
)
v
ersion
=
request
.
args
.
get
(
'
v
'
)
xml_str
=
request
.
data
xml_tree
=
utils
.
parse
(
xml_str
)
if
xml_tree
:
try
:
utils
.
parse
(
xml_str
)
app
.
logger
.
debug
(
'
=== xml_tree OK ===
'
)
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_version
=
x
v
,
xml_str
=
xml_str
)
xsd_str
=
utils
.
get_xsd
(
releases_dict
,
xsd_version
=
v
ersion
,
xml_str
=
xml_str
)
if
xsd_str
:
app
.
logger
.
debug
(
'
=== xsd OK ===
'
)
ret
=
utils
.
validate
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
else
:
app
.
logger
.
debug
(
'
=== xsd invalid ===
'
)
ret
=
utils
.
return_error
(
error
=
'
xsd content not readable
'
)
e
lse
:
app
.
logger
.
debug
(
'
=== xml_tree invalid ===
'
)
ret
=
utils
.
return_error
(
error
=
'
invalid xml data
'
)
e
xcept
:
app
.
logger
.
debug
(
'
=== xml_tree invalid ===
'
)
ret
=
utils
.
return_error
(
error
=
'
invalid xml data
'
)
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/validation.html
'
,
methods
=
[
'
GET
'
])
def
validation
():
app
.
logger
.
debug
(
'
hit validation.html
'
)
# pprint(vars(request))
l
=
str
(
request
.
accept_languages
).
split
(
'
,
'
)[
0
][
0
:
2
]
if
l
!=
'
de
'
:
l
=
'
en
'
x
=
"
[
'
2.4.0
'
,
'
2.3.0
'
,
'
2.2.0
'
,
'
2.1.1
'
,
'
2.1.0
'
]
"
# x = '["2.4.0","2.3.0","2.2.0","2.1.1","2.1.0"]'
x
=
'
[
'
+
'
,
'
.
join
(
versions
)
+
'
]
'
# javascript array definition as string
return
trans
.
show_html
(
version
=
utils
.
get_version
(),
language
=
l
,
xsd_versions
=
x
)
...
...
@@ -90,3 +95,5 @@ def logo_folder(fn):
if
__name__
==
'
__main__
'
:
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
This diff is collapsed.
Click to expand it.
templates/html/validation.html
+
0
−
2
View file @
a0362116
...
...
@@ -39,7 +39,6 @@
<strong
style=
"margin-left:5em;"
>
{{XSD_VERSION}}:
</strong>
<select
id=
"xsd_version"
size=
"1"
>
<option>
{{INTERNAL}}
</option>
<option>
{{LATEST}}
</option>
</select>
</div>
...
...
@@ -68,7 +67,6 @@
function
getXSDversion
()
{
const
idx
=
$xsd_v
.
prop
(
'
selectedIndex
'
);
if
(
idx
==
0
)
return
false
;
if
(
idx
==
1
)
return
'
latest
'
;
return
$xsd_v
.
val
();
}
function
_showError
(
s
)
{
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
36
−
30
View file @
a0362116
...
...
@@ -21,6 +21,29 @@ def get_config_dict():
return
config
# get content of 'releases.json' via http request
def
get_releases_dict
(
url
):
try
:
filename
=
urlparse
(
url
).
path
.
split
(
'
/
'
)[
-
1
]
r
=
requests
.
get
(
url
,
allow_redirects
=
True
)
if
r
.
url
.
endswith
(
filename
):
# no bad redirection
try
:
return
json
.
loads
(
r
.
text
)
except
:
return
False
else
:
return
False
except
:
return
False
# a reverse list of version strings
def
get_versions
(
d
):
v
=
[]
for
i
in
d
[
'
releases
'
]:
v
.
append
(
'"'
+
i
[
'
version
'
]
+
'"'
)
v
=
list
(
reversed
(
v
))
return
v
def
get_version
():
try
:
with
open
(
'
./VERSION
'
,
'
r
'
)
as
f
:
...
...
@@ -29,38 +52,21 @@ def get_version():
except
:
return
False
def
get_xsd
(
cfg
,
xsd_version
=
None
,
xml_str
=
None
):
filename
=
cfg
[
'
xsd
'
][
'
filename
'
]
baseURL
=
cfg
[
'
xsd
'
][
'
externalBaseURL
'
]
xsd_str
=
''
def
get_xsd
(
d
,
xsd_version
=
None
,
xml_str
=
None
):
url
=
''
if
xsd_version
:
if
xsd_version
==
'
latest
'
:
url
=
baseURL
+
filename
else
:
url
=
baseURL
+
'
v
'
+
xsd_version
+
'
/
'
+
filename
else
:
version
=
xsd_version
if
not
version
:
# We use the internal version information in the XML data
root
=
parse
(
xml_str
)
item
=
root
.
attrib
.
get
(
'
schemaVersion
'
)
if
item
:
url
=
baseURL
+
'
v
'
+
item
+
'
/
'
+
filename
else
:
for
key
in
root
.
attrib
:
if
key
.
endswith
(
'
schemaLocation
'
):
x
=
root
.
attrib
.
get
(
key
).
split
()
for
u
in
x
:
if
u
.
endswith
(
filename
):
url
=
u
break
if
uri_validator
(
url
):
try
:
r
=
requests
.
get
(
url
,
allow_redirects
=
True
)
if
r
.
url
.
endswith
(
filename
):
# no bad redirection
return
r
.
text
else
:
return
False
except
:
return
False
version
=
root
.
attrib
.
get
(
'
schemaVersion
'
)
for
i
in
d
[
'
releases
'
]:
if
i
[
'
version
'
]
==
version
:
url
=
i
[
'
url
'
]
break
try
:
r
=
requests
.
get
(
url
,
allow_redirects
=
True
)
return
r
.
text
except
:
return
False
def
parse
(
xml_str
):
try
:
...
...
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