summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanno Schlichting <hanno@hannosch.eu>2011-08-20 16:02:17 +0000
committerHanno Schlichting <hanno@hannosch.eu>2011-08-20 16:02:17 +0000
commitbdf8bee958fbe7c48717553423373781c6679770 (patch)
tree514c5ccae41475188856410ddaf547a5af0b5f37
parent26fadc496dcafd4f668841b98ba5c530e828ee53 (diff)
downloadzope-tal-bdf8bee958fbe7c48717553423373781c6679770.tar.gz
Updated `talinterpreter.FasterStringIO` to faster list-based implementation.
-rw-r--r--CHANGES.txt2
-rw-r--r--src/zope/tal/talinterpreter.py30
2 files changed, 13 insertions, 19 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index d23887a..ef7cc4c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,6 +5,8 @@ CHANGES
3.6.0 (unreleased)
------------------
+- Updated `talinterpreter.FasterStringIO` to faster list-based implementation.
+
- Increase the default value of the `wrap` argument from 60 to 1023 characters,
to avoid extra whitespace and line breaks.
diff --git a/src/zope/tal/talinterpreter.py b/src/zope/tal/talinterpreter.py
index b691868..d98323e 100644
--- a/src/zope/tal/talinterpreter.py
+++ b/src/zope/tal/talinterpreter.py
@@ -18,9 +18,6 @@ import operator
import sys
import warnings
-# Do not use cStringIO here! It's not unicode aware. :(
-from StringIO import StringIO
-
from zope.i18nmessageid import Message
from zope.tal.taldefs import quote, TAL_VERSION, METALError
from zope.tal.taldefs import isCurrentVersion
@@ -996,23 +993,18 @@ class TALInterpreter(object):
bytecode_handlers_tal["optTag"] = do_optTag_tal
-class FasterStringIO(StringIO):
- """Append-only version of StringIO.
-
- This let's us have a much faster write() method.
+class FasterStringIO(list):
+ """Unicode-aware append-only version of StringIO.
"""
- def close(self):
- if not self.closed:
- self.write = _write_ValueError
- StringIO.close(self)
-
- def seek(self, pos, mode=0):
- raise RuntimeError("FasterStringIO.seek() not allowed")
-
- def write(self, s):
- #assert self.pos == self.len
- self.buflist.append(s)
- self.len = self.pos = self.pos + len(s)
+ write = list.append
+
+ def __init__(self, value=None):
+ list.__init__(self)
+ if value is not None:
+ self.append(value)
+
+ def getvalue(self):
+ return u''.join(self)
def _write_ValueError(s):