summaryrefslogtreecommitdiff
path: root/Lib/tokenize.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-06-28 10:23:11 -0400
committerJason R. Coombs <jaraco@jaraco.com>2015-06-28 10:23:11 -0400
commit80c29ac1ea1b3968a91d3328fab02084c59ca0e4 (patch)
tree65a80b757daf57eec3482317d235358735d86df9 /Lib/tokenize.py
parent101ff3541cbe5bd9549722dc53c28d6c21b9389c (diff)
parentd1d628d552128d73d8876d9af9d6f6ef0ec22857 (diff)
downloadcpython-git-80c29ac1ea1b3968a91d3328fab02084c59ca0e4.tar.gz
Issue #20387: Merge patch and test
Diffstat (limited to 'Lib/tokenize.py')
-rw-r--r--Lib/tokenize.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index cf18bf9f2d..4d93a83e29 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -244,6 +244,8 @@ class Untokenizer:
def untokenize(self, iterable):
it = iter(iterable)
+ indents = []
+ startline = False
for t in it:
if len(t) == 2:
self.compat(t, it)
@@ -254,6 +256,21 @@ class Untokenizer:
continue
if tok_type == ENDMARKER:
break
+ if tok_type == INDENT:
+ indents.append(token)
+ continue
+ elif tok_type == DEDENT:
+ indents.pop()
+ self.prev_row, self.prev_col = end
+ continue
+ elif tok_type in (NEWLINE, NL):
+ startline = True
+ elif startline and indents:
+ indent = indents[-1]
+ if start[1] >= len(indent):
+ self.tokens.append(indent)
+ self.prev_col = len(indent)
+ startline = False
self.add_whitespace(start)
self.tokens.append(token)
self.prev_row, self.prev_col = end