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
ef9f1868
Commit
ef9f1868
authored
May 09, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix code annotation for unicode source
parent
cd9d08f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
33 deletions
+36
-33
Cython/Compiler/Annotate.py
Cython/Compiler/Annotate.py
+36
-33
No files found.
Cython/Compiler/Annotate.py
View file @
ef9f1868
...
...
@@ -3,15 +3,17 @@
import
os
import
re
import
time
import
codecs
from
StringIO
import
StringIO
import
Version
from
Code
import
CCodeWriter
from
Cython
import
Utils
# need one-characters subsitutions (for now) so offsets aren't off
special_chars
=
[(
'<'
,
'
\
xF0
'
,
'<'
),
(
'>'
,
'
\
xF1
'
,
'>'
),
(
'&'
,
'
\
xF2
'
,
'&'
)]
special_chars
=
[(
u'<'
,
u'
\
xF0
'
,
u
'<'
),
(
u'>'
,
u'
\
xF1
'
,
u
'>'
),
(
u'&'
,
u'
\
xF2
'
,
u
'&'
)]
class
AnnotationCCodeWriter
(
CCodeWriter
):
...
...
@@ -48,7 +50,7 @@ class AnnotationCCodeWriter(CCodeWriter):
def
save_annotation
(
self
,
filename
):
self
.
mark_pos
(
None
)
f
=
open
(
filename
)
f
=
Utils
.
open_source_file
(
filename
)
lines
=
f
.
readlines
()
for
k
in
range
(
len
(
lines
)):
line
=
lines
[
k
]
...
...
@@ -76,10 +78,11 @@ class AnnotationCCodeWriter(CCodeWriter):
line
=
lines
[
line_no
]
lines
[
line_no
]
=
line
[:
col
]
+
item
+
line
[
col
:]
f
=
open
(
"%s.html"
%
filename
,
"w
"
)
f
.
write
(
'<html>
\
n
'
)
f
.
write
(
"""
f
=
codecs
.
open
(
"%s.html"
%
filename
,
"w"
,
encoding
=
"UTF-8
"
)
f
.
write
(
u
'<html>
\
n
'
)
f
.
write
(
u
"""
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body { font-family: courier; font-size: 12; }
...
...
@@ -112,16 +115,16 @@ function toggleDiv(id) {
</script>
</head>
"""
)
f
.
write
(
'<body>
\
n
'
)
f
.
write
(
'<p>Generated by Cython %s on %s
\
n
'
%
(
Version
.
version
,
time
.
asctime
()))
c_file
=
os
.
path
.
basename
(
filename
)[:
-
3
]
+
'c'
f
.
write
(
'<p>Raw output: <a href="%s">%s</a>
\
n
'
%
(
c_file
,
c_file
))
f
.
write
(
u
'<body>
\
n
'
)
f
.
write
(
u
'<p>Generated by Cython %s on %s
\
n
'
%
(
Version
.
version
,
time
.
asctime
()))
c_file
=
Utils
.
encode_filename
(
os
.
path
.
basename
(
filename
)[:
-
3
]
+
'c'
)
f
.
write
(
u
'<p>Raw output: <a href="%s">%s</a>
\
n
'
%
(
c_file
,
c_file
))
k
=
0
py_c_api
=
re
.
compile
(
'(Py[A-Z][a-z]+_[A-Z][a-z][A-Za-z_]+)'
)
pyx_api
=
re
.
compile
(
'(__Pyx[A-Za-z_]+)
\
(
'
)
py_marco_api = re.compile('
(
Py
[
A
-
Za
-
z
]
*
_
[
A
-
Z
][
A
-
Z_
]
+
)
')
error_goto = re.compile(r'
((;
*
if
.
*
)
?
\
{
__pyx_filename
=
.
*
goto
__pyx_L
\
w
+
;
\
})
')
py_c_api
=
re
.
compile
(
u
'(Py[A-Z][a-z]+_[A-Z][a-z][A-Za-z_]+)'
)
pyx_api
=
re
.
compile
(
u
'(__Pyx[A-Za-z_]+)
\
(
'
)
py_marco_api = re.compile(
u
'
(
Py
[
A
-
Za
-
z
]
*
_
[
A
-
Z
][
A
-
Z_
]
+
)
')
error_goto = re.compile(
u
r'
((;
*
if
.
*
)
?
\
{
__pyx_filename
=
.
*
goto
__pyx_L
\
w
+
;
\
})
')
for line in lines:
...
...
@@ -131,33 +134,33 @@ function toggleDiv(id) {
except KeyError:
code = ''
code, c_api_calls = py_c_api.subn(r"<span class='
py_api
'>
\
1
</span>", code)
code, pyx_api_calls = pyx_api.subn(r"<span class='
pyx_api
'>
\
1
</span>(", code)
code, macro_api_calls = py_marco_api.subn(r"<span class='
py_macro_api
'>
\
1
</span>", code)
code, error_goto_calls = error_goto.subn(r"<span class='
error_goto
'>
\
1
</span>", code)
code, c_api_calls = py_c_api.subn(
u
r"<span class='
py_api
'>
\
1
</span>", code)
code, pyx_api_calls = pyx_api.subn(
u
r"<span class='
pyx_api
'>
\
1
</span>(", code)
code, macro_api_calls = py_marco_api.subn(
u
r"<span class='
py_macro_api
'>
\
1
</span>", code)
code, error_goto_calls = error_goto.subn(
u
r"<span class='
error_goto
'>
\
1
</span>", code)
code = code.replace(
"<span class='
error_goto
'>;",
";<span class='
error_goto
'>")
code = code.replace(
u"<span class='
error_goto
'>;", u
";<span class='
error_goto
'>")
color = "FFFF%02x" % int(255/(1+(5*c_api_calls+2*pyx_api_calls+macro_api_calls)/10.0))
f.write("<pre class='
line
' style='
background
-
color
:
#%s' onclick='toggleDiv(\"line%s\")'>" % (color, k))
color =
u
"FFFF%02x" % int(255/(1+(5*c_api_calls+2*pyx_api_calls+macro_api_calls)/10.0))
f.write(
u
"<pre class='
line
' style='
background
-
color
:
#%s' onclick='toggleDiv(\"line%s\")'>" % (color, k))
f
.
write
(
" %d: "
%
k
)
f
.
write
(
u
" %d: "
%
k
)
for
c
,
cc
,
html
in
special_chars
:
line
=
str
(
line
)
.
replace
(
cc
,
html
)
line
=
line
.
replace
(
cc
,
html
)
f
.
write
(
line
.
rstrip
())
f
.
write
(
'</pre>
\
n
'
)
f
.
write
(
"<pre id='line%s' class='code' style='background-color: #%s'>%s</pre>"
%
(
k
,
color
,
code
))
f
.
write
(
'</body></html>
\
n
'
)
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
()
# TODO: make this cleaner
def
escape
(
raw_string
):
raw_string
=
raw_string
.
replace
(
"
\
'
"
,
r"’"
)
raw_string
=
raw_string
.
replace
(
'
\
"
'
,
r'"'
)
raw_string
=
raw_string
.
replace
(
'
\
n
'
,
r'<br>\n'
)
raw_string
=
raw_string
.
replace
(
'
\
t
'
,
r'\t'
)
raw_string
=
raw_string
.
replace
(
u"
\
'
"
,
u
r"’"
)
raw_string
=
raw_string
.
replace
(
u'
\
"
'
,
u
r'"'
)
raw_string
=
raw_string
.
replace
(
u'
\
n
'
,
u
r'<br>\n'
)
raw_string
=
raw_string
.
replace
(
u'
\
t
'
,
u
r'\t'
)
return
raw_string
...
...
@@ -170,7 +173,7 @@ class AnnotationItem:
self
.
size
=
size
def
start
(
self
):
return
"<span class='tag %s' title='%s'>%s"
%
(
self
.
style
,
self
.
text
,
self
.
tag
)
return
u
"<span class='tag %s' title='%s'>%s"
%
(
self
.
style
,
self
.
text
,
self
.
tag
)
def
end
(
self
):
return
self
.
size
,
"</span>"
return
self
.
size
,
u
"</span>"
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