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