Make xmlast tostring easier to debug

Update samples to work with and without lxml (hopefully)
master
Jason Morgan 1 year ago
parent 7d3e60fb70
commit 2be9a3e519

@ -120,14 +120,15 @@ def thing2xml(thing, pretty=False, object_names=False):
tree = create_tree(thing, None, object_names)
try:
if lxml:
return etree.tostring(tree, pretty_print=pretty)
txt = etree.tostring(tree, pretty_print=pretty)
except NameError:
if __debug__:
if pretty:
warnings.warn("lxml is needed for pretty printing",
ImportWarning)
etree.indent(tree)
return etree.tostring(tree)
txt = etree.tostring(tree)
return txt
def create_thing(element, symbol_table):

@ -58,8 +58,9 @@ pyPEG contains an XML backend, too:
>>> del f[2]
>>> from pypeg2.xmlast import thing2xml
>>> import sys
>>> xml = thing2xml(f, pretty=True)
>>> print(xml.decode()) # doctest: +ELLIPSIS
>>> print(xml.decode(), end="") # doctest: +ELLIPSIS
<Function typing="int" name="f">
<Parameters>
<Parameter typing="int" name="a".../>
@ -68,7 +69,6 @@ pyPEG contains an XML backend, too:
<Instruction>do_this</Instruction>
<Instruction>do_that</Instruction>
</Function>
<BLANKLINE>
The XML backend can read XML text and create things:

@ -65,7 +65,6 @@ pyPEG contains an XML backend, too:
</Section>
<Section name="Number 3".../>
</IniFile>
<BLANKLINE>
In this sample the tree contains named objects only. Then we can output object
names as tag names. Spaces in names will be translated into underscores.
@ -82,7 +81,6 @@ names as tag names. Spaces in names will be translated into underscores.
</Number_2>
<Number_3.../>
</IniFile>
<BLANKLINE>
"""
from __future__ import unicode_literals, print_function

Loading…
Cancel
Save