Back to index

plone3  3.1.7
Functions | Variables
wicked.testing.xml Namespace Reference

Functions

def libstrip
def lxmlstrip
def test_suite

Variables

 USELIBXML = False
string slug
string xslt
tuple xsltfile = os.path.join(os.path.dirname(__file__), 'strip.xsl')
tuple styledoc = libxml2.parseFile(xsltfile)
tuple style = libxslt.parseStylesheetDoc(styledoc)
 libstrip = None
 xstrip = libstrip
 optionflags = doctest.REPORT_ONLY_FIRST_FAILURE|doctest.ELLIPSIS

Function Documentation

strip out whitespace
>>> print xstrip(slug)
<div><some tag="true"><other></other></some></div>
...

Definition at line 30 of file xml.py.

00030 
00031     def libstrip(text):
00032         """
00033         strip out whitespace
00034         >>> print xstrip(slug)
00035         <div><some tag="true"><other></other></some></div>
00036         ...
00037         """
00038         encoding = 'UTF-8'
00039         INDENT = True
00040         try:
00041             doc = libxml2.parseDoc(text)
00042             res = style.applyStylesheet(doc, None)
00043             # XXX: this raises an unhandled c exception
00044             #res = style.saveResultToString(resdoc)
00045             out = res.serialize(encoding=encoding, format=INDENT)
00046         finally:
00047             try: doc.freeDoc()
00048             except: pass
00049             try: res.freeDoc()
00050             except: pass
00051         return out

strip out whitespace
>>> print xstrip(slug)
<div><some tag="true"><other></other></some></div>
...

Definition at line 56 of file xml.py.

00056 
00057 def lxmlstrip(text):
00058     """
00059     strip out whitespace
00060     >>> print xstrip(slug)
00061     <div><some tag="true"><other></other></some></div>
00062     ...
00063     """
00064     if not text:
00065         return ''
00066     
00067     from lxml import etree
00068     xslt_doc = etree.XML(xslt)
00069     stripper = etree.XSLT(xslt_doc)
00070     doc = etree.XML(text)
00071     result = stripper(doc)
00072     val = str(result)
00073     return val

Definition at line 82 of file xml.py.

00082 
00083 def test_suite():
00084 
00085     return unittest.TestSuite((
00086         doctest.DocTestSuite('xml', optionflags=optionflags)
00087         ))

Here is the call graph for this function:


Variable Documentation

Definition at line 53 of file xml.py.

wicked.testing.xml.optionflags = doctest.REPORT_ONLY_FIRST_FAILURE|doctest.ELLIPSIS

Definition at line 81 of file xml.py.

Initial value:
00001 """ <div><some tag="true">
00002                <other />            </some>
00003      </div>
00004      """

Definition at line 6 of file xml.py.

tuple wicked.testing.xml.style = libxslt.parseStylesheetDoc(styledoc)

Definition at line 28 of file xml.py.

tuple wicked.testing.xml.styledoc = libxml2.parseFile(xsltfile)

Definition at line 27 of file xml.py.

Definition at line 4 of file xml.py.

Initial value:
00001 """
00002 <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
00003   <xsl:output method="html" indent="yes"/>
00004   <xsl:strip-space elements="*"/>
00005   <xsl:template match="@*|node()">
00006     <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
00007   </xsl:template>
00008 </xsl:stylesheet>
00009 """

Definition at line 10 of file xml.py.

tuple wicked.testing.xml.xsltfile = os.path.join(os.path.dirname(__file__), 'strip.xsl')

Definition at line 21 of file xml.py.

Definition at line 75 of file xml.py.