aboutsummaryrefslogtreecommitdiffstats
path: root/mako/exceptions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-04 23:45:40 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-04 23:45:40 +0000
commita629df3f7ef4e36573671018a25e2e9aa0889dbf (patch)
treeeaefb6faad4bbaaf66ddfa27346b9cf2b29a414d /mako/exceptions.py
parent4d91d760cd4ef62192c74ff0aa6c27c3d6dff844 (diff)
downloadexternal_python_mako-a629df3f7ef4e36573671018a25e2e9aa0889dbf.tar.gz
external_python_mako-a629df3f7ef4e36573671018a25e2e9aa0889dbf.tar.bz2
external_python_mako-a629df3f7ef4e36573671018a25e2e9aa0889dbf.zip
- merged -r481:499 of py3k branch.
- Python 3 support is added ! See README.py3k for installation and testing notes. [ticket:119]
Diffstat (limited to 'mako/exceptions.py')
-rw-r--r--mako/exceptions.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/mako/exceptions.py b/mako/exceptions.py
index dcd6a64..b8b7747 100644
--- a/mako/exceptions.py
+++ b/mako/exceptions.py
@@ -19,7 +19,9 @@ def _format_filepos(lineno, pos, filename):
if filename is None:
return " at line: %d char: %d" % (lineno, pos)
else:
- return " in file '%s' at line: %d char: %d" % (filename, lineno, pos)
+ return " in file '%s' at line: %d char: %d" % (filename, lineno, pos)
+
+
class CompileException(MakoException):
def __init__(self, message, source, lineno, pos, filename):
MakoException.__init__(self, message + _format_filepos(lineno, pos, filename))
@@ -35,6 +37,9 @@ class SyntaxException(MakoException):
self.pos = pos
self.filename = filename
self.source = source
+
+class UnsupportedError(MakoException):
+ """raised when a retired feature is used."""
class TemplateLookupException(MakoException):
pass
@@ -130,17 +135,19 @@ class RichTraceback(object):
template_filename = info.template_filename or filename
except KeyError:
# A normal .py file (not a Template)
- try:
- fp = open(filename)
- encoding = util.parse_encoding(fp)
- fp.close()
- except IOError:
- encoding = None
- if encoding:
- line = line.decode(encoding)
- else:
- line = line.decode('ascii', 'replace')
- new_trcback.append((filename, lineno, function, line, None, None, None, None))
+ if not util.py3k:
+ try:
+ fp = open(filename, 'rb')
+ encoding = util.parse_encoding(fp)
+ fp.close()
+ except IOError:
+ encoding = None
+ if encoding:
+ line = line.decode(encoding)
+ else:
+ line = line.decode('ascii', 'replace')
+ new_trcback.append((filename, lineno, function, line,
+ None, None, None, None))
continue
template_ln = module_ln = 1
@@ -161,7 +168,9 @@ class RichTraceback(object):
template_line = template_lines[template_ln - 1]
else:
template_line = None
- new_trcback.append((filename, lineno, function, line, template_filename, template_ln, template_line, template_source))
+ new_trcback.append((filename, lineno, function,
+ line, template_filename, template_ln,
+ template_line, template_source))
if not self.source:
for l in range(len(new_trcback)-1, 0, -1):
if new_trcback[l][5]:
@@ -171,7 +180,7 @@ class RichTraceback(object):
else:
try:
# A normal .py file (not a Template)
- fp = open(new_trcback[-1][0])
+ fp = open(new_trcback[-1][0], 'rb')
encoding = util.parse_encoding(fp)
fp.seek(0)
self.source = fp.read()