Commit c756f243 by Chris Jerdonek

Added extension argument to Loader constructor.

parent 00090310
...@@ -15,21 +15,25 @@ from . import defaults ...@@ -15,21 +15,25 @@ from . import defaults
class Loader(object): class Loader(object):
def __init__(self, encoding=None, decode_errors=None): def __init__(self, encoding=None, decode_errors=None, extension=None):
""" """
Construct a template reader. Construct a template reader.
Arguments: Arguments:
decode_errors: the string to pass as the errors argument to the
built-in function unicode() when converting str strings to
unicode. Defaults to the package default.
encoding: the file encoding. This is the name of the encoding to encoding: the file encoding. This is the name of the encoding to
use when converting file contents to unicode. This name is use when converting file contents to unicode. This name is
passed as the encoding argument to Python's built-in function passed as the encoding argument to Python's built-in function
unicode(). Defaults to the encoding name returned by unicode(). Defaults to the encoding name returned by
sys.getdefaultencoding(). sys.getdefaultencoding().
decode_errors: the string to pass as the errors argument to the extension: the template file extension. Pass False for no
built-in function unicode() when converting str strings to extension (i.e. to use extensionless template files).
unicode. Defaults to the package default. Defaults to the package default.
""" """
if decode_errors is None: if decode_errors is None:
...@@ -38,8 +42,12 @@ class Loader(object): ...@@ -38,8 +42,12 @@ class Loader(object):
if encoding is None: if encoding is None:
encoding = sys.getdefaultencoding() encoding = sys.getdefaultencoding()
if extension is None:
extension = defaults.TEMPLATE_EXTENSION
self.decode_errors = decode_errors self.decode_errors = decode_errors
self.encoding = encoding self.encoding = encoding
self.extension = extension
def unicode(self, s, encoding=None): def unicode(self, s, encoding=None):
""" """
......
...@@ -38,6 +38,14 @@ class ReaderTestCase(unittest.TestCase, AssertStringMixin): ...@@ -38,6 +38,14 @@ class ReaderTestCase(unittest.TestCase, AssertStringMixin):
reader = Reader(encoding='foo') reader = Reader(encoding='foo')
self.assertEquals(reader.encoding, 'foo') self.assertEquals(reader.encoding, 'foo')
def test_init__extension(self):
# Test the default value.
reader = Reader()
self.assertEquals(reader.extension, 'mustache')
reader = Reader(extension='foo')
self.assertEquals(reader.extension, 'foo')
def test_unicode__basic__input_str(self): def test_unicode__basic__input_str(self):
""" """
Test unicode(): default arguments with str input. Test unicode(): default arguments with str input.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment