summaryrefslogtreecommitdiff
path: root/pystache/loader.py
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2011-12-23 16:53:50 -0800
committerChris Jerdonek <chris.jerdonek@gmail.com>2011-12-23 16:53:50 -0800
commit3a960197fa06f5c912b7651eac61431877f1bc67 (patch)
tree902c3fc49c850afd3935089a4e80c091f3994600 /pystache/loader.py
parent10e867c92393089b74113ab7053cc00137fb22ce (diff)
downloadpystache-3a960197fa06f5c912b7651eac61431877f1bc67.tar.gz
Fixed issue #65: "Loader should accept decode_errors like Renderer"
Diffstat (limited to 'pystache/loader.py')
-rw-r--r--pystache/loader.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/pystache/loader.py b/pystache/loader.py
index 9dfa71c..4647bbb 100644
--- a/pystache/loader.py
+++ b/pystache/loader.py
@@ -8,12 +8,13 @@ This module provides a Loader class.
import os
import sys
+DEFAULT_DECODE_ERRORS = 'strict'
DEFAULT_EXTENSION = 'mustache'
class Loader(object):
- def __init__(self, search_dirs=None, encoding=None, extension=None):
+ def __init__(self, search_dirs=None, extension=None, encoding=None, decode_errors=None):
"""
Construct a template loader.
@@ -32,8 +33,14 @@ class Loader(object):
argument to the built-in function unicode(). Defaults to the
encoding name returned by sys.getdefaultencoding().
+ decode_errors: the string to pass as the "errors" argument to the
+ built-in function unicode() when converting file contents to
+ unicode. Defaults to "strict".
"""
+ if decode_errors is None:
+ decode_errors = DEFAULT_DECODE_ERRORS
+
if encoding is None:
encoding = sys.getdefaultencoding()
@@ -46,6 +53,7 @@ class Loader(object):
if isinstance(search_dirs, basestring):
search_dirs = [search_dirs]
+ self.decode_errors = decode_errors
self.search_dirs = search_dirs
self.template_encoding = encoding
self.template_extension = extension
@@ -88,6 +96,6 @@ class Loader(object):
finally:
f.close()
- template = unicode(template, self.template_encoding)
+ template = unicode(template, self.template_encoding, self.decode_errors)
return template