11
11
import cPickle as pickle
12
12
#import pickle
13
13
14
- from cStringIO import StringIO
14
+ from io import BytesIO
15
15
16
16
17
17
def depth_getter (obj ,
@@ -87,7 +87,7 @@ def recursive_pickle(top_obj):
87
87
for _ , obj , location in objs :
88
88
# print('trying %s' % location)
89
89
try :
90
- pickle .dump (obj , StringIO (), pickle .HIGHEST_PROTOCOL )
90
+ pickle .dump (obj , BytesIO (), pickle .HIGHEST_PROTOCOL )
91
91
except Exception , err :
92
92
print (obj )
93
93
print ('Failed to pickle %s. \n Type: %s. Traceback follows:' % (location , type (obj )))
@@ -99,21 +99,21 @@ def test_simple():
99
99
fig = plt .figure ()
100
100
# un-comment to debug
101
101
# recursive_pickle(fig)
102
- pickle .dump (fig , StringIO (), pickle .HIGHEST_PROTOCOL )
102
+ pickle .dump (fig , BytesIO (), pickle .HIGHEST_PROTOCOL )
103
103
104
104
ax = plt .subplot (121 )
105
- pickle .dump (ax , StringIO (), pickle .HIGHEST_PROTOCOL )
105
+ pickle .dump (ax , BytesIO (), pickle .HIGHEST_PROTOCOL )
106
106
107
107
ax = plt .axes (projection = 'polar' )
108
108
plt .plot (range (10 ), label = 'foobar' )
109
109
plt .legend ()
110
110
111
111
# recursive_pickle(fig)
112
- pickle .dump (ax , StringIO (), pickle .HIGHEST_PROTOCOL )
112
+ pickle .dump (ax , BytesIO (), pickle .HIGHEST_PROTOCOL )
113
113
114
114
# ax = plt.subplot(121, projection='hammer')
115
115
# recursive_pickle(ax, 'figure')
116
- # pickle.dump(ax, StringIO (), pickle.HIGHEST_PROTOCOL)
116
+ # pickle.dump(ax, BytesIO (), pickle.HIGHEST_PROTOCOL)
117
117
118
118
119
119
@image_comparison (baseline_images = ['multi_pickle' ],
@@ -163,7 +163,7 @@ def test_complete():
163
163
# Uncomment to debug any unpicklable objects. This is slow (~200 seconds).
164
164
# recursive_pickle(fig)
165
165
166
- result_fh = StringIO ()
166
+ result_fh = BytesIO ()
167
167
pickle .dump (fig , result_fh , pickle .HIGHEST_PROTOCOL )
168
168
169
169
plt .close ('all' )
@@ -196,4 +196,4 @@ def test_no_pyplot():
196
196
# Uncomment to debug any unpicklable objects. This is slow so is not
197
197
# uncommented by default.
198
198
# recursive_pickle(fig)
199
- pickle .dump (fig , StringIO (), pickle .HIGHEST_PROTOCOL )
199
+ pickle .dump (fig , BytesIO (), pickle .HIGHEST_PROTOCOL )
0 commit comments