berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

non-printable chars #6

Closed anazarkin1 closed 10 years ago

anazarkin1 commented 10 years ago

Hi guys!

Found an issue with astor when working with non printable chars in string. For example code below yields an error:

old_source="""
def write(self, param):
    if param=='\n':
        return;
"""
tree = ast.parse(old_source)
new_source = to_source(tree)
print(new_source)

Error: if param==' ^ SyntaxError: EOL while scanning string literal.

And thanks for astor, it's really useful!

berkerpeksag commented 10 years ago

Thanks for the report!

theanalyst commented 10 years ago

Hi, the above example fails because ast.parse() is failing. However trying to intepret oldsource as a raw string oldsource=r'def write.. or escaping the \ seems working

ztane commented 10 years ago

Yeah, this is not a bug, but user error :D.