Beispiel #1
0
def uixml(scwin, uixslt):
    extidx = uixslt.rindex('.')
    xslt2 = uixslt[:extidx] + "Post" + uixslt[extidx:]
    sctemplate = XMLHelper.writexml(scwin.asXML(True), UnicodeStringIO(), '',
                                    '\t', '\n')

    try:
        source = DefaultFactory.fromString(sctemplate, "urn:pass1")
        xsltUri = OsPathToUri(uixslt)
        transform = DefaultFactory.fromUri(xsltUri)

        processor = Processor.Processor()
        processor.appendStylesheet(transform)
        uixmlstr = processor.run(source)

        if os.path.exists(xslt2):
            source = DefaultFactory.fromString(uixmlstr, "urn:pass2")
            xsltUri = OsPathToUri(xslt2)
            transform = DefaultFactory.fromUri(xsltUri)

            processor = Processor.Processor()
            processor.appendStylesheet(transform)
            uixmlstr = processor.run(source)
    except Exception, e:
        QMessageBox.critical(None, 'Error!',
                             'Error with XSLT transform!\n\n' + str(e), 'OK')
        return
Beispiel #2
0
    def render_document(self, document, stylesheet, outfile):
        """
        This method is responsible for using 'stylesheet' to transform
        'document' to the file 'outfile'.

        Override this method to use a different XSLT rendering engine.
        """
        from Ft.Xml.InputSource import DefaultFactory
        from Ft.Xml.Xslt import Processor

        # Get a "clean" processor object
        if self._xslt_processor is None:
            self._xslt_processor = Processor.Processor()
        else:
            self._xslt_processor.reset()

        # Add the stylesheet to the processor object.
        isrc = DefaultFactory.fromUri(stylesheet.uri)
        try:
            self._xslt_processor.appendStylesheet(isrc)
        finally:
            isrc.close()

        params = {
            'name': self.distribution.get_name(),
            'version': self.distribution.version,
            'fullname': self.distribution.get_fullname(),
            'author': self.distribution.author,
            'author-email': self.distribution.author_email,
        }
        params.update(document.params)

        # Render the document
        isrc = DefaultFactory.fromUri(document.uri)
        try:
            if self.dry_run:
                stream = cStringIO.StringIO()
            else:
                self.mkpath(os.path.dirname(outfile))
                stream = open(outfile, 'w')
            try:
                try:
                    self._xslt_processor.run(isrc,
                                             topLevelParams=params,
                                             outputStream=stream)
                    stream.write('\n')
                finally:
                    stream.close()
            except:
                if not self.dry_run:
                    os.remove(outfile)
                raise
        finally:
            isrc.close()
        return
    def render_document(self, document, stylesheet, outfile):
        """
        This method is responsible for using 'stylesheet' to transform
        'document' to the file 'outfile'.

        Override this method to use a different XSLT rendering engine.
        """
        from Ft.Xml.InputSource import DefaultFactory
        from Ft.Xml.Xslt import Processor

        # Get a "clean" processor object
        if self._xslt_processor is None:
            self._xslt_processor = Processor.Processor()
        else:
            self._xslt_processor.reset()

        # Add the stylesheet to the processor object.
        isrc = DefaultFactory.fromUri(stylesheet.uri)
        try:
            self._xslt_processor.appendStylesheet(isrc)
        finally:
            isrc.close()

        params = {'name' : self.distribution.get_name(),
                  'version' : self.distribution.version,
                  'fullname' : self.distribution.get_fullname(),
                  'author' : self.distribution.author,
                  'author-email' : self.distribution.author_email,
                  }
        params.update(document.params)

        # Render the document
        isrc = DefaultFactory.fromUri(document.uri)
        try:
            if self.dry_run:
                stream = cStringIO.StringIO()
            else:
                self.mkpath(os.path.dirname(outfile))
                stream = open(outfile, 'w')
            try:
                try:
                    self._xslt_processor.run(isrc, topLevelParams=params,
                                             outputStream=stream)
                    stream.write('\n')
                finally:
                    stream.close()
            except:
                if not self.dry_run:
                    os.remove(outfile)
                raise
        finally:
            isrc.close()
        return
    def __init__(self,iptFile,ctFile,truncTime):
        # Read epidemic and truncate to truncTime
        self.infectives = []
        self.labels = []
        epiFile = open(iptFile,'r')
        for line in epiFile:
            toks = line.split()
            label = atoi(toks[0])
            I = atof(toks[1])
            N = atof(toks[2])
            R = atof(toks[3])
            if N <= truncTime: # Take individuals who have been notified by truncTime
                if R > truncTime: # If R > truncTime, set R = truncTime
                    R = truncTime
                self.infectives.append(Infective(label,I,N,R))
                self.labels.append(label)
        epiFile.close()

                
        # Read in XML
        conFile = Uri.OsPathToUri(ctFile)
        xmlSrc = DefaultFactory.fromUri(conFile,stripElements=[(EMPTY_NAMESPACE,'*',1)])
        self.doc = NonvalidatingReader.parse(xmlSrc)

        # Remove from the contact DOM any contact info
        #   for individuals that are not present in labels
        self.labels = set(self.labels)
        for contact in self.doc.documentElement.xpath(u'tc:contact',explicitNss={u'tc':u'tracedcontacts'}):
            contactLabel = atoi(contact.getAttributeNS(None,u'id'))
            if contactLabel not in self.labels:
                self.doc.documentElement.removeChild(contact)
