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
9e8cd885
Commit
9e8cd885
authored
Apr 22, 2014
by
Matthias BUSSONNIER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use context manager to close file, and more explicit variable name
parent
80e769d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
Cython/Compiler/Annotate.py
Cython/Compiler/Annotate.py
+22
-19
No files found.
Cython/Compiler/Annotate.py
View file @
9e8cd885
...
...
@@ -10,6 +10,8 @@ import Version
from
Code
import
CCodeWriter
from
Cython
import
Utils
from
contextlib
import
closing
# need one-characters subsitutions (for now) so offsets aren't off
special_chars
=
[
(
u'&'
,
u'
\
xF2
'
,
u'&'
),
...
...
@@ -55,21 +57,21 @@ class AnnotationCCodeWriter(CCodeWriter):
self
.
annotations
.
append
((
pos
,
item
))
def
save_annotation
(
self
,
source_filename
,
target_filename
):
with
closing
(
Utils
.
open_source_file
(
source_filename
))
as
f
:
lines
=
f
.
readlines
()
html_filename
=
os
.
path
.
splitext
(
target_filename
)[
0
]
+
".html"
self
.
mark_pos
(
None
)
f
=
Utils
.
open_source_file
(
source_filename
)
lines
=
f
.
readlines
()
for
k
,
line
in
enumerate
(
lines
):
for
c
,
cc
,
html
in
special_chars
:
line
=
line
.
replace
(
c
,
cc
)
lines
[
k
]
=
line
f
.
close
()
html_filename
=
os
.
path
.
splitext
(
target_filename
)[
0
]
+
".html"
f
=
codecs
.
open
(
html_filename
,
"w"
,
encoding
=
"UTF-8"
)
f
.
write
(
u'<!DOCTYPE html>
\
n
'
)
f
.
write
(
u'<!-- Generated by Cython %s -->
\
n
'
%
Version
.
watermark
)
f
.
write
(
u'<html>
\
n
'
)
f
.
write
(
u"""
output_buffer
=
codecs
.
open
(
html_filename
,
"w"
,
encoding
=
"UTF-8"
)
output_buffer
.
write
(
u'<!DOCTYPE html>
\
n
'
)
output_buffer
.
write
(
u'<!-- Generated by Cython %s -->
\
n
'
%
Version
.
watermark
)
output_buffer
.
write
(
u'<html>
\
n
'
)
output_buffer
.
write
(
u"""
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
...
...
@@ -107,10 +109,10 @@ function toggleDiv(id) {
</script>
</head>
"""
)
f
.
write
(
u'<body>
\
n
'
)
f
.
write
(
u'<p>Generated by Cython %s
\
n
'
%
Version
.
watermark
)
output_buffer
.
write
(
u'<body>
\
n
'
)
output_buffer
.
write
(
u'<p>Generated by Cython %s
\
n
'
%
Version
.
watermark
)
c_file
=
Utils
.
decode_filename
(
os
.
path
.
basename
(
target_filename
))
f
.
write
(
u'<p>Raw output: <a href="%s">%s</a>
\
n
'
%
(
c_file
,
c_file
))
output_buffer
.
write
(
u'<p>Raw output: <a href="%s">%s</a>
\
n
'
%
(
c_file
,
c_file
))
zero_calls
=
dict
((
name
,
0
)
for
name
in
'refnanny py_macro_api py_c_api pyx_macro_api pyx_c_api error_goto'
.
split
())
...
...
@@ -124,6 +126,7 @@ function toggleDiv(id) {
pos_comment_marker
=
u'/*
\
N{HORIZONTAL ELLIPSIS}
*/
\
n
'
k
=
0
code_source_file
=
self
.
code
.
get
(
source_filename
,
{})
print
code_source_file
for
line
in
lines
:
k
+=
1
try
:
...
...
@@ -141,17 +144,17 @@ function toggleDiv(id) {
score
=
(
5
*
calls
[
'py_c_api'
]
+
2
*
calls
[
'pyx_c_api'
]
+
calls
[
'py_macro_api'
]
+
calls
[
'pyx_macro_api'
])
color
=
u"FFFF%02x"
%
int
(
255
/
(
1
+
score
/
10.0
))
f
.
write
(
u"<pre class='line' style='background-color: #%s' onclick='toggleDiv(
\
"
line%s
\
"
)'>"
%
(
color
,
k
))
output_buffer
.
write
(
u"<pre class='line' style='background-color: #%s' onclick='toggleDiv(
\
"
line%s
\
"
)'>"
%
(
color
,
k
))
f
.
write
(
u" %d: "
%
k
)
output_buffer
.
write
(
u" %d: "
%
k
)
for
c
,
cc
,
html
in
special_chars
:
line
=
line
.
replace
(
cc
,
html
)
f
.
write
(
line
.
rstrip
())
output_buffer
.
write
(
line
.
rstrip
())
f
.
write
(
u'</pre>
\
n
'
)
f
.
write
(
u"<pre id='line%s' class='code' style='background-color: #%s'>%s</pre>"
%
(
k
,
color
,
code
))
f
.
write
(
u'</body></html>
\
n
'
)
f
.
close
()
output_buffer
.
write
(
u'</pre>
\
n
'
)
output_buffer
.
write
(
u"<pre id='line%s' class='code' style='background-color: #%s'>%s</pre>"
%
(
k
,
color
,
code
))
output_buffer
.
write
(
u'</body></html>
\
n
'
)
output_buffer
.
close
()
_parse_code
=
re
.
compile
(
...
...
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