summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-03 15:30:51 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-03 15:30:51 (GMT)
commit7d24b1698a5590df066f829fb4eeef93186d7150 (patch)
treec216580e6d3aa39581bfd7cf20b5b9d029bf4825 /Lib
parentd7bae5e85ac9ae3a6fbd5c9de5b21be0df7a848d (diff)
downloadcpython-7d24b1698a5590df066f829fb4eeef93186d7150.zip
cpython-7d24b1698a5590df066f829fb4eeef93186d7150.tar.gz
cpython-7d24b1698a5590df066f829fb4eeef93186d7150.tar.bz2
#16152: fix tokenize to ignore whitespace at the end of the code when no newline is found. Patch by Ned Batchelder.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_tokenize.py4
-rw-r--r--Lib/tokenize.py4
2 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index a51e781..489f68f 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -550,6 +550,10 @@ Evil tabs
NAME 'pass' (3, 9) (3, 13)
DEDENT '' (4, 0) (4, 0)
DEDENT '' (4, 0) (4, 0)
+
+Pathological whitespace (http://bugs.python.org/issue16152)
+ >>> dump_tokens("@ ")
+ OP '@' (1, 0) (1, 1)
"""
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 1cba6e5..ca7b074 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -95,7 +95,7 @@ ContStr = group(r"[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
group("'", r'\\\r?\n'),
r'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' +
group('"', r'\\\r?\n'))
-PseudoExtras = group(r'\\\r?\n', Comment, Triple)
+PseudoExtras = group(r'\\\r?\n|\Z', Comment, Triple)
PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name)
tokenprog, pseudoprog, single3prog, double3prog = map(
@@ -362,6 +362,8 @@ def generate_tokens(readline):
if pseudomatch: # scan for tokens
start, end = pseudomatch.span(1)
spos, epos, pos = (lnum, start), (lnum, end), end
+ if start == end:
+ continue
token, initial = line[start:end], line[start]
if initial in numchars or \