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
4b003074
Commit
4b003074
authored
Mar 16, 2010
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6716/2: Backslash-replace error output in compilall.
parent
09c86afb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
2 deletions
+31
-2
Lib/compileall.py
Lib/compileall.py
+4
-1
Lib/test/test_compileall.py
Lib/test/test_compileall.py
+25
-1
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/compileall.py
View file @
4b003074
...
...
@@ -104,7 +104,10 @@ def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0):
print
(
'*** Error compiling'
,
fullname
,
'...'
)
else
:
print
(
'*** '
,
end
=
''
)
print
(
err
.
msg
)
# escape non-printable characters in msg
msg
=
err
.
msg
.
encode
(
sys
.
stdout
.
encoding
,
errors
=
'backslashreplace'
)
msg
=
msg
.
decode
(
sys
.
stdout
.
encoding
)
print
(
msg
)
success
=
0
except
(
SyntaxError
,
UnicodeError
,
IOError
)
as
e
:
if
quiet
:
...
...
Lib/test/test_compileall.py
View file @
4b003074
import
sys
import
compileall
import
imp
import
os
...
...
@@ -7,6 +8,7 @@ import struct
import
tempfile
from
test
import
support
import
unittest
import
io
class
CompileallTests
(
unittest
.
TestCase
):
...
...
@@ -72,8 +74,30 @@ class CompileallTests(unittest.TestCase):
os
.
unlink
(
self
.
bc_path
)
os
.
unlink
(
self
.
bc_path2
)
class
EncodingTest
(
unittest
.
TestCase
):
'Issue 6716: compileall should escape source code when printing errors to stdout.'
def
setUp
(
self
):
self
.
directory
=
tempfile
.
mkdtemp
()
self
.
source_path
=
os
.
path
.
join
(
self
.
directory
,
'_test.py'
)
with
open
(
self
.
source_path
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
file
.
write
(
'# -*- coding: utf-8 -*-
\
n
'
)
file
.
write
(
'print u"
\
u20ac
"
\
n
'
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
directory
)
def
test_error
(
self
):
try
:
orig_stdout
=
sys
.
stdout
sys
.
stdout
=
io
.
TextIOWrapper
(
io
.
BytesIO
(),
encoding
=
'ascii'
)
compileall
.
compile_dir
(
self
.
directory
)
finally
:
sys
.
stdout
=
orig_stdout
def
test_main
():
support
.
run_unittest
(
CompileallTests
)
support
.
run_unittest
(
CompileallTests
,
EncodingTest
)
if
__name__
==
"__main__"
:
...
...
Misc/NEWS
View file @
4b003074
...
...
@@ -283,6 +283,8 @@ C-API
Library
-------
- Issue #6716/2: Backslash-replace error output in compilall.
- Issue #4961: Inconsistent/wrong result of askyesno function in tkMessageBox
with Tcl/Tk-8.5.
...
...
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