summaryrefslogtreecommitdiff
path: root/simplejson
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-04-25 11:14:29 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2018-04-25 11:14:29 +0300
commit7c7b77d4beae7d2c69947fb1374177ce2095af4e (patch)
treeaae04e92e05c15b19eb33b4b7e0d0774708cb67c /simplejson
parent4af3c417547b4a0505e4b1baa5dbd360b7665e7e (diff)
downloadsimplejson-7c7b77d4beae7d2c69947fb1374177ce2095af4e.tar.gz
Support builds without cStringIO.cStringIO
The cStringIO module is optional. Fall back to StringIO if it is not available.
Diffstat (limited to 'simplejson')
-rw-r--r--simplejson/compat.py11
-rw-r--r--simplejson/tests/__init__.py8
2 files changed, 13 insertions, 6 deletions
diff --git a/simplejson/compat.py b/simplejson/compat.py
index b5df5af..5fc1412 100644
--- a/simplejson/compat.py
+++ b/simplejson/compat.py
@@ -5,8 +5,11 @@ if sys.version_info[0] < 3:
PY3 = False
def b(s):
return s
- import cStringIO as StringIO
- StringIO = BytesIO = StringIO.StringIO
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
+ BytesIO = StringIO
text_type = unicode
binary_type = str
string_types = (basestring,)
@@ -21,9 +24,7 @@ else:
from imp import reload as reload_module
def b(s):
return bytes(s, 'latin1')
- import io
- StringIO = io.StringIO
- BytesIO = io.BytesIO
+ from io import StringIO, BytesIO
text_type = str
binary_type = bytes
string_types = (str,)
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py
index 8d2642f..25d3305 100644
--- a/simplejson/tests/__init__.py
+++ b/simplejson/tests/__init__.py
@@ -1,6 +1,5 @@
from __future__ import absolute_import
import unittest
-import doctest
import sys
import os
@@ -28,6 +27,13 @@ def additional_tests(suite=None):
import simplejson.decoder
if suite is None:
suite = unittest.TestSuite()
+ try:
+ import doctest
+ except ImportError:
+ if sys.version_info < (2, 7):
+ # doctests in 2.6 depends on cStringIO
+ return suite
+ raise
for mod in (simplejson, simplejson.encoder, simplejson.decoder):
suite.addTest(doctest.DocTestSuite(mod))
suite.addTest(doctest.DocFileSuite('../../index.rst'))