Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
33856de8
Commit
33856de8
authored
Aug 30, 2010
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle names starting with non-ascii characters correctly #9712
parent
e01de8f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
+25
-5
Lib/test/test_tokenize.py
Lib/test/test_tokenize.py
+13
-0
Lib/tokenize.py
Lib/tokenize.py
+10
-5
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_tokenize.py
View file @
33856de8
...
...
@@ -531,6 +531,7 @@ pass the '-ucompiler' option to process the full directory.
True
Evil tabs
>>> dump_tokens("def f():
\
\
n
\
\
tif x
\
\
n
\
\
tpass")
ENCODING 'utf-8' (0, 0) (0, 0)
NAME 'def' (1, 0) (1, 3)
...
...
@@ -547,6 +548,18 @@ Evil tabs
NAME 'pass' (3, 9) (3, 13)
DEDENT '' (4, 0) (4, 0)
DEDENT '' (4, 0) (4, 0)
Non-ascii identifiers
>>> dump_tokens("Örter = 'places'
\
\
ngrün = 'green'")
ENCODING 'utf-8' (0, 0) (0, 0)
NAME 'Örter' (1, 0) (1, 5)
OP '=' (1, 6) (1, 7)
STRING "'places'" (1, 8) (1, 16)
NEWLINE '
\
\
n' (1, 16) (1, 17)
NAME 'grün' (2, 0) (2, 4)
OP '=' (2, 5) (2, 6)
STRING "'green'" (2, 7) (2, 14)
"""
from
test
import
support
...
...
Lib/tokenize.py
View file @
33856de8
...
...
@@ -92,7 +92,7 @@ def maybe(*choices): return group(*choices) + '?'
Whitespace
=
r'[ \f\t]*'
Comment
=
r'#[^\r\n]*'
Ignore
=
Whitespace
+
any
(
r'\\\r?\n'
+
Whitespace
)
+
maybe
(
Comment
)
Name
=
r'
[a-zA-Z_]\
w*
'
Name
=
r'
\
w+
'
Hexnumber = r'
0
[
xX
][
0
-
9
a
-
fA
-
F
]
+
'
Binnumber = r'
0
[
bB
][
01
]
+
'
...
...
@@ -142,9 +142,12 @@ ContStr = group(r"[bB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
PseudoExtras
=
group
(
r'\\\r?\n'
,
Comment
,
Triple
)
PseudoToken
=
Whitespace
+
group
(
PseudoExtras
,
Number
,
Funny
,
ContStr
,
Name
)
def
_compile
(
expr
):
return
re
.
compile
(
expr
,
re
.
UNICODE
)
tokenprog
,
pseudoprog
,
single3prog
,
double3prog
=
map
(
re
.
compile
,
(
Token
,
PseudoToken
,
Single3
,
Double3
))
endprogs
=
{
"'"
:
re
.
compile
(
Single
),
'"'
:
re
.
compile
(
Double
),
_
compile
,
(
Token
,
PseudoToken
,
Single3
,
Double3
))
endprogs
=
{
"'"
:
_compile
(
Single
),
'"'
:
_
compile
(
Double
),
"'''"
:
single3prog
,
'"""'
:
double3prog
,
"r'''"
:
single3prog
,
'r"""'
:
double3prog
,
"b'''"
:
single3prog
,
'b"""'
:
double3prog
,
...
...
@@ -171,6 +174,8 @@ for t in ("'", '"',
"bR'"
,
'bR"'
,
"BR'"
,
'BR"'
):
single_quoted
[
t
]
=
t
del
_compile
tabsize
=
8
class
TokenError
(
Exception
):
pass
...
...
@@ -393,7 +398,7 @@ def tokenize(readline):
def
_tokenize
(
readline
,
encoding
):
lnum
=
parenlev
=
continued
=
0
n
amechars
,
numchars
=
string
.
ascii_letters
+
'_'
,
'0123456789'
n
umchars
=
'0123456789'
contstr
,
needcont
=
''
,
0
contline
=
None
indents
=
[
0
]
...
...
@@ -520,7 +525,7 @@ def _tokenize(readline, encoding):
break
else
:
# ordinary string
yield
TokenInfo
(
STRING
,
token
,
spos
,
epos
,
line
)
elif
initial
in
namechars
:
# ordinary name
elif
initial
.
isidentifier
():
# ordinary name
yield
TokenInfo
(
NAME
,
token
,
spos
,
epos
,
line
)
elif
initial
==
'
\
\
'
:
# continued stmt
continued
=
1
...
...
Misc/NEWS
View file @
33856de8
...
...
@@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 2?
Core and Builtins
-----------------
- Issue #9712: Fix tokenize on identifiers that start with non-ascii names.
- Issue #9688: __basicsize__ and __itemsize__ must be accessed as Py_ssize_t.
- Issue #9684: Added a definition for SIZEOF_WCHAR_T to PC/pyconfig.h,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment