diff options
author | Marius Gedminas <marius@gedmin.as> | 2013-02-07 23:04:56 +0000 |
---|---|---|
committer | Marius Gedminas <marius@gedmin.as> | 2013-02-07 23:04:56 +0000 |
commit | cec5452b6cb93ed0d0139be1d01aa660e14b3bbb (patch) | |
tree | d1e4eed56d64c239e1a9f80a01f47480a18c6f06 /src | |
parent | 040631594cdcf3edb55e35e80bb0b6ef1ba66921 (diff) | |
download | zope-tal-cec5452b6cb93ed0d0139be1d01aa660e14b3bbb.tar.gz |
Towards Py3K: use io.StringIO
While Python 2.6+ also has io.StringIO(), using it causes numerous test
failures -- because io.StringIO() insists on unicode, and our tests are
full of (ASCII-only) native string literals. For this reason I decided
to keep using StringIO.StringIO or cStringIO.StringIO on Python 2.x.
Diffstat (limited to 'src')
-rw-r--r-- | src/zope/tal/dummyengine.py | 11 | ||||
-rw-r--r-- | src/zope/tal/runtest.py | 7 | ||||
-rw-r--r-- | src/zope/tal/tests/test_sourcepos.py | 7 | ||||
-rw-r--r-- | src/zope/tal/tests/test_talgettext.py | 8 | ||||
-rw-r--r-- | src/zope/tal/tests/test_talinterpreter.py | 7 |
5 files changed, 34 insertions, 6 deletions
diff --git a/src/zope/tal/dummyengine.py b/src/zope/tal/dummyengine.py index 1e954a7..6cb4ac3 100644 --- a/src/zope/tal/dummyengine.py +++ b/src/zope/tal/dummyengine.py @@ -15,6 +15,13 @@ """ import re +try: + # Python 2.x + from StringIO import StringIO +except ImportError: + # Python 3.x + from io import StringIO + from zope.interface import implementer from zope.tal.taldefs import NAME_RE, TALExpressionError, ErrorInfo from zope.tal.interfaces import ITALExpressionCompiler, ITALExpressionEngine @@ -209,7 +216,7 @@ class DummyEngine(object): locals = self.locals.copy() assert lang == 'text/server-python' - import sys, StringIO + import sys # Removing probable comments if code.strip().startswith('<!--') and code.strip().endswith('-->'): @@ -223,7 +230,7 @@ class DummyEngine(object): if code.startswith(' ') or code.startswith('\t'): code = 'if 1 == 1:\n' + code + '\n' tmp = sys.stdout - sys.stdout = StringIO.StringIO() + sys.stdout = StringIO() try: exec(code, globals, locals) finally: diff --git a/src/zope/tal/runtest.py b/src/zope/tal/runtest.py index 5c50e52..fb002b8 100644 --- a/src/zope/tal/runtest.py +++ b/src/zope/tal/runtest.py @@ -23,7 +23,12 @@ import sys import traceback import difflib -from cStringIO import StringIO +try: + # Python 2.x + from cStringIO import StringIO +except ImportError: + # Python 3.x + from io import StringIO if __name__ == "__main__": from . import setpath # Local hack to tweak sys.path etc. diff --git a/src/zope/tal/tests/test_sourcepos.py b/src/zope/tal/tests/test_sourcepos.py index e9497f9..4cf1053 100644 --- a/src/zope/tal/tests/test_sourcepos.py +++ b/src/zope/tal/tests/test_sourcepos.py @@ -15,7 +15,12 @@ """ import unittest -from StringIO import StringIO +try: + # Python 2.x + from StringIO import StringIO +except ImportError: + # Python 3.x + from io import StringIO from zope.tal.htmltalparser import HTMLTALParser from zope.tal.talinterpreter import TALInterpreter diff --git a/src/zope/tal/tests/test_talgettext.py b/src/zope/tal/tests/test_talgettext.py index 2b16938..d4761ff 100644 --- a/src/zope/tal/tests/test_talgettext.py +++ b/src/zope/tal/tests/test_talgettext.py @@ -15,7 +15,13 @@ """ import sys import unittest -from StringIO import StringIO + +try: + # Python 2.x + from StringIO import StringIO +except ImportError: + # Python 3.x + from io import StringIO from zope.tal.htmltalparser import HTMLTALParser from zope.tal.talgettext import POTALInterpreter diff --git a/src/zope/tal/tests/test_talinterpreter.py b/src/zope/tal/tests/test_talinterpreter.py index c8dcfce..25799fb 100644 --- a/src/zope/tal/tests/test_talinterpreter.py +++ b/src/zope/tal/tests/test_talinterpreter.py @@ -18,7 +18,12 @@ import os import sys import unittest -from StringIO import StringIO +try: + # Python 2.x + from StringIO import StringIO +except ImportError: + # Python 3.x + from io import StringIO from zope.tal.taldefs import METALError, I18NError, TAL_VERSION from zope.tal.taldefs import TALExpressionError |