I want to convert a string literal like r"r'\nasdf'" to a string ('\\nasdf' in this case).

Another case: r"'\nasdf'" to '\nasdf'.
I hope you get it.

This is important, because I have a parser of python scripts, that wants to know the exact contents of a string literal.

Is eval a clever solution? The string literals are filtered before (with tokenize) and should not cause security liabilities. Aren't there any nobler solutions than evaluating a literal? A parser library maybe?