[Python-checkins] CVS: python/dist/src/Lib/xml/sax __init__.py,1.11,1.12 saxutils.py,1.6,1.7

Martin v. Löwis python-dev@python.org
Sun, 24 Sep 2000 14:31:09 -0700


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

Modified Files:
	__init__.py saxutils.py 
Log Message:
[Patch 101634]
xml.sax: Fix parse and parseString not to rely on ExpatParser
         Greatly simplify import logic by using __import__
saxutils: Support Unicode strings and files as parameters to
          prepare_input_source


Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/__init__.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** __init__.py	2000/09/24 20:38:18	1.11
--- __init__.py	2000/09/24 21:31:06	1.12
***************
*** 27,31 ****
  
  def parse(source, handler, errorHandler=ErrorHandler()):
!     parser = ExpatParser()
      parser.setContentHandler(handler)
      parser.setErrorHandler(errorHandler)
--- 27,31 ----
  
  def parse(source, handler, errorHandler=ErrorHandler()):
!     parser = make_parser()
      parser.setContentHandler(handler)
      parser.setErrorHandler(errorHandler)
***************
*** 40,44 ****
      if errorHandler is None:
          errorHandler = ErrorHandler()
!     parser = ExpatParser()
      parser.setContentHandler(handler)
      parser.setErrorHandler(errorHandler)
--- 40,44 ----
      if errorHandler is None:
          errorHandler = ErrorHandler()
!     parser = make_parser()
      parser.setContentHandler(handler)
      parser.setErrorHandler(errorHandler)
***************
*** 88,114 ****
  
  else:
-     import imp as _imp
- 
-     def _rec_find_module(module):
-         "Improvement over imp.find_module which finds submodules."
-         path=""
-         for mod in string.split(module,"."):
-             if path == "":
-                 info = (mod,) + _imp.find_module(mod)
-             else:
-                 info = (mod,) + _imp.find_module(mod, [path])
-                 
-             lastmod = _imp.load_module(*info)
- 
-             try:
-                 path = lastmod.__path__[0]
-             except AttributeError, e:
-                 pass
- 
-         return info
- 
      def _create_parser(parser_name):
!         info = _rec_find_module(parser_name)
!         drv_module = _imp.load_module(*info)
          return drv_module.create_parser()
  
--- 88,93 ----
  
  else:
      def _create_parser(parser_name):
!         drv_module = __import__(parser_name,{},{},['create_parser'])
          return drv_module.create_parser()
  

Index: saxutils.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/saxutils.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** saxutils.py	2000/09/24 18:54:49	1.6
--- saxutils.py	2000/09/24 21:31:06	1.7
***************
*** 4,11 ****
  """
  
! import os, urlparse, urllib
  import handler
  import xmlreader
  
  def escape(data, entities={}):
      """Escape &, <, and > in a string of data.
--- 4,13 ----
  """
  
! import os, urlparse, urllib, types
  import handler
  import xmlreader
  
+ _StringTypes = [types.StringType, types.UnicodeType]
+ 
  def escape(data, entities={}):
      """Escape &, <, and > in a string of data.
***************
*** 190,195 ****
      returns a fully resolved InputSource object ready for reading."""
      
!     if type(source) == type(""):
          source = xmlreader.InputSource(source)
  
      if source.getByteStream() == None:
--- 192,201 ----
      returns a fully resolved InputSource object ready for reading."""
      
!     if type(source) in _StringTypes:
!         source = xmlreader.InputSource(source)
!     elif hasattr(source, "read"):
!         f = source
          source = xmlreader.InputSource(source)
+         source.setByteStream(f)
  
      if source.getByteStream() == None: