Exemple #1
0
    def build_static(self):
        documents = []
        for document in self.static:
            # Building is as simple as creating a new Document instance to
            # reflect the converted paths.
            document = copy.copy(document)
            document.source = util.convert_path(document.source)
            documents.append(document)

        # Validate the content
        if self.validate:
            from xml.sax.handler import feature_validation
            from Ft.Xml.InputSource import DefaultFactory
            from Ft.Xml.Sax import CreateParser

            class ErrorHandler:
                def __init__(self, displayhook):
                    self.displayhook = displayhook
                def warning(self, exception):
                    self.displayhook(exception)
                def error(self, exception):
                    self.displayhook(exception)
                def fatalError(self, exception):
                    raise exception

            parser = CreateParser()
            parser.setFeature(feature_validation, True)
            parser.setErrorHandler(ErrorHandler(self.warn))

            for document in documents:
                self.announce('validating %s' % document.source, 2)
                parser.parse(DefaultFactory.fromUri(document.source))
        return documents
Exemple #2
0
def transform(self, node):
    import FragmentFilter
    from Ft.Xml.Sax import CreateParser, DomBuilder
    rules = FragmentFilter.RulesLoader()
    parser = CreateParser()
    parser.setContentHandler(rules)
    parser.setFeature(xml.sax.handler.property_dom_node, self.applyElt.dom)
    parser.parse(None)
    fragFilter = FragmentFilter.FragmentFilter(rules)
    parser.setContentHandler(fragFilter)
    parser.setFeature(xml.sax.handler.property_dom_node, node)

    parser.setContentHandler(fragFilter)
    builder = DomBuilder()
    fragFilter.setContentHandler(builder)
    try:
        parser.parse(None)
    except:
        return None
    #print "reg frag result: %s" % domg.getRootNode().childNodes[1]
    return builder.getDocument().documentElement
Exemple #3
0
    def _parseXmlCat(self, data):
        """
        Parse an XML Catalog, as specified in
        http://www.oasis-open.org/committees/entity/spec-2001-08-06.html.
        Partially implemented.
        """
        self.prefer_public = [True]
        self.base = [self.uri]

        # Since we have the catalog data already, parse it.
        source = xmlreader.InputSource(self.uri)
        source.setByteStream(cStringIO.StringIO(data))

        from Ft.Xml.Sax import CreateParser
        p = CreateParser()
        p.setFeature(
          'http://xml.org/sax/features/external-parameter-entities', False)
        p.setContentHandler(self)
        p.parse(source)

        # are these explicit dels needed?
        del self.prefer_public
        del self.base
        return
Exemple #4
0
    def _parseXmlCat(self, data):
        """
        Parse an XML Catalog, as specified in
        http://www.oasis-open.org/committees/entity/spec-2001-08-06.html.
        Partially implemented.
        """
        self.prefer_public = [True]
        self.base = [self.uri]

        # Since we have the catalog data already, parse it.
        source = xmlreader.InputSource(self.uri)
        source.setByteStream(cStringIO.StringIO(data))

        from Ft.Xml.Sax import CreateParser
        p = CreateParser()
        p.setFeature('http://xml.org/sax/features/external-parameter-entities',
                     False)
        p.setContentHandler(self)
        p.parse(source)

        # are these explicit dels needed?
        del self.prefer_public
        del self.base
        return