Replace StringIO with the faster version of cStringIO