summaryrefslogtreecommitdiff
path: root/Lib/xml/sax/saxutils.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2000-09-24 21:31:06 +0000
committerMartin v. Löwis <martin@v.loewis.de>2000-09-24 21:31:06 +0000
commit58af43fd760c2d7d0d8238b7919cf8fa9f1b6dbe (patch)
treedc6f958ea915438ae6c4316c253d2a3e6f05b7ee /Lib/xml/sax/saxutils.py
parenteedb5764a51ce4f18c2505ecad9c55d18be22961 (diff)
downloadcpython-git-58af43fd760c2d7d0d8238b7919cf8fa9f1b6dbe.tar.gz
[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
Diffstat (limited to 'Lib/xml/sax/saxutils.py')
-rw-r--r--Lib/xml/sax/saxutils.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py
index 8f8f42e811..3f130f3af5 100644
--- a/Lib/xml/sax/saxutils.py
+++ b/Lib/xml/sax/saxutils.py
@@ -3,10 +3,12 @@ A library of useful helper classes to the SAX classes, for the
convenience of application and driver writers.
"""
-import os, urlparse, urllib
+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.
@@ -189,8 +191,12 @@ def prepare_input_source(source, base = ""):
"""This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading."""
- if type(source) == type(""):
+ 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:
sysid = source.getSystemId()