diff options
author | R. Tyler Ballance <tyler@monkeypox.org> | 2009-10-14 22:39:58 -0700 |
---|---|---|
committer | R. Tyler Ballance <tyler@monkeypox.org> | 2009-10-14 22:41:48 -0700 |
commit | b51cd10aa0e22a55029833c1e80cd9bd6846e38d (patch) | |
tree | 88928666de37eb238b1c2e53efdfc9d6fbe168ad | |
parent | e0df2a214f6404b41073127ed4b8b52cbb1f6380 (diff) | |
download | python-cheetah-b51cd10aa0e22a55029833c1e80cd9bd6846e38d.tar.gz |
Revert "Use cStringIO instead of array in DummyTransaction"
This reverts commit 9ac5e4c6ed36c3b6b1bc8340fdb69d32db9d98c4.
Left some of my previous changes in place; self._outputChunks
will deal with only utf-8 encoded strings and then decode them all
at the very end
Conflicts:
cheetah/DummyTransaction.py
-rw-r--r--[-rwxr-xr-x] | cheetah/DummyTransaction.py | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/cheetah/DummyTransaction.py b/cheetah/DummyTransaction.py index e04a604..6726a63 100755..100644 --- a/cheetah/DummyTransaction.py +++ b/cheetah/DummyTransaction.py @@ -10,11 +10,6 @@ specific DummyTransaction or DummyResponse behavior import types -try: - from cStringIO import StringIO -except ImportError: - import StringIO - class DummyResponseFailure(Exception): pass @@ -25,15 +20,15 @@ class DummyResponse(object): servlet ''' def __init__(self): - self._outputChunks = StringIO() - + self._outputChunks = [] + def flush(self): pass def write(self, value): if isinstance(value, unicode): value = value.encode('utf-8') - self._outputChunks.write(value) + self._outputChunks.append(value) def writeln(self, txt): @@ -41,17 +36,11 @@ class DummyResponse(object): write('\n') def getvalue(self, outputChunks=None): - #chunks = outputChunks or self._outputChunks - try: - if outputChunks is not None: - return ''.join(outputChunks) - else: - return self._outputChunks.getvalue().decode('utf-8') + chunks = outputChunks or self._outputChunks + try: + return ''.join(chunks).decode('utf-8') except UnicodeDecodeError, ex: - #not sure about the best way to check for non-unicode in StringIO - nonunicode = '' - if outputChunks: - nonunicode = [c for c in outputChunks if not isinstance(c, unicode)] + nonunicode = [c for c in chunks if not isinstance(c, unicode)] raise DummyResponseFailure('''Looks like you're trying to mix encoded strings with Unicode strings (most likely utf-8 encoded ones) |