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
Gwenaël Samain
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
Show 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):
path
=
os
.
path
.
normpath
(
filename
.
encode
(
"UTF-8"
))
m
=
hashlib
.
md5
(
str
(
len
(
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
()
def
parse_list
(
s
):
...
...
Cython/Compiler/Main.py
View file @
d66375b2
...
...
@@ -309,7 +309,14 @@ class Context(object):
position
=
e
.
args
[
2
]
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
'
):
line
+=
1
column
=
0
...
...
Cython/Compiler/Tests/TestParseTreeTransforms.py
View file @
d66375b2
...
...
@@ -271,13 +271,15 @@ class TestDebugTransform(DebuggerTestCase):
assert
'puts'
in
spam_stepinto
assert
'some_c_function'
in
spam_stepinto
except
:
print
open
(
self
.
debug_dest
).
read
()
f
=
open
(
self
.
debug_dest
)
try
:
print
(
f
.
read
())
finally
:
f
.
close
()
raise
if
__name__
==
"__main__"
:
import
unittest
unittest
.
main
()
Cython/Debugger/Cygdb.py
View file @
d66375b2
...
...
@@ -35,6 +35,7 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
fd
,
tempfilename
=
tempfile
.
mkstemp
()
f
=
os
.
fdopen
(
fd
,
'w'
)
try
:
f
.
write
(
prefix_code
)
f
.
write
(
'set breakpoint pending on
\
n
'
)
f
.
write
(
"set print pretty on
\
n
"
)
...
...
@@ -46,7 +47,11 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
pass
else
:
path
=
os
.
path
.
join
(
path_to_debug_info
,
"cython_debug"
,
"interpreter"
)
interpreter
=
open
(
path
).
read
()
interpreter_file
=
open
(
path
)
try
:
interpreter
=
interpreter_file
.
read
()
finally
:
interpreter_file
.
close
()
f
.
write
(
"file %s
\
n
"
%
interpreter
)
f
.
write
(
'
\
n
'
.
join
(
'cy import %s
\
n
'
%
fn
for
fn
in
debug_files
))
f
.
write
(
textwrap
.
dedent
(
'''
\
...
...
@@ -62,7 +67,7 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
source .cygdbinit
'''
))
finally
:
f
.
close
()
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