--- saxutils.py.old 2006-04-14 23:37:48.040744000 +0400 +++ saxutils.py 2006-04-14 23:44:18.301912000 +0400 @@ -6,6 +6,7 @@ import os, urlparse, urllib, types import handler import xmlreader +from codecs import getwriter try: _StringTypes = [types.StringType, types.UnicodeType] @@ -86,17 +87,14 @@ import sys out = sys.stdout handler.ContentHandler.__init__(self) - self._out = out + self._out = getwriter(encoding)(out, _error_handling) self._ns_contexts = [{}] # contains uri -> prefix dicts self._current_context = self._ns_contexts[-1] self._undeclared_ns_maps = [] self._encoding = encoding def _write(self, text): - if isinstance(text, str): - self._out.write(text) - else: - self._out.write(text.encode(self._encoding, _error_handling)) + self._out.write(unicode(text)) # ContentHandler methods @@ -104,6 +102,9 @@ self._write('\n' % self._encoding) + def endDocument(self): + self._out.reset() + def startPrefixMapping(self, prefix, uri): self._ns_contexts.append(self._current_context.copy()) self._current_context[uri] = prefix