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
c2cc5ee6
Commit
c2cc5ee6
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
ref
parent
692dd60f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server.py
+8
-19
8 additions, 19 deletions
server.py
utils.py
+13
-5
13 additions, 5 deletions
utils.py
with
21 additions
and
24 deletions
server.py
+
8
−
19
View file @
c2cc5ee6
...
...
@@ -5,7 +5,7 @@ import utils as utils
config
=
utils
.
get_config_dict
()
git_cmd
=
utils
.
git_cmd
(
config
)
## komt später vom server
## kom
m
t später vom server
xsd_file_name
=
'
DCC_v1.8.1.xsd
'
app
=
Flask
(
__name__
)
...
...
@@ -14,8 +14,8 @@ CORS(app)
@app.route
(
'
/version
'
,
methods
=
[
'
get
'
])
def
version
():
app
.
logger
.
debug
(
'
hit version
'
)
ret
=
'
<version>{version}</version>
'
.
format
(
version
=
git_cmd
.
describe
())
ret
=
utils
.
return_version
(
version
=
git_cmd
.
describe
())
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/update
'
,
methods
=
[
'
post
'
])
...
...
@@ -24,7 +24,7 @@ def update():
#req = request.get_json()
git_cmd
.
pull
()
app
.
logger
.
info
(
"
pulled {log}
"
.
format
(
log
=
git_cmd
.
log
(
"
-n 1
"
)))
ret
=
'
<ok/>
'
ret
=
utils
.
return_ok
()
return
utils
.
xml_response
(
ret
)
...
...
@@ -34,23 +34,13 @@ def update_xsd():
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
True
)
xsd_xml
=
utils
.
parse
(
xsd_str
)
if
xsd_xml
:
res
=
utils
.
save_xsd
(
config
,
xsd_str
,
xsd_file_name
)
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/is_valid
'
,
methods
=
[
'
post
'
])
def
is_valid
():
app
.
logger
.
debug
(
'
hit is_valid
'
)
xml_str
=
request
.
data
xml_tree
=
utils
.
parse
(
xml_str
)
if
xml_tree
:
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
False
)
ret
=
utils
.
is_valid
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
ret
=
utils
.
save_xsd
(
config
,
xsd_str
,
xsd_file_name
)
else
:
ret
=
'
<error>unvalid xml data</error>
'
ret
=
utils
.
return_error
(
error
=
'
error on atempt to parse xsd file from server
'
)
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/validate
'
,
methods
=
[
'
post
'
])
def
validate
():
app
.
logger
.
debug
(
'
hit validate
'
)
...
...
@@ -60,10 +50,9 @@ def validate():
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
False
)
ret
=
utils
.
validate
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
else
:
ret
=
'
<
error
>
unvalid xml data
</error>
'
ret
=
utils
.
return_error
(
error
=
'
unvalid xml data
'
)
return
utils
.
xml_response
(
ret
)
if
__name__
==
'
__main__
'
:
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
\ No newline at end of file
This diff is collapsed.
Click to expand it.
utils.py
+
13
−
5
View file @
c2cc5ee6
...
...
@@ -36,14 +36,13 @@ def save_xsd(config, xsd_str, xsd_name):
file
=
open
(
path_file
,
"
w
"
)
file
.
write
(
xsd_str
)
return
'
ok
'
return
return_ok
()
def
parse
(
xml_str
):
try
:
tree
=
ET
.
fromstring
(
xml_str
)
except
ET
.
ParseError
:
tree
=
None
return
tree
def
validate
(
xml_str
,
xsd_str
):
...
...
@@ -51,9 +50,18 @@ def validate(xml_str, xsd_str):
schema
=
xmlschema
.
XMLSchema
(
xsd_str
)
try
:
schema
.
validate
(
tree
)
return
'
<ok/>
'
return
return_ok
()
except
xmlschema
.
XMLSchemaValidationError
as
error
:
return
'
<error>{error}</error>
'
.
format
(
error
=
error
)
return
return_error
(
error
)
def
xml_response
(
xml_str
):
return
Response
(
xml_str
,
content_type
=
'
text/xml; charset=utf-8
'
)
\ No newline at end of file
return
Response
(
xml_str
,
content_type
=
'
text/xml; charset=utf-8
'
)
def
return_ok
():
return
'
<ok/>
'
def
return_error
(
error
):
return
'
<error>{error}</error>
'
.
format
(
error
=
error
)
def
return_version
(
version
):
return
'
<version>{version}</version>
'
.
format
(
version
=
version
)
\ No newline at end of file
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