diff options
-rw-r--r-- | mako/_ast_util.py | 1 | ||||
-rw-r--r-- | mako/pyparser.py | 1 | ||||
-rw-r--r-- | mako/template.py | 4 | ||||
-rw-r--r-- | mako/util.py | 5 | ||||
-rw-r--r-- | test/test_util.py | 29 |
5 files changed, 34 insertions, 6 deletions
diff --git a/mako/_ast_util.py b/mako/_ast_util.py index 41a40c4..9521ccb 100644 --- a/mako/_ast_util.py +++ b/mako/_ast_util.py @@ -4,7 +4,6 @@ # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -# -*- coding: utf-8 -*- """ ast ~~~ diff --git a/mako/pyparser.py b/mako/pyparser.py index aaf8125..953596a 100644 --- a/mako/pyparser.py +++ b/mako/pyparser.py @@ -1,6 +1,5 @@ # mako/pyparser.py # Copyright (C) 2006-2011 the Mako authors and contributors <see AUTHORS file> -# Copyright (C) Mako developers # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/mako/template.py b/mako/template.py index f93be79..6166895 100644 --- a/mako/template.py +++ b/mako/template.py @@ -96,8 +96,8 @@ class Template(object): Python module file. For advanced usage only. :param output_encoding: The encoding to use when :meth:`.render` - is called. See :ref:`usage_unicode` as well as - :ref:`unicode_toplevel`. + is called. Defaults to ``ascii`` as of Mako 0.4.0. + See :ref:`usage_unicode` as well as :ref:`unicode_toplevel`. :param preprocessor: Python callable which will be passed the full template source before it is parsed. The return diff --git a/mako/util.py b/mako/util.py index 3613a5b..5518b4d 100644 --- a/mako/util.py +++ b/mako/util.py @@ -112,7 +112,7 @@ class SetLikeDict(dict): class FastEncodingBuffer(object): """a very rudimentary buffer that is faster than StringIO, - but doesnt crash on unicode data like cStringIO.""" + but doesn't crash on unicode data like cStringIO.""" def __init__(self, encoding=None, errors='strict', unicode=False): self.data = collections.deque() @@ -126,7 +126,8 @@ class FastEncodingBuffer(object): self.write = self.data.append def truncate(self): - self.data =collections.deque() + self.data = collections.deque() + self.write = self.data.append def getvalue(self): if self.encoding: diff --git a/test/test_util.py b/test/test_util.py new file mode 100644 index 0000000..8f826a0 --- /dev/null +++ b/test/test_util.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import unittest +from mako import util +from test import eq_ + +class UtilTest(unittest.TestCase): + def test_fast_buffer_write(self): + buf = util.FastEncodingBuffer() + buf.write("string a ") + buf.write("string b") + eq_(buf.getvalue(), "string a string b") + + def test_fast_buffer_truncate(self): + buf = util.FastEncodingBuffer() + buf.write("string a ") + buf.write("string b") + buf.truncate() + buf.write("string c ") + buf.write("string d") + eq_(buf.getvalue(), "string c string d") + + def test_fast_buffer_encoded(self): + s = u"drôl m’a rée « S’il" + buf = util.FastEncodingBuffer(encoding='utf-8') + buf.write(s[0:10]) + buf.write(s[10:]) + q = buf.getvalue() + eq_(buf.getvalue(), s.encode('utf-8'))
\ No newline at end of file |