[Python-checkins] CVS: python/dist/src/Lib/xml/sax saxutils.py,1.2,1.3

Fred L. Drake python-dev@python.org
Mon, 18 Sep 2000 10:40:26 -0700


Update of /cvsroot/python/python/dist/src/Lib/xml/sax
In directory slayer.i.sourceforge.net:/tmp/cvs-serv16813

Modified Files:
	saxutils.py 
Log Message:

Reduce the number of imports needed.

Make the code conform better to the Python style guide.


Index: saxutils.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/saxutils.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** saxutils.py	2000/07/01 19:19:32	1.2
--- saxutils.py	2000/09/18 17:40:22	1.3
***************
*** 1,33 ****
! """
! A library of useful helper classes to the sax classes, for the
  convenience of application and driver writers.
- 
- $Id$
  """
  
- import types, string, sys
  import handler
  
! def escape(data, entities = {}):
      """Escape &, <, and > in a string of data.
      You can escape other strings of data by passing a dictionary as 
      the optional entities parameter.  The keys and values must all be
      strings; each key will be replaced with its corresponding value.
      """
!     data = string.replace(data, "&", "&amp;")
!     data = string.replace(data, "<", "&lt;")
!     data = string.replace(data, ">", "&gt;")
      for chars, entity in entities.items():
!         data = string.replace(data, chars, entity)        
      return data
  
  class XMLGenerator(handler.ContentHandler):
  
!     def __init__(self, out = sys.stdout):
          handler.ContentHandler.__init__(self)
          self._out = out
  
      # ContentHandler methods
!         
      def startDocument(self):
          self._out.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
--- 1,36 ----
! """\
! A library of useful helper classes to the SAX classes, for the
  convenience of application and driver writers.
  """
  
  import handler
+ 
  
! def escape(data, entities={}):
      """Escape &, <, and > in a string of data.
+ 
      You can escape other strings of data by passing a dictionary as 
      the optional entities parameter.  The keys and values must all be
      strings; each key will be replaced with its corresponding value.
      """
!     data = data.replace("&", "&amp;")
!     data = data.replace("<", "&lt;")
!     data = data.replace(">", "&gt;")
      for chars, entity in entities.items():
!         data = data.replace(chars, entity)        
      return data
  
+ 
  class XMLGenerator(handler.ContentHandler):
  
!     def __init__(self, out=None):
!         if out is None:
!             import sys
!             out = sys.stdout
          handler.ContentHandler.__init__(self)
          self._out = out
  
      # ContentHandler methods
! 
      def startDocument(self):
          self._out.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
***************
*** 40,46 ****
  
      def startElement(self, name, attrs):
!         if type(name)==type(()):
!             uri, localname, prefix=name
!             name="%s:%s"%(prefix,localname)
          self._out.write('<' + name)
          for (name, value) in attrs.items():
--- 43,49 ----
  
      def startElement(self, name, attrs):
!         if type(name) is type(()):
!             uri, localname, prefix = name
!             name = "%s:%s"%(prefix,localname)
          self._out.write('<' + name)
          for (name, value) in attrs.items():
***************
*** 57,64 ****
      def ignorableWhitespace(self, content):
          self._out.write(content)
!         
      def processingInstruction(self, target, data):
          self._out.write('<?%s %s?>' % (target, data))
  
  class XMLFilterBase:
      """This class is designed to sit between an XMLReader and the
--- 60,68 ----
      def ignorableWhitespace(self, content):
          self._out.write(content)
! 
      def processingInstruction(self, target, data):
          self._out.write('<?%s %s?>' % (target, data))
  
+ 
  class XMLFilterBase:
      """This class is designed to sit between an XMLReader and the
***************
*** 81,88 ****
  
      # ContentHandler methods
!         
      def setDocumentLocator(self, locator):
          self._cont_handler.setDocumentLocator(locator)
!         
      def startDocument(self):
          self._cont_handler.startDocument()
--- 85,92 ----
  
      # ContentHandler methods
! 
      def setDocumentLocator(self, locator):
          self._cont_handler.setDocumentLocator(locator)
! 
      def startDocument(self):
          self._cont_handler.startDocument()
***************
*** 139,143 ****
      def setLocale(self, locale):
          self._parent.setLocale(locale)
!     
      def getFeature(self, name):
          return self._parent.getFeature(name)
--- 143,147 ----
      def setLocale(self, locale):
          self._parent.setLocale(locale)
! 
      def getFeature(self, name):
          return self._parent.getFeature(name)
***************
*** 151,153 ****
      def setProperty(self, name, value):
          self._parent.setProperty(name, value)
-         
--- 155,156 ----