def _my_unctrl(c, u=_make_unctrl_map()): if c in u: return u[c] else: if unicodedata.category(c).startswith('C'): return b'\u%04x' % ord(c) else: return c