Migrate use of StringIO to Python 2+3 compatible six.moves.cStringIO.

And add a check for additional usage of the original StringIO module.
This commit is contained in:
Tim Abbott 2016-01-23 19:22:35 -08:00
parent 1f44417fc1
commit 757e89260e
7 changed files with 15 additions and 8 deletions

View File

@ -41,7 +41,7 @@ except Exception, e:
print e
print
import traceback
import StringIO
tb = StringIO.StringIO()
from six.moves import cStringIO as StringIO
tb = StringIO()
traceback.print_exc(file=tb)
print tb.getvalue()

View File

@ -42,7 +42,7 @@ import git
import shlex
import codecs
import fcntl
from StringIO import StringIO
from six.moves import cStringIO as StringIO
from email.message import Message
from email.header import Header
from shutil import rmtree, copyfile, copytree

View File

@ -56,6 +56,13 @@ for fixer in $fixers; do
fi
done
if git grep -q '\(^\W*import StringIO\|^\W*from StringIO\)'; then
echo "ERROR: StringIO imports not compatible with python 2+3:"
git grep '\(^\W*import StringIO\|^\W*from StringIO\)'
echo "Please use 'from six.moves import cStringIO as StringIO'"
failed=1
fi
echo
if [ -z "$failed" ]; then
echo "No issues detected!"

View File

@ -10,7 +10,7 @@ from zerver.lib.response import json_error, json_unauthorized
from django.utils.timezone import now
from django.conf import settings
import ujson
from StringIO import StringIO
from six.moves import cStringIO as StringIO
from zerver.lib.queue import queue_json_publish
from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.utils import statsd

View File

@ -14,7 +14,7 @@ from zerver.models import get_user_profile_by_id
import base64
import os
from PIL import Image, ImageOps
from StringIO import StringIO
from six.moves import cStringIO as StringIO
import random
# Performance Note:

View File

@ -24,7 +24,7 @@ from six.moves import urllib
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from StringIO import StringIO
from six.moves import StringIO
from six.moves import range
class MITNameTest(TestCase):

View File

@ -32,7 +32,7 @@ import time
import datetime
import logging
import simplejson
import StringIO
from six.moves import cStringIO as StringIO
def assign_queue(queue_name, enabled=True):
def decorate(clazz):
@ -283,7 +283,7 @@ class MessageSenderWorker(QueueProcessingWorker):
'SERVER_PORT': 9993,
'SERVER_PROTOCOL': 'ZULIP_SOCKET/1.0',
'wsgi.version': (1, 0),
'wsgi.input': StringIO.StringIO(),
'wsgi.input': StringIO(),
'wsgi.errors': sys.stderr,
'wsgi.multithread': False,
'wsgi.multiprocess': True,