Commit caa2fe39 authored by Stefan Behnel's avatar Stefan Behnel

make some imports compatible with Py2/Py3

parent 4a761906
......@@ -11,7 +11,7 @@ from datetime import datetime
from functools import partial
from collections import defaultdict
from xml.sax.saxutils import escape as html_escape
from StringIO import StringIO
from io import StringIO
from . import Version
from .Code import CCodeWriter
......
......@@ -6,6 +6,12 @@ from __future__ import absolute_import
import copy
import re
try:
import __builtin__ as builtins
except ImportError: # Py3
import builtins
from .Errors import warning, error, InternalError
from .StringEncoding import EncodedString
from . import Options, Naming
......@@ -14,8 +20,8 @@ from .PyrexTypes import py_object_type, unspecified_type
from .TypeSlots import \
pyfunction_signature, pymethod_signature, \
get_special_method_signature, get_property_accessor_signature
from . import Code
import __builtin__ as builtins
iso_c99_keywords = set(
['auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
......
......@@ -9,7 +9,7 @@ Support for parsing strings into code trees.
from __future__ import absolute_import
import re
from StringIO import StringIO
from io import StringIO
from .Scanning import PyrexScanner, StringSourceDescriptor
from .Symtab import ModuleScope
......
from cStringIO import StringIO
from io import StringIO
class StringIOTree(object):
......
......@@ -29,6 +29,8 @@ can use ``__name='tmpl.html'`` to set the name of the template.
If there are syntax errors ``TemplateError`` will be raised.
"""
from __future__ import absolute_import
import re
import sys
import cgi
......@@ -38,12 +40,10 @@ except ImportError: # Py3
from urllib.parse import quote as url_quote
import os
import tokenize
try:
from io import StringIO
except ImportError:
from cStringIO import StringIO
from Cython.Tempita._looper import looper
from Cython.Tempita.compat3 import bytes, basestring_, next, is_unicode, coerce_text
from io import StringIO
from ._looper import looper
from .compat3 import bytes, basestring_, next, is_unicode, coerce_text
__all__ = ['TemplateError', 'Template', 'sub', 'HTMLTemplate',
'sub_html', 'html', 'bunch']
......
......@@ -38,11 +38,13 @@ if __name__ == '__main__':
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
"""
from __future__ import absolute_import
import os
import sys
import time
from unittest import TestResult, _TextTestResult, TextTestRunner
from cStringIO import StringIO
from io import StringIO
import xml.dom.minidom
......
......@@ -23,21 +23,13 @@ except (ImportError, AttributeError):
IS_CPYTHON = True
IS_PYPY = False
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from io import StringIO, open as io_open
try:
import cPickle as pickle
except ImportError:
import pickle
try:
from io import open as io_open
except ImportError:
from codecs import open as io_open
try:
import threading
except ImportError: # No threads, no problems
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment