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
729ad5cf
Commit
729ad5cf
authored
Jun 09, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18038: SyntaxError raised during compilation sources with illegal
encoding now always contains an encoding name.
parent
c49805e9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
7 deletions
+28
-7
Lib/test/test_pep263.py
Lib/test/test_pep263.py
+18
-0
Misc/NEWS
Misc/NEWS
+3
-0
Parser/tokenizer.c
Parser/tokenizer.c
+7
-7
No files found.
Lib/test/test_pep263.py
View file @
729ad5cf
...
...
@@ -41,6 +41,24 @@ class PEP263Test(unittest.TestCase):
# two bytes in common with the UTF-8 BOM
self
.
assertRaises
(
SyntaxError
,
eval
,
'
\
xef
\
xbb
\
x20
'
)
def
test_error_message
(
self
):
compile
(
'# -*- coding: iso-8859-15 -*-
\
n
'
,
'dummy'
,
'exec'
)
compile
(
'
\
xef
\
xbb
\
xbf
\
n
'
,
'dummy'
,
'exec'
)
compile
(
'
\
xef
\
xbb
\
xbf
# -*- coding: utf-8 -*-
\
n
'
,
'dummy'
,
'exec'
)
with
self
.
assertRaisesRegexp
(
SyntaxError
,
'fake'
):
compile
(
'# -*- coding: fake -*-
\
n
'
,
'dummy'
,
'exec'
)
with
self
.
assertRaisesRegexp
(
SyntaxError
,
'iso-8859-15'
):
compile
(
'
\
xef
\
xbb
\
xbf
# -*- coding: iso-8859-15 -*-
\
n
'
,
'dummy'
,
'exec'
)
with
self
.
assertRaisesRegexp
(
SyntaxError
,
'BOM'
):
compile
(
'
\
xef
\
xbb
\
xbf
# -*- coding: iso-8859-15 -*-
\
n
'
,
'dummy'
,
'exec'
)
with
self
.
assertRaisesRegexp
(
SyntaxError
,
'fake'
):
compile
(
'
\
xef
\
xbb
\
xbf
# -*- coding: fake -*-
\
n
'
,
'dummy'
,
'exec'
)
with
self
.
assertRaisesRegexp
(
SyntaxError
,
'BOM'
):
compile
(
'
\
xef
\
xbb
\
xbf
# -*- coding: fake -*-
\
n
'
,
'dummy'
,
'exec'
)
def
test_main
():
test_support
.
run_unittest
(
PEP263Test
)
...
...
Misc/NEWS
View file @
729ad5cf
...
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.6?
Core and Builtins
-----------------
- Issue #18038: SyntaxError raised during compilation sources with illegal
encoding now always contains an encoding name.
- Issue #18019: Fix crash in the repr of dictionaries containing their own
views.
...
...
Parser/tokenizer.c
View file @
729ad5cf
...
...
@@ -277,8 +277,11 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,
tok
->
encoding
=
cs
;
tok
->
decoding_state
=
-
1
;
}
else
else
{
PyErr_Format
(
PyExc_SyntaxError
,
"encoding problem: %s"
,
cs
);
PyMem_FREE
(
cs
);
}
#else
/* Without Unicode support, we cannot
process the coding spec. Since there
...
...
@@ -289,15 +292,12 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,
}
}
else
{
/* then, compare cs with BOM */
r
=
(
strcmp
(
tok
->
encoding
,
cs
)
==
0
);
if
(
!
r
)
PyErr_Format
(
PyExc_SyntaxError
,
"encoding problem: %s with BOM"
,
cs
);
PyMem_FREE
(
cs
);
}
}
if
(
!
r
)
{
cs
=
tok
->
encoding
;
if
(
!
cs
)
cs
=
"with BOM"
;
PyErr_Format
(
PyExc_SyntaxError
,
"encoding problem: %s"
,
cs
);
}
return
r
;
}
...
...
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