Beispiel #5
0
    def download(self, xmlobj, whichStyleSheet="styleSheet.xsl"):
  
        """Download XML to EEPROM, use broken method. This will likely fail if
        line is longer than reciever's buffer size."""
        #xml = testmeasurements.get_string(xmlobj)
        xml = get_string(xmlobj)
        from Ft.Lib import Uri
        from Ft.Xml.Xslt import Transform
        from Ft.Xml.InputSource import DefaultFactory
        import os.path
        #STYLESHEET = os.path.join(os.environ["STRATATEST_HOME"], 'etc', 'styleSheet.xsl')
        STYLESHEET = os.path.join(os.environ["STRATATEST_HOME"], 'etc', whichStyleSheet)
        #print "XML: %s" % xml
        xsltFile = DefaultFactory.fromUri(Uri.OsPathToUri(STYLESHEET))
        result = Transform(xml, xsltFile)
        #print "******** result: %s ********" % result
        if (result == ""):
            # This is a fall back in case the xsl stylesheet found no matches.
            print >>sys.stderr, "Warning: XSL didn't match any xml elements."
            result = xml
            
        #5/16/07 - dave 
        #self._docommand("download clear")

        for line in result.split("\n"):
            self.info("line: %s" % line)
        time.sleep(1)
            #self._download_line(line)
        return  
Beispiel #6
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
Beispiel #7
0
def test_locator_ft(tester):
    tester.startTest("4Suite InputSource")
    parser = CreateParser()
    parser.setContentHandler(LocatorTester(tester))
    parser.parse(DefaultFactory.fromUri(CONTENT_URI))
    verify_finished_locator(tester, parser)
    tester.testDone()
    return
def test_locator_ft(tester):
    tester.startTest("4Suite InputSource")
    parser = CreateParser()
    parser.setContentHandler(LocatorTester(tester))
    parser.parse(DefaultFactory.fromUri(CONTENT_URI))
    verify_finished_locator(tester, parser)
    tester.testDone()
    return
Beispiel #9
0
def test_xmlreader_ft(tester):
    tester.startTest("4Suite InputSource")
    parser = CreateParser()
    builder = DomBuilder()
    parser.setContentHandler(builder)
    parser.parse(DefaultFactory.fromUri(CONTENT_URI))
    tester.compare(XMLREADER_CONTENT, builder, func=compare_builder)
    tester.testDone()
    return
Beispiel #10
0
def test_xmlreader_ft(tester):
    tester.startTest("4Suite InputSource")
    parser = CreateParser()
    builder = DomBuilder()
    parser.setContentHandler(builder)
    parser.parse(DefaultFactory.fromUri(CONTENT_URI))
    tester.compare(XMLREADER_CONTENT, builder, func=compare_builder)
    tester.testDone()
    return
