diff --git a/puppet/zulip_internal/files/trac/cgi-bin/trac.fcgi b/puppet/zulip_internal/files/trac/cgi-bin/trac.fcgi index 627f5cdf3a..ad01b1ce40 100644 --- a/puppet/zulip_internal/files/trac/cgi-bin/trac.fcgi +++ b/puppet/zulip_internal/files/trac/cgi-bin/trac.fcgi @@ -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() diff --git a/tools/deprecated/review b/tools/deprecated/review index 6597522e44..30630af595 100755 --- a/tools/deprecated/review +++ b/tools/deprecated/review @@ -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 diff --git a/tools/travis/py3k b/tools/travis/py3k index 6a78639b5e..547c5fcb5c 100755 --- a/tools/travis/py3k +++ b/tools/travis/py3k @@ -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!" diff --git a/zerver/decorator.py b/zerver/decorator.py index 37edebc34d..fab81a0236 100644 --- a/zerver/decorator.py +++ b/zerver/decorator.py @@ -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 diff --git a/zerver/lib/upload.py b/zerver/lib/upload.py index def4b981b5..b45fb4d402 100644 --- a/zerver/lib/upload.py +++ b/zerver/lib/upload.py @@ -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: diff --git a/zerver/test_external.py b/zerver/test_external.py index 9b991af026..bc9d9bfb30 100644 --- a/zerver/test_external.py +++ b/zerver/test_external.py @@ -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): diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index f9ca5bf69c..3f077084f9 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -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,