File: generate.py

package info (click to toggle)
pyxb 1.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 63,792 kB
  • ctags: 48,994
  • sloc: python: 235,928; sh: 803; xml: 657; makefile: 57
file content (36 lines) | stat: -rw-r--r-- 986 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
from __future__ import print_function
import pyxb.bundles.common.xhtml1 as xhtml
import pyxb.utils.domutils

pyxb.utils.domutils.BindingDOMSupport.SetDefaultNamespace(xhtml.Namespace)

head = xhtml.head(title='A Test Document')
body = xhtml.body()
body.append(xhtml.h1('Contents'))
body.append(xhtml.p('''Here is some text.

It doesn't do anything special.'''))

p2 = xhtml.p('Here is more text.  It has ',
             xhtml.b('bold'),
             ' and ',
             xhtml.em('emphasized'),
             ' content with ',
             xhtml.b('more bold'),
             ' just to complicate things.')
body.append(p2)

# Verify we have two b's and an em
assert 2 == len(p2.b)
assert 1 == len(p2.em)

# Generate the document and externally verify that the em is between the two bs.
doc = xhtml.html(head, body)
try:
    xmls = doc.toDOM().toprettyxml()
except pyxb.ValidationError as e:
    print(e.details())
    raise
open('genout.xhtml', 'w').write(xmls)