Skip to content
Myr

Added `TemplateStream.dump`.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent d02fc7d · Browse files · 3 files+30 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+30 added−1 removed

  • other:+30 added−1 removed

3 files+30 added−1 removed

modified:docs/api.rst+1 added-1 removed
214 unmodified lines
215 .. automethod:: stream([context])216217218.. autoclass:: jinja2.environment.TemplateStream()219 :members: disable_buffering, enable_buffering219 :members: disable_buffering, enable_buffering, dump220221222.. _identifier-naming:223
402 unmodified lines
modified:jinja2/environment.py+27 added
679 unmodified lines
680 def __init__(self, gen):681 self._gen = gen682 self.disable_buffering()683684 def dump(self, fp, encoding=None, errors='strict'):685 """Dump the complete stream into a file or file-like object.686 Per default unicode strings are written, if you want to encode687 before writing specifiy an `encoding`.688689 Example usage::690691 Template('Hello {{ name }}!').stream(name='foo').dump('hello.html')692 """693 close = False694 if isinstance(fp, basestring):695 fp = file(fp, 'w')696 close = True697 try:698 if encoding is not None:699 iterable = (x.encode(encoding, errors) for x in self)700 else:701 iterable = self702 if hasattr(fp, 'writelines'):703 fp.writelines(iterable)704 else:705 for item in iterable:706 fp.write(item)707 finally:708 if close:709 fp.close()710711 def disable_buffering(self):712 """Disable the output buffering."""713 self._next = self._gen.next714 self.buffered = False
38 unmodified lines
modified:CHANGES+2 added
15 unmodified lines
16- added support for preprocessing and token stream filtering for extensions.17 This would allow extensions to allow simplified gettext calls in template18 data and something similar.1920- added :meth:`jinja2.environment.TemplateStream.dump`.2122Version 2.0rc123--------------24(no codename, released on July 9th 2008)25
1 unmodified line