예제 #1
0
 def _parse(self):
     parser = etree.XMLParser()
     data = StringIO(self._xml_data)
     try:
         self._xml_doc = etree.parse(data, parser)
     except Exception, e:
         raise InvalidObjectError("Invalid XML data. (%s)" % str(e))
예제 #2
0
class XmlTreeDoc(XmlDoc):
    """
    XML document using lxml's element tree parser.
    """
    implements(IXmlTreeDoc)

    def __init__(self, xml_data=None, blocking=False):
        XmlDoc.__init__(self)
        self.errors = list()
        self.options = {
            'blocking': blocking,
        }
        if isinstance(xml_data, basestring):
            self._xml_data = xml_data
        else:
            raise InvalidObjectError("No xml data str was given: %s" %
                                     xml_data)
        self._parse()

    def _parse(self):
        parser = etree.XMLParser()
        data = StringIO(self._xml_data)
        try:
            self._xml_doc = etree.parse(data, parser)
        except Exception, e:
            raise InvalidObjectError("Invalid XML data. (%s)" % str(e))
        self.errors = parser.error_log
        if self.options['blocking'] and len(self.errors) > 0:
            raise InvalidObjectError(self.errors)
        return True
예제 #3
0
 def __init__(self, xml_data=None, blocking=False):
     XmlDoc.__init__(self)
     self.errors = list()
     self.options = {
         'blocking': blocking,
     }
     if isinstance(xml_data, basestring):
         self._xml_data = xml_data
     else:
         raise InvalidObjectError("No xml data str was given: %s" %
                                  xml_data)
     self._parse()
예제 #4
0
 def deleteIndex(self, xmlindex):
     """
     Delete an XMLIndex and all related indexed data from the catalog.
     """
     if not xmlindex._id:
         msg = "DeleteIndex: an XmlIndex has no id."
         raise InvalidObjectError(msg)
     resourcetype = xmlindex.resourcetype
     self.flushIndex(xmlindex)
     self.drop(XmlIndex, _id=xmlindex._id)
     # cache
     self._deleteFromCache(xmlindex)
     # refresh index view
     self.updateIndexView(resourcetype)
예제 #5
0
 def validate(self, xml_doc):
     if not IXmlDoc.providedBy(xml_doc):
         raise DoesNotImplement(IXmlDoc)
     doc = xml_doc.getXml_doc()
     try:
         self.schema.assertValid(doc)
     except AttributeError:
         valid = self.schema.validate(doc)
         if not valid:
             msg = "Could not validate document."
             raise SeisHubError(msg)
     except etree.DocumentInvalid, e:
         msg = "Could not validate document. (%s)"
         raise InvalidObjectError(msg % str(e))
예제 #6
0
 def validateResource(self, resource):
     """
     Do a schema validation of a given resource.
     
     This validates against all schemas of the corresponding resourcetype.
     """
     pid = resource.package.package_id
     rid = resource.resourcetype.resourcetype_id
     schemas = self.env.registry.schemas.get(pid, rid)
     for schema in schemas:
         try:
             schema.validate(resource)
         except Exception, e:
             msg = "Resource-validation against schema '%s' failed. (%s)"
             raise InvalidObjectError(msg % (str(schema.getResource().name),
                                             str(e)))