11
11
12
12
from mako import exceptions
13
13
from mako import util
14
+ from mako import compat
14
15
from mako .template import Template
15
16
16
17
try :
@@ -249,7 +250,7 @@ def get_template(self, uri):
249
250
return self ._check (uri , self ._collection [uri ])
250
251
else :
251
252
return self ._collection [uri ]
252
- except KeyError :
253
+ except KeyError as e :
253
254
u = re .sub (r"^\/+" , "" , uri )
254
255
for dir_ in self .directories :
255
256
# make sure the path seperators are posix - os.altsep is empty
@@ -259,8 +260,12 @@ def get_template(self, uri):
259
260
if os .path .isfile (srcfile ):
260
261
return self ._load (srcfile , uri )
261
262
else :
262
- raise exceptions .TopLevelLookupException (
263
- "Cant locate template for uri %r" % uri
263
+ compat .reraise (
264
+ exceptions .TopLevelLookupException ,
265
+ exceptions .TopLevelLookupException (
266
+ "Cant locate template for uri %r" % uri
267
+ ),
268
+ cause = e
264
269
)
265
270
266
271
def adjust_uri (self , uri , relativeto ):
@@ -347,10 +352,14 @@ def _check(self, uri, template):
347
352
return self ._load (template .filename , uri )
348
353
else :
349
354
return template
350
- except OSError :
355
+ except OSError as e :
351
356
self ._collection .pop (uri , None )
352
- raise exceptions .TemplateLookupException (
353
- "Cant locate template for uri %r" % uri
357
+ compat .reraise (
358
+ exceptions .TemplateLookupException ,
359
+ exceptions .TemplateLookupException (
360
+ "Cant locate template for uri %r" % uri
361
+ ),
362
+ cause = e
354
363
)
355
364
356
365
def put_string (self , uri , text ):
0 commit comments