exchanges fyzz query parsing with rdflib functionality

This commit is contained in:
Ronald Steinke 2018-10-14 18:32:03 +02:00
parent 8bf52c8b02
commit cde278501b

View File

@ -6,9 +6,10 @@ from random import choice
from urlparse import urlparse from urlparse import urlparse
import binascii import binascii
import base64 import base64
from xml.sax import SAXParseException
from iso8601.iso8601 import parse_date, ParseError from iso8601.iso8601 import parse_date, ParseError
from fyzz import parse from pyparsing import ParseException
from rdflib import Graph from rdflib import Graph
import openmtc_cse.api as api import openmtc_cse.api as api
@ -1427,7 +1428,7 @@ class SemanticDescriptorController(OneM2MDefaultController):
try: try:
g = Graph() g = Graph()
g.parse(data=data, format="application/rdf+xml") g.parse(data=data, format="application/rdf+xml")
except Exception: except SAXParseException:
raise CSEContentsUnacceptable("The descriptor attribute does not conform to the " raise CSEContentsUnacceptable("The descriptor attribute does not conform to the "
"RDF/XML syntax as defined in RDF 1.1 XML Syntax.") "RDF/XML syntax as defined in RDF 1.1 XML Syntax.")
@ -1455,9 +1456,10 @@ class SemanticDescriptorController(OneM2MDefaultController):
self._check_descriptor_data(self.values["descriptor"]) self._check_descriptor_data(self.values["descriptor"])
elif "semanticOpExec" in values: elif "semanticOpExec" in values:
# verify if the semanticOpExec has a correct SPAROL syntax # verify if the semanticOpExec has a correct SPAROL syntax
g = Graph()
try: try:
parse(values["semanticOpExec"]) g.parse(values["semanticOpExec"])
except Exception: except ParseException:
raise CSEContentsUnacceptable("The semanticOpExec attribute does not conform to " raise CSEContentsUnacceptable("The semanticOpExec attribute does not conform to "
"the SPARQL query syntax.") "the SPARQL query syntax.")
else: else: