| 476 |
|
if returnGenerator:
|
| 477 |
|
return _resultAsGenerator(result, inputEncoding, outputEncoding, outputEncodingErrors)
|
| 478 |
|
else:
|
| 479 |
|
result = ''.join(list(result))
|
| 480 |
|
if not isinstance(result, unicode):
|
| 481 |
|
if inputEncoding:
|
| 482 |
|
result = unicode(result, inputEncoding)
|
| 483 |
|
if outputEncoding:
|
| 484 |
|
return result.encode(outputEncoding, outputEncodingErrors)
|
| 485 |
|
return result
|
| |
477 |
if returnGenerator:
|
| |
478 |
return _resultAsGenerator(result, inputEncoding, outputEncoding, outputEncodingErrors)
|
| |
479 |
else:
|
| |
480 |
result = ''.join(list(result))
|
| |
481 |
if not isinstance(result, unicode):
|
| |
482 |
if inputEncoding:
|
| |
483 |
result = unicode(result, inputEncoding)
|
| |
484 |
if outputEncoding:
|
| |
485 |
return result.encode(outputEncoding, outputEncodingErrors)
|
| |
486 |
return result
|
| |
487 |
except:
|
| |
488 |
# In case of an exception, we include the body of the template in
|
| |
489 |
# the traceback
|
| |
490 |
import sys, traceback
|
| |
491 |
tb = "".join(traceback.format_exception(*sys.exc_info()))
|
| |
492 |
errorList = ["An error occured while trying to render a template."]
|
| |
493 |
if file is not None:
|
| |
494 |
errorList.append("The template file was %s" % repr(file))
|
| |
495 |
errorList.append("The traceback was:")
|
| |
496 |
errorList.append(_indentAndNumberCode(tb, number = False))
|
| |
497 |
errorList.append("The template code was:")
|
| |
498 |
errorList.append(_indentAndNumberCode(template))
|
| |
499 |
if file is None:
|
| |
500 |
errorList.append("The original template was:")
|
| |
501 |
errorList.append(_indentAndNumberCode(originalTemplate, number = False))
|
| |
502 |
raise RenderError, '\n'.join(errorList)
|