diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2000-09-24 18:54:49 +0000 |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2000-09-24 18:54:49 +0000 |
commit | 523b0a6ec87ac7f84de8a004e3c33581eb2a542f (patch) | |
tree | d12ad6fecb01461ee48a7d55876e56f32d0305fe /Lib/xml/sax/saxutils.py | |
parent | b7536d58606ec06e81453ca8fd1b14292f7427a9 (diff) | |
download | cpython-git-523b0a6ec87ac7f84de8a004e3c33581eb2a542f.tar.gz |
Added back the InputSource class (patch 101630).
Diffstat (limited to 'Lib/xml/sax/saxutils.py')
-rw-r--r-- | Lib/xml/sax/saxutils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py index fe13bdebcf..8f8f42e811 100644 --- a/Lib/xml/sax/saxutils.py +++ b/Lib/xml/sax/saxutils.py @@ -3,6 +3,7 @@ A library of useful helper classes to the SAX classes, for the convenience of application and driver writers. """ +import os, urlparse, urllib import handler import xmlreader @@ -181,3 +182,24 @@ class XMLFilterBase(xmlreader.XMLReader): def setProperty(self, name, value): self._parent.setProperty(name, value) + +# --- Utility functions + +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(""): + source = xmlreader.InputSource(source) + + if source.getByteStream() == None: + sysid = source.getSystemId() + if urlparse.urlparse(sysid)[0] == '': + basehead = os.path.split(os.path.normpath(base))[0] + source.setSystemId(os.path.join(basehead, sysid)) + else: + source.setSystemId(urlparse.urljoin(base, sysid)) + + source.setByteStream(urllib.urlopen(source.getSystemId())) + + return source |