| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | """\
 | 
					
						
							|  |  |  | A library of useful helper classes to the SAX classes, for the | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | convenience of application and driver writers. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-24 21:31:06 +00:00
										 |  |  | import os, urlparse, urllib, types | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | import handler | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  | import xmlreader | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-16 01:45:11 +00:00
										 |  |  | try: | 
					
						
							|  |  |  |     _StringTypes = [types.StringType, types.UnicodeType] | 
					
						
							|  |  |  | except AttributeError: | 
					
						
							|  |  |  |     _StringTypes = [types.StringType] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  | # See whether the xmlcharrefreplace error handler is | 
					
						
							|  |  |  | # supported | 
					
						
							|  |  |  | try: | 
					
						
							|  |  |  |     from codecs import xmlcharrefreplace_errors | 
					
						
							|  |  |  |     _error_handling = "xmlcharrefreplace" | 
					
						
							|  |  |  |     del xmlcharrefreplace_errors | 
					
						
							|  |  |  | except ImportError: | 
					
						
							|  |  |  |     _error_handling = "strict" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-26 14:50:45 +00:00
										 |  |  | def __dict_replace(s, d): | 
					
						
							|  |  |  |     """Replace substrings of a string using a dictionary.""" | 
					
						
							|  |  |  |     for key, value in d.items(): | 
					
						
							|  |  |  |         s = s.replace(key, value) | 
					
						
							|  |  |  |     return s | 
					
						
							| 
									
										
										
										
											2000-09-24 21:31:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | def escape(data, entities={}): | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     """Escape &, <, and > in a string of data.
 | 
					
						
							| 
									
										
										
										
											2003-04-24 16:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  |     You can escape other strings of data by passing a dictionary as | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     the optional entities parameter.  The keys and values must all be | 
					
						
							|  |  |  |     strings; each key will be replaced with its corresponding value. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2002-10-26 14:50:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # must do ampersand first | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  |     data = data.replace("&", "&") | 
					
						
							| 
									
										
										
										
											2002-10-28 17:29:01 +00:00
										 |  |  |     data = data.replace(">", ">") | 
					
						
							|  |  |  |     data = data.replace("<", "<") | 
					
						
							|  |  |  |     if entities: | 
					
						
							|  |  |  |         data = __dict_replace(data, entities) | 
					
						
							|  |  |  |     return data | 
					
						
							| 
									
										
										
										
											2002-10-26 14:50:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def unescape(data, entities={}): | 
					
						
							|  |  |  |     """Unescape &, <, and > in a string of data.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     You can unescape 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. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2002-10-28 17:29:01 +00:00
										 |  |  |     data = data.replace("<", "<") | 
					
						
							|  |  |  |     data = data.replace(">", ">") | 
					
						
							|  |  |  |     if entities: | 
					
						
							|  |  |  |         data = __dict_replace(data, entities) | 
					
						
							| 
									
										
										
										
											2002-10-28 17:46:59 +00:00
										 |  |  |     # must do ampersand last | 
					
						
							| 
									
										
										
										
											2002-10-28 18:09:41 +00:00
										 |  |  |     return data.replace("&", "&") | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-19 16:10:15 +00:00
										 |  |  | def quoteattr(data, entities={}): | 
					
						
							|  |  |  |     """Escape and quote an attribute value.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Escape &, <, and > in a string of data, then quote it for use as | 
					
						
							|  |  |  |     an attribute value.  The \" character will be escaped as well, if | 
					
						
							|  |  |  |     necessary. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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 = escape(data, entities) | 
					
						
							|  |  |  |     if '"' in data: | 
					
						
							|  |  |  |         if "'" in data: | 
					
						
							|  |  |  |             data = '"%s"' % data.replace('"', """) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             data = "'%s'" % data | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         data = '"%s"' % data | 
					
						
							|  |  |  |     return data | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | class XMLGenerator(handler.ContentHandler): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |     def __init__(self, out=None, encoding="iso-8859-1"): | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  |         if out is None: | 
					
						
							|  |  |  |             import sys | 
					
						
							|  |  |  |             out = sys.stdout | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |         handler.ContentHandler.__init__(self) | 
					
						
							|  |  |  |         self._out = out | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |         self._ns_contexts = [{}] # contains uri -> prefix dicts | 
					
						
							|  |  |  |         self._current_context = self._ns_contexts[-1] | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  |         self._undeclared_ns_maps = [] | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |         self._encoding = encoding | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |     def _write(self, text): | 
					
						
							|  |  |  |         if isinstance(text, str): | 
					
						
							|  |  |  |             self._out.write(text) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self._out.write(text.encode(self._encoding, _error_handling)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     # ContentHandler methods | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     def startDocument(self): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write('<?xml version="1.0" encoding="%s"?>\n' % | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |                         self._encoding) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def startPrefixMapping(self, prefix, uri): | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |         self._ns_contexts.append(self._current_context.copy()) | 
					
						
							|  |  |  |         self._current_context[uri] = prefix | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  |         self._undeclared_ns_maps.append((prefix, uri)) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def endPrefixMapping(self, prefix): | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  |         self._current_context = self._ns_contexts[-1] | 
					
						
							|  |  |  |         del self._ns_contexts[-1] | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def startElement(self, name, attrs): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write('<' + name) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |         for (name, value) in attrs.items(): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |             self._write(' %s=%s' % (name, quoteattr(value))) | 
					
						
							|  |  |  |         self._write('>') | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     def endElement(self, name): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write('</%s>' % name) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |     def startElementNS(self, name, qname, attrs): | 
					
						
							| 
									
										
										
										
											2000-10-03 22:35:29 +00:00
										 |  |  |         if name[0] is None: | 
					
						
							|  |  |  |             # if the name was not namespace-scoped, use the unqualified part | 
					
						
							|  |  |  |             name = name[1] | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             # else try to restore the original prefix from the namespace | 
					
						
							|  |  |  |             name = self._current_context[name[0]] + ":" + name[1] | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write('<' + name) | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for pair in self._undeclared_ns_maps: | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |             self._write(' xmlns:%s="%s"' % pair) | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  |         self._undeclared_ns_maps = [] | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |         for (name, value) in attrs.items(): | 
					
						
							|  |  |  |             name = self._current_context[name[0]] + ":" + name[1] | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |             self._write(' %s=%s' % (name, quoteattr(value))) | 
					
						
							|  |  |  |         self._write('>') | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def endElementNS(self, name, qname): | 
					
						
							| 
									
										
										
										
											2000-10-03 22:35:29 +00:00
										 |  |  |         if name[0] is None: | 
					
						
							|  |  |  |             name = name[1] | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             name = self._current_context[name[0]] + ":" + name[1] | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write('</%s>' % name) | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     def characters(self, content): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write(escape(content)) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def ignorableWhitespace(self, content): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write(content) | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     def processingInstruction(self, target, data): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:22:43 +00:00
										 |  |  |         self._write('<?%s %s?>' % (target, data)) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  | class XMLFilterBase(xmlreader.XMLReader): | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     """This class is designed to sit between an XMLReader and the
 | 
					
						
							|  |  |  |     client application's event handlers.  By default, it does nothing | 
					
						
							|  |  |  |     but pass requests up to the reader and events on to the handlers | 
					
						
							|  |  |  |     unmodified, but subclasses can override specific methods to modify | 
					
						
							|  |  |  |     the event stream or the configuration requests as they pass | 
					
						
							|  |  |  |     through."""
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-11 22:35:00 +00:00
										 |  |  |     def __init__(self, parent = None): | 
					
						
							|  |  |  |         xmlreader.XMLReader.__init__(self) | 
					
						
							|  |  |  |         self._parent = parent | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     # ErrorHandler methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def error(self, exception): | 
					
						
							|  |  |  |         self._err_handler.error(exception) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def fatalError(self, exception): | 
					
						
							|  |  |  |         self._err_handler.fatalError(exception) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def warning(self, exception): | 
					
						
							|  |  |  |         self._err_handler.warning(exception) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # ContentHandler methods | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     def setDocumentLocator(self, locator): | 
					
						
							|  |  |  |         self._cont_handler.setDocumentLocator(locator) | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     def startDocument(self): | 
					
						
							|  |  |  |         self._cont_handler.startDocument() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def endDocument(self): | 
					
						
							|  |  |  |         self._cont_handler.endDocument() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def startPrefixMapping(self, prefix, uri): | 
					
						
							|  |  |  |         self._cont_handler.startPrefixMapping(prefix, uri) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def endPrefixMapping(self, prefix): | 
					
						
							|  |  |  |         self._cont_handler.endPrefixMapping(prefix) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def startElement(self, name, attrs): | 
					
						
							|  |  |  |         self._cont_handler.startElement(name, attrs) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  |     def endElement(self, name): | 
					
						
							|  |  |  |         self._cont_handler.endElement(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def startElementNS(self, name, qname, attrs): | 
					
						
							| 
									
										
										
										
											2004-05-06 02:04:21 +00:00
										 |  |  |         self._cont_handler.startElementNS(name, qname, attrs) | 
					
						
							| 
									
										
										
										
											2000-09-21 08:25:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def endElementNS(self, name, qname): | 
					
						
							|  |  |  |         self._cont_handler.endElementNS(name, qname) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def characters(self, content): | 
					
						
							|  |  |  |         self._cont_handler.characters(content) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-24 10:53:31 +00:00
										 |  |  |     def ignorableWhitespace(self, chars): | 
					
						
							|  |  |  |         self._cont_handler.ignorableWhitespace(chars) | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def processingInstruction(self, target, data): | 
					
						
							|  |  |  |         self._cont_handler.processingInstruction(target, data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def skippedEntity(self, name): | 
					
						
							|  |  |  |         self._cont_handler.skippedEntity(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # DTDHandler methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def notationDecl(self, name, publicId, systemId): | 
					
						
							|  |  |  |         self._dtd_handler.notationDecl(name, publicId, systemId) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def unparsedEntityDecl(self, name, publicId, systemId, ndata): | 
					
						
							|  |  |  |         self._dtd_handler.unparsedEntityDecl(name, publicId, systemId, ndata) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # EntityResolver methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def resolveEntity(self, publicId, systemId): | 
					
						
							|  |  |  |         self._ent_handler.resolveEntity(publicId, systemId) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # XMLReader methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def parse(self, source): | 
					
						
							|  |  |  |         self._parent.setContentHandler(self) | 
					
						
							|  |  |  |         self._parent.setErrorHandler(self) | 
					
						
							|  |  |  |         self._parent.setEntityResolver(self) | 
					
						
							|  |  |  |         self._parent.setDTDHandler(self) | 
					
						
							|  |  |  |         self._parent.parse(source) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setLocale(self, locale): | 
					
						
							|  |  |  |         self._parent.setLocale(locale) | 
					
						
							| 
									
										
										
										
											2000-09-18 17:40:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-29 19:34:54 +00:00
										 |  |  |     def getFeature(self, name): | 
					
						
							|  |  |  |         return self._parent.getFeature(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setFeature(self, name, state): | 
					
						
							|  |  |  |         self._parent.setFeature(name, state) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def getProperty(self, name): | 
					
						
							|  |  |  |         return self._parent.getProperty(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setProperty(self, name, value): | 
					
						
							|  |  |  |         self._parent.setProperty(name, value) | 
					
						
							| 
									
										
										
										
											2000-09-24 18:54:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-11 22:35:00 +00:00
										 |  |  |     # XMLFilter methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def getParent(self): | 
					
						
							|  |  |  |         return self._parent | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setParent(self, parent): | 
					
						
							|  |  |  |         self._parent = parent | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-24 18:54:49 +00:00
										 |  |  | # --- 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."""
 | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-24 21:31:06 +00:00
										 |  |  |     if type(source) in _StringTypes: | 
					
						
							|  |  |  |         source = xmlreader.InputSource(source) | 
					
						
							|  |  |  |     elif hasattr(source, "read"): | 
					
						
							|  |  |  |         f = source | 
					
						
							| 
									
										
										
										
											2000-10-06 21:11:20 +00:00
										 |  |  |         source = xmlreader.InputSource() | 
					
						
							| 
									
										
										
										
											2000-09-24 21:31:06 +00:00
										 |  |  |         source.setByteStream(f) | 
					
						
							| 
									
										
										
										
											2000-10-06 21:11:20 +00:00
										 |  |  |         if hasattr(f, "name"): | 
					
						
							| 
									
										
										
										
											2000-10-24 15:53:12 +00:00
										 |  |  |             source.setSystemId(f.name) | 
					
						
							| 
									
										
										
										
											2000-09-24 18:54:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-26 17:23:09 +00:00
										 |  |  |     if source.getByteStream() is None: | 
					
						
							| 
									
										
										
										
											2000-09-24 18:54:49 +00:00
										 |  |  |         sysid = source.getSystemId() | 
					
						
							| 
									
										
										
										
											2000-09-26 17:23:09 +00:00
										 |  |  |         if os.path.isfile(sysid): | 
					
						
							| 
									
										
										
										
											2000-09-24 18:54:49 +00:00
										 |  |  |             basehead = os.path.split(os.path.normpath(base))[0] | 
					
						
							|  |  |  |             source.setSystemId(os.path.join(basehead, sysid)) | 
					
						
							| 
									
										
										
										
											2000-09-26 17:23:09 +00:00
										 |  |  |             f = open(sysid, "rb") | 
					
						
							| 
									
										
										
										
											2000-09-24 18:54:49 +00:00
										 |  |  |         else: | 
					
						
							|  |  |  |             source.setSystemId(urlparse.urljoin(base, sysid)) | 
					
						
							| 
									
										
										
										
											2000-09-26 17:23:09 +00:00
										 |  |  |             f = urllib.urlopen(source.getSystemId()) | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-26 17:23:09 +00:00
										 |  |  |         source.setByteStream(f) | 
					
						
							| 
									
										
										
										
											2000-10-23 18:09:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-24 18:54:49 +00:00
										 |  |  |     return source |