Skip to content

Commit

Permalink
replace minixsv validator by lxml
Browse files Browse the repository at this point in the history
lxml is available in standard distribution and is compatible with
python 2 and 3, which is not the case of minixsv

only constraint seems to be that complex regex patterns like negative
lookahead is not possible anymore, which is not a big deal since this
was not a valid XMLSchema format anyway
  • Loading branch information
gautierhattenberger committed Mar 26, 2020
1 parent e982822 commit 2bc2c1a
Show file tree
Hide file tree
Showing 35 changed files with 15 additions and 9,713 deletions.
6 changes: 3 additions & 3 deletions message_definitions/v1.0/pprz_schema.xsd
Expand Up @@ -9,9 +9,9 @@
<xs:attribute name="name"> <!-- msg_class, message,field -->
<xs:simpleType>
<xs:restriction base="xs:string">
<!-- class,long,var are currently used/valid field names in pprz -->
<xs:pattern value="^(?!break$|case$|catch$|const$|continue$|debugger$|default$|delete$|do$|else$|export$|extends$|finally$|for$|function$|if$|import$|in$|instanceof$|let$|new$|return$|super$|switch$|this$|throw$|try$|typeof$|void$|while$|with$|yield$|enum$|await$|implements$|package$|protected$|static$|interface$|private$|public$|abstract$|boolean$|byte$|char$|double$|final$|float$|goto$|int$|native$|short$|synchronized$|transient$|volatile$).+"/>
<!-- <xs:pattern value="^(?!break$|case$|class$|catch$|const$|continue$|debugger$|default$|delete$|do$|else$|export$|extends$|finally$|for$|function$|if$|import$|in$|instanceof$|let$|new$|return$|super$|switch$|this$|throw$|try$|typeof$|var$|void$|while$|with$|yield$|enum$|await$|implements$|package$|protected$|static$|interface$|private$|public$|abstract$|boolean$|byte$|char$|double$|final$|float$|goto$|int$|long$|native$|short$|synchronized$|transient$|volatile$).+"/> -->
<!-- for now, restrict to non-white characters -->
<xs:pattern value="[\S]+"/>
<!--xs:pattern value="^(?!break$|case$|catch$|const$|continue$|debugger$|default$|delete$|do$|else$|export$|extends$|finally$|for$|function$|if$|import$|in$|instanceof$|let$|new$|return$|super$|switch$|this$|throw$|try$|typeof$|void$|while$|with$|yield$|enum$|await$|implements$|package$|protected$|static$|interface$|private$|public$|abstract$|boolean$|byte$|char$|double$|final$|float$|goto$|int$|native$|short$|synchronized$|transient$|volatile$).+"/-->
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Expand Down
16 changes: 7 additions & 9 deletions tools/generator/gen_messages.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

'''
parse a PPRZ protocol XML file and generate appropriate implementation
Expand Down Expand Up @@ -39,22 +39,20 @@ def gen_messages(opts) :
# Enable validation by default, disabling it if explicitly requested
if opts.validate:
try:
from lib.genxmlif import GenXmlIfError
from lib.minixsv import pyxsval
from lxml import etree
except:
print("WARNING: Unable to load XML validator libraries. XML validation will not be performed")
opts.validate = False

def pprz_validate(fname, schema, errorLimitNumber) :
"""Uses minixsv to validate an XML file with a given XSD schema file. We define pprz_validate
here because it relies on the XML libs that were loaded in gen_messages(), so it can't be called standalone"""
# use default values of minixsv, location of the schema file must be specified in the XML file
try:
domTreeWrapper = pyxsval.parseAndValidate(fname, xsdFile=schema, errorLimit=errorLimitNumber)
except pyxsval.XsvalError as errstr:
print(errstr)
return 1
except GenXmlIfError as errstr:
xmlschema_doc = etree.parse(schema)
xmlschema = etree.XMLSchema(xmlschema_doc)
f_doc = etree.parse(fname)
xmlschema.assertValid(f_doc)
except Exception as errstr:
print(errstr)
return 1
return 0
Expand Down
2 changes: 1 addition & 1 deletion tools/generator/gen_messages_v1_0_c.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''
parse a PPRZLink protocol XML file and generate a C implementation
Expand Down
2 changes: 1 addition & 1 deletion tools/generator/gen_messages_v2_0_c.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''
parse a PPRZLink protocol XML file and generate a C implementation
for version 2.0 of the protocol
Expand Down
2 changes: 1 addition & 1 deletion tools/generator/gen_messages_v2_0_c_standalone.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''
parse a PPRZLink protocol XML file and generate a C implementation
for version 2.0 of the protocol
Expand Down
Empty file removed tools/generator/lib/__init__.py
Empty file.
82 changes: 0 additions & 82 deletions tools/generator/lib/genxmlif/README.txt

This file was deleted.

92 changes: 0 additions & 92 deletions tools/generator/lib/genxmlif/__init__.py

This file was deleted.

139 changes: 0 additions & 139 deletions tools/generator/lib/genxmlif/xmlif4Dom.py

This file was deleted.

0 comments on commit 2bc2c1a

Please sign in to comment.