Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
d66375b2
Commit
d66375b2
authored
Jan 16, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace open(filepath).read() anti-pattern by code that safely and timely closes the file
parent
9cec5b0e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
33 deletions
+54
-33
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+8
-1
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+8
-1
Cython/Compiler/Tests/TestParseTreeTransforms.py
Cython/Compiler/Tests/TestParseTreeTransforms.py
+5
-3
Cython/Debugger/Cygdb.py
Cython/Debugger/Cygdb.py
+33
-28
No files found.
Cython/Build/Dependencies.py
View file @
d66375b2
...
@@ -91,7 +91,14 @@ def file_hash(filename):
...
@@ -91,7 +91,14 @@ def file_hash(filename):
path
=
os
.
path
.
normpath
(
filename
.
encode
(
"UTF-8"
))
path
=
os
.
path
.
normpath
(
filename
.
encode
(
"UTF-8"
))
m
=
hashlib
.
md5
(
str
(
len
(
path
))
+
":"
)
m
=
hashlib
.
md5
(
str
(
len
(
path
))
+
":"
)
m
.
update
(
path
)
m
.
update
(
path
)
m
.
update
(
open
(
filename
).
read
())
f
=
open
(
filename
,
'rb'
)
try
:
data
=
f
.
read
(
65000
)
while
data
:
m
.
update
(
data
)
data
=
f
.
read
(
65000
)
finally
:
f
.
close
()
return
m
.
hexdigest
()
return
m
.
hexdigest
()
def
parse_list
(
s
):
def
parse_list
(
s
):
...
...
Cython/Compiler/Main.py
View file @
d66375b2
...
@@ -309,7 +309,14 @@ class Context(object):
...
@@ -309,7 +309,14 @@ class Context(object):
position
=
e
.
args
[
2
]
position
=
e
.
args
[
2
]
encoding
=
e
.
args
[
0
]
encoding
=
e
.
args
[
0
]
for
idx
,
c
in
enumerate
(
open
(
source_filename
,
"rb"
).
read
()):
f
=
open
(
source_filename
,
"rb"
)
try
:
byte_data
=
f
.
read
()
finally
:
f
.
close
()
# FIXME: make this at least a little less inefficient
for
idx
,
c
in
enumerate
(
byte_data
):
if
c
in
(
ord
(
'
\
n
'
),
'
\
n
'
):
if
c
in
(
ord
(
'
\
n
'
),
'
\
n
'
):
line
+=
1
line
+=
1
column
=
0
column
=
0
...
...
Cython/Compiler/Tests/TestParseTreeTransforms.py
View file @
d66375b2
...
@@ -271,13 +271,15 @@ class TestDebugTransform(DebuggerTestCase):
...
@@ -271,13 +271,15 @@ class TestDebugTransform(DebuggerTestCase):
assert
'puts'
in
spam_stepinto
assert
'puts'
in
spam_stepinto
assert
'some_c_function'
in
spam_stepinto
assert
'some_c_function'
in
spam_stepinto
except
:
except
:
print
open
(
self
.
debug_dest
).
read
()
f
=
open
(
self
.
debug_dest
)
try
:
print
(
f
.
read
())
finally
:
f
.
close
()
raise
raise
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
import
unittest
import
unittest
unittest
.
main
()
unittest
.
main
()
Cython/Debugger/Cygdb.py
View file @
d66375b2
...
@@ -35,35 +35,40 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
...
@@ -35,35 +35,40 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
fd
,
tempfilename
=
tempfile
.
mkstemp
()
fd
,
tempfilename
=
tempfile
.
mkstemp
()
f
=
os
.
fdopen
(
fd
,
'w'
)
f
=
os
.
fdopen
(
fd
,
'w'
)
f
.
write
(
prefix_code
)
try
:
f
.
write
(
'set breakpoint pending on
\
n
'
)
f
.
write
(
prefix_code
)
f
.
write
(
"set print pretty on
\
n
"
)
f
.
write
(
'set breakpoint pending on
\
n
'
)
f
.
write
(
'python from Cython.Debugger import libcython, libpython
\
n
'
)
f
.
write
(
"set print pretty on
\
n
"
)
f
.
write
(
'python from Cython.Debugger import libcython, libpython
\
n
'
)
if
no_import
:
# don't do this, this overrides file command in .gdbinit
if
no_import
:
# f.write("file %s\n" % sys.executable)
# don't do this, this overrides file command in .gdbinit
pass
# f.write("file %s\n" % sys.executable)
else
:
pass
path
=
os
.
path
.
join
(
path_to_debug_info
,
"cython_debug"
,
"interpreter"
)
else
:
interpreter
=
open
(
path
).
read
()
path
=
os
.
path
.
join
(
path_to_debug_info
,
"cython_debug"
,
"interpreter"
)
f
.
write
(
"file %s
\
n
"
%
interpreter
)
interpreter_file
=
open
(
path
)
f
.
write
(
'
\
n
'
.
join
(
'cy import %s
\
n
'
%
fn
for
fn
in
debug_files
))
f
.
write
(
textwrap
.
dedent
(
'''
\
python
import sys
try
:
try
:
gdb.lookup_type('PyModuleObject')
interpreter
=
interpreter_file
.
read
()
except RuntimeError:
finally
:
sys.stderr.write(
interpreter_file
.
close
()
'Python was not compiled with debug symbols (or it was '
f
.
write
(
"file %s
\
n
"
%
interpreter
)
'stripped). Some functionality may not work (properly).
\
\
n')
f
.
write
(
'
\
n
'
.
join
(
'cy import %s
\
n
'
%
fn
for
fn
in
debug_files
))
end
f
.
write
(
textwrap
.
dedent
(
'''
\
python
source .cygdbinit
import sys
'''
))
try:
gdb.lookup_type('PyModuleObject')
f
.
close
()
except RuntimeError:
sys.stderr.write(
'Python was not compiled with debug symbols (or it was '
'stripped). Some functionality may not work (properly).
\
\
n')
end
source .cygdbinit
'''
))
finally
:
f
.
close
()
return
tempfilename
return
tempfilename
...
...
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