Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-mako
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-mako
Commits
04a09d48
Commit
04a09d48
authored
16 years ago
by
Philip Jenvey
Browse files
Options
Downloads
Patches
Plain Diff
fix the html_error_template not handling tracebacks from normal .py files with
a magic encoding comment
parent
4559801f
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGES
+4
-0
4 additions, 0 deletions
CHANGES
lib/mako/exceptions.py
+9
-1
9 additions, 1 deletion
lib/mako/exceptions.py
lib/mako/util.py
+51
-1
51 additions, 1 deletion
lib/mako/util.py
test/exceptions_.py
+9
-0
9 additions, 0 deletions
test/exceptions_.py
with
73 additions
and
2 deletions
CHANGES
+
4
−
0
View file @
04a09d48
0.2.3
- fixed the html_error_template not handling tracebacks from
normal .py files with a magic encoding comment [ticket:88]
0.2.2
- cached blocks now use the current context when rendering
an expired section, instead of the original context
...
...
This diff is collapsed.
Click to expand it.
lib/mako/exceptions.py
+
9
−
1
View file @
04a09d48
...
...
@@ -7,6 +7,7 @@
"""
exception classes
"""
import
traceback
,
sys
,
re
from
mako
import
util
class
MakoException
(
Exception
):
pass
...
...
@@ -139,7 +140,14 @@ class RichTraceback(object):
break
else
:
try
:
self
.
source
=
file
(
new_trcback
[
-
1
][
0
]).
read
()
# A normal .py file (not a Template)
fp
=
open
(
new_trcback
[
-
1
][
0
])
encoding
=
util
.
parse_encoding
(
fp
)
fp
.
seek
(
0
)
self
.
source
=
fp
.
read
()
fp
.
close
()
if
encoding
:
self
.
source
=
self
.
source
.
decode
(
encoding
)
except
IOError
:
self
.
source
=
''
self
.
lineno
=
new_trcback
[
-
1
][
1
]
...
...
This diff is collapsed.
Click to expand it.
lib/mako/util.py
+
51
−
1
View file @
04a09d48
...
...
@@ -16,7 +16,7 @@ try:
except
:
from
StringIO
import
StringIO
import
weakref
,
os
,
time
import
codecs
,
re
,
weakref
,
os
,
time
try
:
import
threading
...
...
@@ -130,6 +130,56 @@ class LRUCache(dict):
# on us. loop around and try again
break
# Regexp to match python magic encoding line
_PYTHON_MAGIC_COMMENT_re
=
re
.
compile
(
r
'
[ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)
'
,
re
.
VERBOSE
)
def
parse_encoding
(
fp
):
"""
Deduce the encoding of a source file from magic comment.
It does this in the same way as the `Python interpreter`__
.. __: http://docs.python.org/ref/encodings.html
The ``fp`` argument should be a seekable file object.
"""
pos
=
fp
.
tell
()
fp
.
seek
(
0
)
try
:
line1
=
fp
.
readline
()
has_bom
=
line1
.
startswith
(
codecs
.
BOM_UTF8
)
if
has_bom
:
line1
=
line1
[
len
(
codecs
.
BOM_UTF8
):]
m
=
_PYTHON_MAGIC_COMMENT_re
.
match
(
line1
)
if
not
m
:
try
:
import
parser
parser
.
suite
(
line1
)
except
(
ImportError
,
SyntaxError
):
# Either it's a real syntax error, in which case the source
# is not valid python source, or line2 is a continuation of
# line1, in which case we don't want to scan line2 for a magic
# comment.
pass
else
:
line2
=
fp
.
readline
()
m
=
_PYTHON_MAGIC_COMMENT_re
.
match
(
line2
)
if
has_bom
:
if
m
:
raise
SyntaxError
,
\
"
python refuses to compile code with both a UTF8
"
\
"
byte-order-mark and a magic encoding comment
"
return
'
utf_8
'
elif
m
:
return
m
.
group
(
1
)
else
:
return
None
finally
:
fp
.
seek
(
pos
)
def
restore__ast
(
_ast
):
"""
Attempt to restore the required classes to the _ast module if it
appears to be missing them
...
...
This diff is collapsed.
Click to expand it.
test/exceptions_.py
+
9
−
0
View file @
04a09d48
...
...
@@ -60,6 +60,15 @@ ${u'привет'}
assert
False
,
(
"
This function should trigger a CompileException,
"
"
but didn
'
t
"
)
def
test_py_utf8_html_error_template
(
self
):
try
:
foo
=
u
'
日本
'
raise
RuntimeError
(
'
test
'
)
except
:
html_error
=
exceptions
.
html_error_template
().
render
()
assert
'
RuntimeError: test
'
in
html_error
assert
"
foo = u
'
日本
'"
in
html_error
def
test_format_exceptions
(
self
):
l
=
TemplateLookup
(
format_exceptions
=
True
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment