diff options
author | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2004-07-24 14:13:38 +0000 |
---|---|---|
committer | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2004-07-24 14:13:38 +0000 |
commit | 1941d0dc7b6120c34640c8d6e089a1eca21a434b (patch) | |
tree | f54599bc6d87750fa560384e2d319aa48bdcc161 /docutils/io.py | |
parent | f7873d1a0c07f4a1ce311a93e4e011dc8c6a3111 (diff) | |
download | docutils-1941d0dc7b6120c34640c8d6e089a1eca21a434b.tar.gz |
xmlcharrefreplace backport
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2446 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/io.py')
-rw-r--r-- | docutils/io.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/docutils/io.py b/docutils/io.py index 09119cef5..ad825bb12 100644 --- a/docutils/io.py +++ b/docutils/io.py @@ -9,6 +9,8 @@ I/O classes provide a uniform API for low-level input and output. Subclasses will exist for a variety of input/output mechanisms. """ +from __future__ import nested_scopes + __docformat__ = 'reStructuredText' import sys @@ -127,6 +129,16 @@ class Output(TransformSpec): def encode(self, data): if self.encoding and self.encoding.lower() == 'unicode': return data + elif (self.error_handler == 'xmlcharrefreplace' and + sys.hexversion < 0x02030000): + # We are using xmlcharrefreplace on a Python version which + # doesn't support it. + def enc(x): + try: + return x.encode(self.encoding, 'strict') + except UnicodeError: + return '&#%s;' % str(ord(x)) + return ''.join(map(enc, data)) else: return data.encode(self.encoding, self.error_handler) |