]> granicus.if.org Git - python/commitdiff
encode(): Handle Latin-1 input characters better.
authorFred Drake <fdrake@acm.org>
Sat, 21 Apr 2001 06:01:53 +0000 (06:01 +0000)
committerFred Drake <fdrake@acm.org>
Sat, 21 Apr 2001 06:01:53 +0000 (06:01 +0000)
Doc/tools/sgmlconv/esistools.py

index 893af762ad4474da2e020fe9a4974bf58dfd1aa3..7feeada8dc978642d32856b1b46cab9345bdfa5f 100644 (file)
@@ -35,15 +35,19 @@ def decode(s):
 
 
 _charmap = {}
-for c in map(chr, range(256)):
-    _charmap[c] = c
+for c in range(128):
+    _charmap[chr(c)] = chr(c)
+    _charmap[unichr(c + 128)] = chr(c + 128)
 _charmap["\n"] = r"\n"
 _charmap["\\"] = r"\\"
 del c
 
 _null_join = ''.join
 def encode(s):
-    return _null_join(map(_charmap.get, s))
+    try:
+        return _null_join(map(_charmap.get, s))
+    except TypeError:
+        raise Exception("could not encode %r: %r" % (s, map(_charmap.get, s)))
 
 
 class ESISReader(xml.sax.xmlreader.XMLReader):