コード例 #1
0
ファイル: load.py プロジェクト: Zurga/ocrfeeder
    def startElementNS(self, tag, qname, attrs):
        if tag in ((OFFICENS, 'body'), (OFFICENS, 'styles')):
            self.parse = True
        if self.parse == False:
            return

        self.level = self.level + 1
        # Add any accumulated text content
        content = ''.join(self.data).strip()
        if len(content) > 0:
            self.parent.addText(content)
            self.data = []
        # Create the element
        attrdict = {}
        for (att, value) in list(attrs.items()):
            attrdict[att] = value
        try:
            e = element.Element(qname=tag, qattributes=attrdict)
            self.curr = e
        except AttributeError as v:
            print("Error: %s" % v)

        if tag == (OFFICENS, 'styles'):
            self.doc.styles = e
        elif tag == (OFFICENS, 'body'):
            self.doc.body = e
        else:
            self.parent.addElement(e)
        self.parent = e
コード例 #2
0
from odf.opendocument import OpenDocumentText
from odf import text, dc, meta, table, draw, math, element
from mwlib import parser
from mwlib.log import Log
from mwlib import advtree 
from mwlib import odfstyles as style
from mwlib import writerbase
from mwlib.treecleaner import TreeCleaner
from mwlib import odfconf


log = Log("odfwriter")

# using alpha software is challenging as APIs change -------------------
# check for ODF version and monkey patch stuff
e = element.Element(qname = ("a","n"))
if hasattr(e, "elements"): # odfpy-0.7
    def _f(self, c):
        log("assumming odfpy-0.7x")
        self.elements.append(e)
    element.Element.appendChild = _f
    element.Element.lastChild = property(lambda s:s.elements[-1])
    element.Element.setAttribute = element.Element.addAttribute
else:
    # assume the odfpy-08 api is stable
    # but we don't support this now, as they changed their API
    # easy_install odfpy==0.7.0  might help
    raise Exception, "only version 0.7 of odfpy is supported"
    assert hasattr(e, "appendChild")
    assert hasattr(e, "lastChild")
    assert hasattr(e, "setAttribute")