Skip to content

Commit a912e2a

Browse files
committed
safely import simplejson for python 2.6
1 parent 64b8abb commit a912e2a

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

plotly/exceptions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
1616
1717
"""
18-
import json
18+
import sys
1919
import six
2020

21+
if sys.version[:3] == '2.6':
22+
import simplejson as json
23+
else:
24+
import json
25+
2126
## Base Plotly Error ##
2227

2328
class PlotlyError(Exception):

plotly/grid_objs/grid_objs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
"""
66
from __future__ import absolute_import
77

8-
9-
import json
8+
import sys
109
from collections import MutableSequence
1110
from plotly import exceptions
1211
from plotly import utils
1312

13+
if sys.version[:3] == '2.6':
14+
import simplejson as json
15+
else:
16+
import json
17+
1418
__all__ = None
1519

1620

plotly/plotly/plotly.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import absolute_import
1818

1919
import sys
20-
import json
2120
import warnings
2221
import copy
2322
import os
@@ -30,6 +29,11 @@
3029
else:
3130
from urllib.parse import urlparse
3231

32+
if sys.version[:3] == '2.6':
33+
import simplejson as json
34+
else:
35+
import json
36+
3337
from plotly.plotly import chunked_requests
3438
from plotly import utils
3539
from plotly import tools

plotly/tests/test_core/test_get_figure/test_get_figure.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from plotly import exceptions
1111
from nose.tools import raises
1212
import six
13-
import json
1413

1514
from unittest import TestCase
1615

plotly/tests/test_core/test_get_requests/test_get_requests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
import requests
1010
import copy
11-
import json
1211
import six
12+
import sys
13+
14+
if sys.version[:3] == '2.6':
15+
import simplejson as json
16+
else:
17+
import json
1318

1419
default_headers = {'plotly-username': '',
1520
'plotly-apikey': '',

plotly/tests/test_core/test_utils/test_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import json
1+
import sys
22
from unittest import TestCase
33

44
from plotly.utils import PlotlyJSONEncoder
55

6+
if sys.version[:3] == '2.6':
7+
import simplejson as json
8+
else:
9+
import json
10+
611

712
class TestJSONEncoder(TestCase):
813

plotly/widgets/graph_widget.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import deque
2-
import json
32
import uuid
3+
import sys
44

55
# TODO: protected imports?
66
from IPython.html import widgets
@@ -11,6 +11,12 @@
1111
from plotly.graph_objs import Figure
1212
from pkg_resources import resource_string
1313

14+
# even though python 2.6 wouldn't be able to run *any* of this...
15+
if sys.version[:3] == '2.6':
16+
import simplejson as json
17+
else:
18+
import json
19+
1420
# Load JS widget code
1521
# No officially recommended way to do this in any other way
1622
# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html

0 commit comments

Comments
 (0)