[Python-checkins] python/dist/src/Lib/xml/dom minidom.py,1.46,1.47

loewis@users.sourceforge.net loewis@users.sourceforge.net
Sun, 30 Jun 2002 08:05:02 -0700


Update of /cvsroot/python/python/dist/src/Lib/xml/dom
In directory usw-pr-cvs1:/tmp/cvs-serv931/Lib/xml/dom

Modified Files:
	minidom.py 
Log Message:
Implement the encoding argument for toxml and toprettyxml.
Document toprettyxml.


Index: minidom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/minidom.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** minidom.py	31 May 2002 20:46:38 -0000	1.46
--- minidom.py	30 Jun 2002 15:05:00 -0000	1.47
***************
*** 66,79 ****
          return 1
  
!     def toxml(self):
!         writer = _get_StringIO()
!         self.writexml(writer)
!         return writer.getvalue()
  
!     def toprettyxml(self, indent="\t", newl="\n"):
          # indent = the indentation string to prepend, per level
          # newl = the newline string to append
          writer = _get_StringIO()
!         self.writexml(writer, "", indent, newl)
          return writer.getvalue()
  
--- 66,85 ----
          return 1
  
!     def toxml(self, encoding = None):
!         return self.toprettyxml("", "", encoding)
  
!     def toprettyxml(self, indent="\t", newl="\n", encoding = None):
          # indent = the indentation string to prepend, per level
          # newl = the newline string to append
          writer = _get_StringIO()
!         if encoding is not None:
!             import codecs
!             # Can't use codecs.getwriter to preserve 2.0 compatibility
!             writer = codecs.lookup(encoding)[3](writer)
!         if self.nodeType == Node.DOCUMENT_NODE:
!             # Can pass encoding only to document, to put it into XML header
!             self.writexml(writer, "", indent, newl, encoding)
!         else:
!             self.writexml(writer, "", indent, newl)
          return writer.getvalue()
  
***************
*** 935,940 ****
                                               NodeList())
  
!     def writexml(self, writer, indent="", addindent="", newl=""):
!         writer.write('<?xml version="1.0" ?>\n')
          for node in self.childNodes:
              node.writexml(writer, indent, addindent, newl)
--- 941,950 ----
                                               NodeList())
  
!     def writexml(self, writer, indent="", addindent="", newl="",
!                  encoding = None):
!         if encoding is None:
!             writer.write('<?xml version="1.0" ?>\n')
!         else:
!             writer.write('<?xml version="1.0" encoding="%s"?>\n' % encoding)
          for node in self.childNodes:
              node.writexml(writer, indent, addindent, newl)