Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception causes in lookup.py #319

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions mako/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import stat

from mako import exceptions
from mako import compat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually don't need this import as "reraise" should be available as util.reraise().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not available as util.reraise:

import mako.util
mako.util.reraise
Traceback (most recent call last):
  Python Shell, prompt 3, line 1
builtins.AttributeError: module 'mako.util' has no attribute 'reraise'

from mako import util
from mako.template import Template

Expand Down Expand Up @@ -249,7 +250,7 @@ def get_template(self, uri):
return self._check(uri, self._collection[uri])
else:
return self._collection[uri]
except KeyError:
except KeyError as e:
u = re.sub(r"^\/+", "", uri)
for dir_ in self.directories:
# make sure the path seperators are posix - os.altsep is empty
Expand All @@ -259,8 +260,12 @@ def get_template(self, uri):
if os.path.isfile(srcfile):
return self._load(srcfile, uri)
else:
raise exceptions.TopLevelLookupException(
"Cant locate template for uri %r" % uri
compat.reraise(
exceptions.TopLevelLookupException,
exceptions.TopLevelLookupException(
"Cant locate template for uri %r" % uri
),
cause=e
)

def adjust_uri(self, uri, relativeto):
Expand Down Expand Up @@ -347,10 +352,14 @@ def _check(self, uri, template):
return self._load(template.filename, uri)
else:
return template
except OSError:
except OSError as e:
self._collection.pop(uri, None)
raise exceptions.TemplateLookupException(
"Cant locate template for uri %r" % uri
compat.reraise(
exceptions.TemplateLookupException,
exceptions.TemplateLookupException(
"Cant locate template for uri %r" % uri
),
cause=e
)

def put_string(self, uri, text):
Expand Down