# $Id: quote_pri.py,v 1.5 2001/04/30 13:16:38 kjetilja Exp $


def mkchar(matchobj):
    import string
    seq = matchobj.group(0)
    try:
        # Try to convert octet
        val = chr(string.atoi(seq[1:], 16))
    except:
        # Bad sequence, return sequence
        val = seq
    return val


def decode(text):
    import re, string
    # Convert octets and remove soft linebreaks
    return string.replace(re.sub('=..', mkchar, text), '=\n', '')


def _test():
    import sys
    f = open(sys.argv[1]).read()
    print decode(f)


if __name__ == "__main__":
    _test()
