#! /home/phd/.local/bin/python3 # https://stackoverflow.com/a/518232/7976758 import sys import unicodedata from m_lib.defenc import default_encoding def strip_accents(s): return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn') def latin1_to_ascii(uinput): if isinstance(uinput, bytes): uinput = uinput.decode(sys.getfilesystemencoding()) return strip_accents(uinput) if __name__ == '__main__': if len(sys.argv) == 1: sys.exit('Usage: %s name\n' % sys.argv[0]) for name in sys.argv[1:]: sys.stdout.buffer.write( latin1_to_ascii(name).encode(default_encoding, 'surrogateescape') + b'\n' )