Mercurial > genshi > genshi-test
diff genshi/template/base.py @ 935:705727288d7e
Merge r1143 from py3k:
add support for python 3 to remaining genshi.template components:
* minor changes to track encoding=None API change in core genshi modules.
* genshi/template/directives:
* slightly odd syntax changes to make the 2to3 .next() fixer pick up *stream.next()
* minor test fix for change in behaviour of division (/) in Python 3.
* genshi/template/loader:
* add 'b' to file modes to ensure it's loaded as bytes in Python 3.
* use not isinstance(s, unicode) instead of isinstance(s, str) since the former is correctly converted by 2to3.
author | hodgestar |
---|---|
date | Fri, 18 Mar 2011 09:17:52 +0000 |
parents | 85e4678337cf |
children |
line wrap: on
line diff
--- a/genshi/template/base.py +++ b/genshi/template/base.py @@ -15,9 +15,9 @@ from collections import deque import os -from StringIO import StringIO import sys +from genshi.compat import StringIO, BytesIO from genshi.core import Attrs, Stream, StreamEventKind, START, TEXT, _ensure from genshi.input import ParseError @@ -398,10 +398,11 @@ self._init_loader() self._prepared = False - if isinstance(source, basestring): - source = StringIO(source) - else: - source = source + if not isinstance(source, Stream) and not hasattr(source, 'read'): + if isinstance(source, unicode): + source = StringIO(source) + else: + source = BytesIO(source) try: self._stream = self._parse(source, encoding) except ParseError, e: