本文整理汇总了Python中odf.opendocument.OpenDocumentText.contentxml方法的典型用法代码示例。如果您正苦于以下问题:Python OpenDocumentText.contentxml方法的具体用法?Python OpenDocumentText.contentxml怎么用?Python OpenDocumentText.contentxml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类odf.opendocument.OpenDocumentText
的用法示例。
在下文中一共展示了OpenDocumentText.contentxml方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUnicode
# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import contentxml [as 别名]
class TestUnicode(unittest.TestCase):
def setUp(self):
self.textdoc = OpenDocumentText()
self.saved = False
def tearDown(self):
if self.saved:
os.unlink("TEST.odt")
def assertContains(self, stack, needle):
self.assertNotEqual(-1, stack.find(needle))
def assertNotContains(self, stack, needle):
self.assertEqual(-1, stack.find(needle))
@unittest.skipIf(sys.version_info[0] != 2,
"For Python3, unicode strings are type 'str'.")
def test_xstyle(self):
self.assertRaises(UnicodeDecodeError, style.Style, name="X✗", family="paragraph")
xstyle = style.Style(name=u"X✗", family=u"paragraph")
pp = style.ParagraphProperties(padding=u"0.2cm")
pp.setAttribute(u"backgroundcolor", u"rød")
xstyle.addElement(pp)
self.textdoc.styles.addElement(xstyle)
self.textdoc.save(u"TEST.odt")
self.saved = True
def test_text(self):
p = P(text=u"Æblegrød")
p.addText(u' Blåbærgrød')
self.textdoc.text.addElement(p)
self.textdoc.save(u"TEST.odt")
self.saved = True
def test_contenttext(self):
p = H(outlinelevel=1,text=u"Æblegrød")
p.addText(u' Blåbærgrød')
self.textdoc.text.addElement(p)
c = self.textdoc.contentxml() # contentxml is supposed to yield a bytes
self.assertContains(c, b'<office:body><office:text><text:h text:outline-level="1">\xc3\x86blegr\xc3\xb8d Bl\xc3\xa5b\xc3\xa6rgr\xc3\xb8d</text:h></office:text></office:body>')
self.assertContains(c, b'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
self.assertContains(c, b'<office:automatic-styles/>')
def test_illegaltext(self):
p = H(outlinelevel=1,text=u"Spot \u001e the")
p.addText(u' d\u00a3libe\u0000rate \ud801 mistakes\U0002fffe')
self.textdoc.text.addElement(p)
c = self.textdoc.contentxml() # contentxml is supposed to yield a bytes
# unicode replacement char \UFFFD === \xef\xbf\xbd in UTF-8
self.assertContains(c, b'<office:body><office:text><text:h text:outline-level="1">Spot \xef\xbf\xbd the d\xc2\xa3libe\xef\xbf\xbdrate \xef\xbf\xbd mistakes\xef\xbf\xbd</text:h></office:text></office:body>')
self.assertContains(c, b'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
self.assertContains(c, b'<office:automatic-styles/>')
示例2: TestUnicode
# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import contentxml [as 别名]
class TestUnicode(unittest.TestCase):
def setUp(self):
self.textdoc = OpenDocumentText()
self.saved = False
def tearDown(self):
if self.saved:
os.unlink("TEST.odt")
def test_subobject(self):
df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
self.textdoc.text.addElement(df)
subdoc = OpenDocumentText()
# Here we add the subdocument to the main document. We get back a reference
# to use in the href.
subloc = self.textdoc.addObject(subdoc)
self.assertEqual(subloc, "./Object 1")
do = draw.Object(href=subloc)
df.addElement(do)
subsubdoc = OpenDocumentText()
subsubloc = subdoc.addObject(subsubdoc)
self.assertEqual(subsubloc, "./Object 1/Object 1")
c = unicode(self.textdoc.contentxml(), "UTF-8")
c.index(
u'<office:body><office:text><draw:frame svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt"><draw:object xlink:href="./Object 1"/></draw:frame></office:text></office:body>'
)
c.index(u'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
self.textdoc.save("TEST.odt")
self.saved = True
m = _getxmlpart("TEST.odt", "META-INF/manifest.xml")
m.index(
'<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"/>'
)
m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>')
m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>')
m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>')
m.index(
'<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/"/>'
)
m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/styles.xml"/>')
m.index('<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/content.xml"/>')
m.index(
'<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/Object 1/"/>'
)
m.index(
'<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/styles.xml"/>'
)
m.index(
'<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/content.xml"/>'
)
示例3: TestUnicode
# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import contentxml [as 别名]
class TestUnicode(unittest.TestCase):
def setUp(self):
self.textdoc = OpenDocumentText()
self.saved = False
def tearDown(self):
if self.saved:
os.unlink("TEST.odt")
def test_subobject(self):
df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
self.textdoc.text.addElement(df)
subdoc = OpenDocumentText()
# Here we add the subdocument to the main document. We get back a reference
# to use in the href.
subloc = self.textdoc.addObject(subdoc)
self.assertEqual(subloc,'./Object 1')
do = draw.Object(href=subloc)
df.addElement(do)
subsubdoc = OpenDocumentText()
subsubloc = subdoc.addObject(subsubdoc)
self.assertEqual(subsubloc,'./Object 1/Object 1')
c = self.textdoc.contentxml() # contentxml() is supposed to yeld a bytes
c.index(b'<office:body><office:text><draw:frame ')
e = ElementParser(c.decode("utf-8"), u'draw:frame')
# e = ElementParser('<draw:frame svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt">')
self.assertTrue(e.has_value(u'svg:width',"476pt"))
self.assertTrue(e.has_value(u'svg:height',"404pt"))
self.assertTrue(e.has_value(u'text:anchor-type',"paragraph"))
self.assertFalse(e.has_value(u'svg:height',"476pt"))
c.index(b'<draw:object xlink:href="./Object 1"/></draw:frame></office:text></office:body>')
c.index(b'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
self.textdoc.save(u"TEST.odt")
self.saved = True
m = _getxmlpart(u"TEST.odt", u"META-INF/manifest.xml").decode('utf-8')
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="content.xml"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="meta.xml"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/styles.xml"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/content.xml"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/Object 1/"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/styles.xml"'))
assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/content.xml"'))
示例4: testAutomaticStyles
# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import contentxml [as 别名]
def testAutomaticStyles(self):
""" Create a text document with a page layout called "pagelayout"
Add a master page
Add an automatic style for the heading
Check that pagelayout is listed in styles.xml under automatic-styles
Check that the heading style is NOT listed in styles.xml
Check that the pagelayout is NOT listed in content.xml
"""
textdoc = OpenDocumentText()
parastyle = style.Style(name="Para", family="paragraph")
parastyle.addElement(style.ParagraphProperties(numberlines="false", linenumber="0"))
parastyle.addElement(style.TextProperties(fontsize="24pt", fontweight="bold"))
textdoc.automaticstyles.addElement(parastyle)
hpstyle = style.Style(name="HeaderPara", family="paragraph")
hpstyle.addElement(style.ParagraphProperties(linenumber="0"))
hpstyle.addElement(style.TextProperties(fontsize="18pt", fontstyle="italic"))
textdoc.automaticstyles.addElement(hpstyle)
pl = style.PageLayout(name="pagelayout")
textdoc.automaticstyles.addElement(pl)
mp = style.MasterPage(name="Standard", pagelayoutname=pl)
textdoc.masterstyles.addElement(mp)
h = style.Header()
hp = text.P(text="header content", stylename=hpstyle)
h.addElement(hp)
mp.addElement(h)
textdoc.text.addElement(text.P(text="Paragraph 1", stylename=parastyle))
# Check styles.xml
s = unicode(textdoc.stylesxml(),'UTF-8')
self.assertContains(s, u'<style:page-layout style:name="pagelayout"/>')
self.assertContains(s, u'style:name="HeaderPara"')
self.assertNotContains(s, u'style:name="Para" ')
# Check content.xml
s = unicode(textdoc.contentxml(),'UTF-8')
self.assertNotContains(s, u'<style:page-layout style:name="pagelayout"/>')
self.assertContains(s, u'style:name="Para" ')
示例5: TestUnicode
# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import contentxml [as 别名]
class TestUnicode(unittest.TestCase):
def setUp(self):
self.textdoc = OpenDocumentText()
self.saved = False
def tearDown(self):
if self.saved:
os.unlink("TEST.odt")
def assertContains(self, stack, needle):
self.assertNotEqual(-1, stack.find(needle))
def assertNotContains(self, stack, needle):
self.assertEquals(-1, stack.find(needle))
def test_xstyle(self):
self.assertRaises(UnicodeDecodeError, style.Style, name="X✗", family="paragraph")
xstyle = style.Style(name=u"X✗", family=u"paragraph")
pp = style.ParagraphProperties(padding=u"0.2cm")
pp.setAttribute(u"backgroundcolor", u"rød")
xstyle.addElement(pp)
self.textdoc.styles.addElement(xstyle)
self.textdoc.save(u"TEST.odt")
self.saved = True
def test_text(self):
p = P(text=u"Æblegrød")
p.addText(u' Blåbærgrød')
self.textdoc.text.addElement(p)
self.textdoc.save(u"TEST.odt")
self.saved = True
def test_contenttext(self):
p = H(outlinelevel=1,text=u"Æblegrød")
p.addText(u' Blåbærgrød')
self.textdoc.text.addElement(p)
c = self.textdoc.contentxml() # contentxml is supposed to yeld a bytes
self.assertContains(c, b'<office:body><office:text><text:h text:outline-level="1">\xc3\x86blegr\xc3\xb8d Bl\xc3\xa5b\xc3\xa6rgr\xc3\xb8d</text:h></office:text></office:body>')
self.assertContains(c, b'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
self.assertContains(c, b'<office:automatic-styles/>')