Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e99b97e

Browse files
committed
encode(): Handle Latin-1 input characters better.
1 parent bda0556 commit e99b97e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Doc/tools/sgmlconv/esistools.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@ def decode(s):
3535

3636

3737
_charmap = {}
38-
for c in map(chr, range(256)):
39-
_charmap[c] = c
38+
for c in range(128):
39+
_charmap[chr(c)] = chr(c)
40+
_charmap[unichr(c + 128)] = chr(c + 128)
4041
_charmap["\n"] = r"\n"
4142
_charmap["\\"] = r"\\"
4243
del c
4344

4445
_null_join = ''.join
4546
def encode(s):
46-
return _null_join(map(_charmap.get, s))
47+
try:
48+
return _null_join(map(_charmap.get, s))
49+
except TypeError:
50+
raise Exception("could not encode %r: %r" % (s, map(_charmap.get, s)))
4751

4852

4953
class ESISReader(xml.sax.xmlreader.XMLReader):

0 commit comments

Comments
 (0)