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
88079f47
Commit
88079f47
authored
Jul 15, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the encoding specification when reading the source file.
parent
827bfd07
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
Lib/py_compile.py
Lib/py_compile.py
+18
-1
No files found.
Lib/py_compile.py
View file @
88079f47
...
...
@@ -7,6 +7,7 @@ import __builtin__
import
imp
import
marshal
import
os
import
re
import
sys
import
traceback
...
...
@@ -77,6 +78,21 @@ def wr_long(f, x):
(
x
>>
16
)
&
0xff
,
(
x
>>
24
)
&
0xff
]))
def
read_encoding
(
file
,
default
):
"""Read the first two lines of the file looking for coding: xyzzy."""
f
=
open
(
file
,
"rb"
)
try
:
for
i
in
range
(
2
):
line
=
f
.
readline
()
if
not
line
:
break
m
=
re
.
match
(
r".*\bcoding:\
s*(
\S+)\b"
,
line
)
if
m
:
return
str
(
m
.
group
(
1
))
return
default
finally
:
f
.
close
()
def
compile
(
file
,
cfile
=
None
,
dfile
=
None
,
doraise
=
False
):
"""Byte-compile one Python source file to Python bytecode.
...
...
@@ -112,7 +128,8 @@ def compile(file, cfile=None, dfile=None, doraise=False):
directories).
"""
f
=
open
(
file
,
'U'
)
encoding
=
read_encoding
(
file
,
"utf-8"
)
f
=
open
(
file
,
'U'
,
encoding
=
encoding
)
try
:
timestamp
=
int
(
os
.
fstat
(
f
.
fileno
()).
st_mtime
)
except
AttributeError
:
...
...
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