Package tests :: Module saxenc
[hide private]
[frames] | no frames]

Source Code for Module tests.saxenc

 1  # This program is free software; you can redistribute it and/or modify 
 2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
 3  # published by the Free Software Foundation; either version 3 of the  
 4  # License, or (at your option) any later version. 
 5  # 
 6  # This program is distributed in the hope that it will be useful, 
 7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 9  # GNU Library Lesser General Public License for more details at 
10  # ( http://www.gnu.org/licenses/lgpl.html ). 
11  # 
12  # You should have received a copy of the GNU Lesser General Public License 
13  # along with this program; if not, write to the Free Software 
14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
15  # written by: Jeff Ortel ( jortel@redhat.com ) 
16   
17  # 
18  # sax encoding/decoding test. 
19  # 
20   
21  from suds.sax.element import Element 
22  from suds.sax.parser import Parser 
23   
24 -def basic():
25 xml = "<a>Me &amp;&amp; &lt;b&gt;my&lt;/b&gt; shadow&apos;s &lt;i&gt;dog&lt;/i&gt; love to &apos;play&apos; and sing &quot;la,la,la&quot;;</a>" 26 p = Parser() 27 d = p.parse(string=xml) 28 a = d.root() 29 print 'A(parsed)=\n%s' % a 30 assert str(a) == xml 31 b = Element('a') 32 b.setText('Me &&amp; &lt;b>my</b> shadow\'s <i>dog</i> love to \'play\' and sing "la,la,la";') 33 print 'B(encoded)=\n%s' % b 34 assert str(b) == xml 35 print 'A(text-decoded)=\n%s' % a.getText() 36 print 'B(text-decoded)=\n%s' % b.getText() 37 assert a.getText() == b.getText() 38 print 'test pruning' 39 j = Element('A') 40 j.set('n', 1) 41 j.append(Element('B')) 42 print j 43 j.prune() 44 print j
45
46 -def cdata():
47 xml = '<a><![CDATA[<b>This is my &amp;&lt;tag&gt;</b>]]></a>' 48 p = Parser() 49 d = p.parse(string=xml) 50 print d 51 a = d.root() 52 print a.getText()
53 54 if __name__ == '__main__': 55 #basic() 56 cdata() 57