diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2014-02-24 04:33:08 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2014-02-24 04:33:08 (GMT) |
commit | 9dc3a36c849c15c227a8af218cfb215abe7b3c48 (patch) | |
tree | 596fc7e9ff8839ade21aa372182affe4defb8f85 /Lib/tokenize.py | |
parent | 938ba685dc9bbd34a598465eabbbee849b00d803 (diff) | |
download | cpython-9dc3a36c849c15c227a8af218cfb215abe7b3c48.zip cpython-9dc3a36c849c15c227a8af218cfb215abe7b3c48.tar.gz cpython-9dc3a36c849c15c227a8af218cfb215abe7b3c48.tar.bz2 |
Issue #9974: When untokenizing, use row info to insert backslash+newline.
Original patches by A. Kuchling and G. Rees (#12691).
Diffstat (limited to 'Lib/tokenize.py')
-rw-r--r-- | Lib/tokenize.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py index 7356a88..9bbb512 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -234,6 +234,10 @@ class Untokenizer: if row < self.prev_row or row == self.prev_row and col < self.prev_col: raise ValueError("start ({},{}) precedes previous end ({},{})" .format(row, col, self.prev_row, self.prev_col)) + row_offset = row - self.prev_row + if row_offset: + self.tokens.append("\\\n" * row_offset) + self.prev_col = 0 col_offset = col - self.prev_col if col_offset: self.tokens.append(" " * col_offset) @@ -248,6 +252,8 @@ class Untokenizer: if tok_type == ENCODING: self.encoding = token continue + if tok_type == ENDMARKER: + break self.add_whitespace(start) self.tokens.append(token) self.prev_row, self.prev_col = end |