import pprint, re

class Printer(pprint.PrettyPrinter):
    re_numeric = re.compile(r"\\(t|n|x[0-9A-Fa-f][0-9A-Fa-f])")
    def __repr(self, object, context, level):
        re_numeric.sub(pprint.PrettyPrinter.__repr(
            object, context, self.__depth, level), self.__replace)
    def __replace(self, match):
        s = match.group()
        if s[1] == "x":
            return r"\%03o" % int(s[2:], 16)
        elif s[1] == "t":
            return r"\011"
        elif s[1] == "n":
            return r"\012"
        raise RuntimeError, "should not reach here"

if __name__ == "__main__":
    pprint.PrettyPrinter = Printer
    pprint.pformat(["n\n\012\0x0a\xa4\xa2"]) == "['n\012\012\012\244\242']"