Beispiel #11
0
    def build_dom_and_apply_style_sheet(self, xsl, file):
        #doc = xml.dom.minidom.Document()
        doc = implementation.createRootNode('file:///article.xml')

        self.app.ann_frame.build_xml(doc)

        xsltproc = Processor()
        xsltproc.appendStylesheet(DefaultFactory.fromUri(Uri.OsPathToUri(xsl)))
        output = xsltproc.runNode(doc, 'file:///article.xml')

        outFile = open(file, 'w')
        outFile.write(output)
        outFile.close()
Beispiel #12
0
    def build_dom_and_apply_style_sheet(self, xsl, file):
        #doc = xml.dom.minidom.Document()
        doc = implementation.createRootNode('file:///article.xml')

        self.app.ann_frame.build_xml(doc)
            
        xsltproc = Processor()
        xsltproc.appendStylesheet(DefaultFactory.fromUri(Uri.OsPathToUri(xsl)))
        output = xsltproc.runNode(doc, 'file:///article.xml')

        outFile = open(file,'w')
        outFile.write(output)
        outFile.close()                  
def main():
    """
    """
    feed_format = ( len(sys.argv) > 1 ) and sys.argv[1] or 'atom'
    feed_url    = ( len(sys.argv) > 2 ) and sys.argv[2] or FEED_URL
    
    source    = DefaultFactory.fromUri(feed_url)
    
    trans_fin = open('ch14_xslt_normalizer.xsl', 'r')
    trans_url = 'http://www.decafbad.com/2005/04/ch14_xslt_normalizer.xsl'
    transform = DefaultFactory.fromStream(trans_fin, trans_url)
    
    processor = Processor.Processor()
    processor.appendStylesheet(transform)
    
    result = processor.run(source, 
                           topLevelParams={'format':feed_format})
    print result
Beispiel #14
0
def mongetattr(ins, attname):
    print "Aie!"
    return None


def monset(ins, d):
    print "On défini un truc sur le contexte"
    ancienset(ins, d)


def monsetattr(ins, attname, val):
    print "HeHo !"


print Ft.Xml.Xslt.XsltContext.XsltContext.__dict__.keys()
Ft.Xml.Xslt.XsltContext.XsltContext.__dict__['set'] = monset
Ft.Xml.Xslt.XsltContext.XsltContext.__dict__['addDocument'] = monsetattr
Ft.Xml.Xslt.XsltContext.XsltContext.__dict__['__setattr__'] = monsetattr
print Ft.Xml.Xslt.XsltContext.XsltContext.__dict__.keys()
xsltproc = Processor()

xsltproc.appendStylesheet(
    DefaultFactory.fromUri(
        "file:///home/t0rt00se/Travail/SILR3/pTrans/testset/persons_to_xhtml_list.xsl"
    ))
html = xsltproc.run(
    DefaultFactory.fromUri(
        "file:///home/t0rt00se/Travail/SILR3/pTrans/testset/persons.xml"))
print html
import Ft
from Ft.Xml.InputSource import DefaultFactory
import trace,sys


from xml.xpath import Context, Util

ancienset = Ft.Xml.Xslt.XsltContext.XsltContext.set
def mongetattr(ins,attname):
  print "Aie!"
  return None

def monset(ins,d):
  print "On défini un truc sur le contexte"
  ancienset(ins,d)
  

def monsetattr(ins,attname,val):
  print "HeHo !"

print Ft.Xml.Xslt.XsltContext.XsltContext.__dict__.keys()
Ft.Xml.Xslt.XsltContext.XsltContext.__dict__['set'] = monset
Ft.Xml.Xslt.XsltContext.XsltContext.__dict__['addDocument'] = monsetattr
Ft.Xml.Xslt.XsltContext.XsltContext.__dict__['__setattr__'] = monsetattr
print Ft.Xml.Xslt.XsltContext.XsltContext.__dict__.keys()
xsltproc = Processor()

xsltproc.appendStylesheet(DefaultFactory.fromUri("file:///home/t0rt00se/Travail/SILR3/pTrans/testset/persons_to_xhtml_list.xsl"))
html = xsltproc.run(DefaultFactory.fromUri("file:///home/t0rt00se/Travail/SILR3/pTrans/testset/persons.xml"))
print html