def __init__(self, preserve, translate, other):
"""
Arguments::
preserve: a string of characters to preserve
translate: a dict or key/value list of characters to translate
other: the character to return for all characters not in
preserve or translate
"""
self.table = dict(
(k if isinstance(k, int) else ord(k), v)
for k,v in six.iteritems(dict(translate)) )
for c in preserve:
_c = ord(c)
if _c in self.table and self.table[_c] != c:
raise RuntimeError("Duplicate character '%s' appears in both "
"translate table and preserve list" % (c,))
self.table[_c] = c
self.other = other
评论列表
文章目录