Package suds :: Package sax :: Module document
[hide private]
[frames] | no frames]

Source Code for Module suds.sax.document

 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  Provides XML I{document} classes. 
19  """ 
20   
21  from logging import getLogger 
22  from suds import * 
23  from suds.sax import * 
24  from suds.sax.element import Element 
25   
26  log = getLogger(__name__) 
27   
28 -class Document(Element):
29 """ simple document """ 30 31 DECL = '<?xml version="1.0" encoding="UTF-8"?>' 32
33 - def __init__(self, root=None):
34 Element.__init__(self, 'document') 35 if root is not None: 36 self.append(root)
37
38 - def root(self):
39 if len(self.children): 40 return self.children[0] 41 else: 42 return None
43
44 - def str(self):
45 s = [] 46 s.append(self.DECL) 47 s.append('\n') 48 s.append(self.root().str()) 49 return ''.join(s)
50
51 - def plain(self):
52 s = [] 53 s.append(self.DECL) 54 s.append(self.root().plain()) 55 return ''.join(s)
56
57 - def __str__(self):
58 return unicode(self).encode('utf-8')
59
60 - def __unicode__(self):
61 return self.str()
62