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
54c510d7
Commit
54c510d7
authored
Aug 01, 2012
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix findnocoding.p and pysource.py scripts
I suppose that these scripts didn't work since Python 3.0.
parent
18109316
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
+14
-14
Tools/scripts/findnocoding.py
Tools/scripts/findnocoding.py
+11
-11
Tools/scripts/pysource.py
Tools/scripts/pysource.py
+3
-3
No files found.
Tools/scripts/findnocoding.py
View file @
54c510d7
...
@@ -32,7 +32,7 @@ except ImportError:
...
@@ -32,7 +32,7 @@ except ImportError:
"no sophisticated Python source file search will be done."
,
file
=
sys
.
stderr
)
"no sophisticated Python source file search will be done."
,
file
=
sys
.
stderr
)
decl_re
=
re
.
compile
(
r"coding[=:]\
s*([-
\w.]+)"
)
decl_re
=
re
.
compile
(
r
b
"coding[=:]\
s*([-
\w.]+)"
)
def
get_declaration
(
line
):
def
get_declaration
(
line
):
match
=
decl_re
.
search
(
line
)
match
=
decl_re
.
search
(
line
)
...
@@ -50,10 +50,11 @@ def has_correct_encoding(text, codec):
...
@@ -50,10 +50,11 @@ def has_correct_encoding(text, codec):
def
needs_declaration
(
fullpath
):
def
needs_declaration
(
fullpath
):
try
:
try
:
infile
=
open
(
fullpath
)
infile
=
open
(
fullpath
,
'rb'
)
except
IOError
:
# Oops, the file was removed - ignore it
except
IOError
:
# Oops, the file was removed - ignore it
return
None
return
None
with
infile
:
line1
=
infile
.
readline
()
line1
=
infile
.
readline
()
line2
=
infile
.
readline
()
line2
=
infile
.
readline
()
...
@@ -64,7 +65,6 @@ def needs_declaration(fullpath):
...
@@ -64,7 +65,6 @@ def needs_declaration(fullpath):
# check the whole file for non utf-8 characters
# check the whole file for non utf-8 characters
rest
=
infile
.
read
()
rest
=
infile
.
read
()
infile
.
close
()
if
has_correct_encoding
(
line1
+
line2
+
rest
,
"utf-8"
):
if
has_correct_encoding
(
line1
+
line2
+
rest
,
"utf-8"
):
return
False
return
False
...
...
Tools/scripts/pysource.py
View file @
54c510d7
...
@@ -22,7 +22,7 @@ __all__ = ["has_python_ext", "looks_like_python", "can_be_compiled", "walk_pytho
...
@@ -22,7 +22,7 @@ __all__ = ["has_python_ext", "looks_like_python", "can_be_compiled", "walk_pytho
import
os
,
re
import
os
,
re
binary_re
=
re
.
compile
(
'[
\
x00
-
\
x08
\
x0E
-
\
x1F
\
x7F
]'
)
binary_re
=
re
.
compile
(
br
'[\x00-\x08\x0E-\x1F\x7F]'
)
debug
=
False
debug
=
False
...
@@ -42,7 +42,7 @@ def _open(fullpath):
...
@@ -42,7 +42,7 @@ def _open(fullpath):
return
None
return
None
try
:
try
:
return
open
(
fullpath
)
return
open
(
fullpath
,
"rb"
)
except
IOError
as
err
:
# Access denied, or a special file - ignore it
except
IOError
as
err
:
# Access denied, or a special file - ignore it
print_debug
(
"%s: access denied: %s"
%
(
fullpath
,
err
))
print_debug
(
"%s: access denied: %s"
%
(
fullpath
,
err
))
return
None
return
None
...
@@ -65,7 +65,7 @@ def looks_like_python(fullpath):
...
@@ -65,7 +65,7 @@ def looks_like_python(fullpath):
if
fullpath
.
endswith
(
".py"
)
or
fullpath
.
endswith
(
".pyw"
):
if
fullpath
.
endswith
(
".py"
)
or
fullpath
.
endswith
(
".pyw"
):
return
True
return
True
elif
"python"
in
line
:
elif
b
"python"
in
line
:
# disguised Python script (e.g. CGI)
# disguised Python script (e.g. CGI)
return
True
return
True
...
...
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