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
Boxiang Sun
cython
Commits
59d09fd4
Commit
59d09fd4
authored
Apr 26, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweak templating in annotated code writer some more
parent
f2336b61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
37 deletions
+40
-37
Cython/Compiler/Annotate.py
Cython/Compiler/Annotate.py
+40
-37
No files found.
Cython/Compiler/Annotate.py
View file @
59d09fd4
...
...
@@ -3,6 +3,7 @@
import
os
import
re
import
codecs
import
textwrap
from
xml.sax.saxutils
import
escape
as
html_escape
from
StringIO
import
StringIO
...
...
@@ -62,28 +63,28 @@ class AnnotationCCodeWriter(CCodeWriter):
if (theDiv.style.display != 'block') theDiv.style.display = 'block';
else theDiv.style.display = 'none';
}
"""
"""
.
strip
()
_css_template
=
"""
body.cython { font-family: courier; font-size: 12; }
_css_template
=
textwrap
.
dedent
(
"""
body.cython { font-family: courier; font-size: 12; }
.cython.tag { }
.cython.line { margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin-left: 20px; }
.cython.tag { }
.cython.line { margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin-left: 20px; }
.cython.code .py_c_api { color: red; }
.cython.code .py_macro_api { color: #FF7000; }
.cython.code .pyx_c_api { color: #FF3000; }
.cython.code .pyx_macro_api { color: #FF7000; }
.cython.code .refnanny { color: #FFA000; }
.cython.code .error_goto { color: #FFA000; }
.cython.code .py_c_api { color: red; }
.cython.code .py_macro_api { color: #FF7000; }
.cython.code .pyx_c_api { color: #FF3000; }
.cython.code .pyx_macro_api { color: #FF7000; }
.cython.code .refnanny { color: #FFA000; }
.cython.code .error_goto { color: #FFA000; }
.cython.code .coerce { color: #008000; border: 1px dotted #008000 }
.cython.code .py_attr { color: #FF0000; font-weight: bold; }
.cython.code .c_attr { color: #0000FF; }
.cython.code .py_call { color: #FF0000; font-weight: bold; }
.cython.code .c_call { color: #0000FF; }
"""
.cython.code .coerce { color: #008000; border: 1px dotted #008000 }
.cython.code .py_attr { color: #FF0000; font-weight: bold; }
.cython.code .c_attr { color: #0000FF; }
.cython.code .py_call { color: #FF0000; font-weight: bold; }
.cython.code .c_call { color: #0000FF; }
"""
)
def
save_annotation
(
self
,
source_filename
,
target_filename
):
with
Utils
.
open_source_file
(
source_filename
)
as
f
:
...
...
@@ -92,25 +93,27 @@ body.cython { font-family: courier; font-size: 12; }
c_file
=
Utils
.
decode_filename
(
os
.
path
.
basename
(
target_filename
))
html_filename
=
os
.
path
.
splitext
(
target_filename
)[
0
]
+
".html"
with
codecs
.
open
(
html_filename
,
"w"
,
encoding
=
"UTF-8"
)
as
out_buffer
:
out_buffer
.
write
(
self
.
_save_annotation
(
lines
,
code_source_file
,
c_file
))
out_buffer
.
write
(
self
.
_save_annotation
(
lines
,
code_source_file
,
c_file
))
def
_save_annotation_header
(
self
,
c_file
):
outlist
=
[
u'''
<!DOCTYPE html>
<!-- Generated by Cython {watermark} -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
{css}
</style>
<script>
{js}
</script>
</head>
<body class="cython">
<p>Generated by Cython {watermark}</p>
\
n
'''
.
format
(
css
=
self
.
_css
(),
js
=
self
.
_js
,
watermark
=
Version
.
watermark
)]
outlist
=
[
textwrap
.
dedent
(
u'''
\
<!DOCTYPE html>
<!-- Generated by Cython {watermark} -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
{css}
</style>
<script>
{js}
</script>
</head>
<body class="cython">
<p>Generated by Cython {watermark}</p>
'''
).
format
(
css
=
self
.
_css
(),
js
=
self
.
_js
,
watermark
=
Version
.
watermark
)
]
if
c_file
:
outlist
.
append
(
u'<p>Raw output: <a href="%s">%s</a></p>
\
n
'
%
(
c_file
,
c_file
))
return
outlist
...
...
@@ -127,11 +130,11 @@ body.cython { font-family: courier; font-size: 12; }
"""
outlist
=
[]
outlist
.
extend
(
self
.
_save_annotation_header
(
c_file
))
outlist
.
extend
(
self
.
_save_annotation_body
(
lines
,
code_source_file
,
c_file
=
None
))
outlist
.
extend
(
self
.
_save_annotation_body
(
lines
,
code_source_file
))
outlist
.
extend
(
self
.
_save_annotation_footer
())
return
''
.
join
(
outlist
)
def
_save_annotation_body
(
self
,
lines
,
code_source_file
,
c_file
=
None
):
def
_save_annotation_body
(
self
,
lines
,
code_source_file
):
outlist
=
[]
pos_comment_marker
=
u'/*
\
N{HORIZONTAL ELLIPSIS}
*/
\
n
'
new_calls_map
=
dict
(
...
...
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