replaced StringIO imports with import from six
replaced cStringIO and StringIO imports with import from six fixed StringIO imports fixed StringIO imports fixed XSS python-wrap warning
This commit is contained in:
@@ -3,7 +3,7 @@ Unittests for creating a course in an chosen modulestore
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
import ddt
|
||||
import six
|
||||
|
||||
@@ -7,7 +7,7 @@ from __future__ import absolute_import
|
||||
import shutil
|
||||
import tarfile
|
||||
import unittest
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
from tempfile import mkdtemp
|
||||
|
||||
import ddt
|
||||
|
||||
@@ -7,7 +7,7 @@ from __future__ import absolute_import
|
||||
import copy
|
||||
import os
|
||||
import shutil
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import subprocess
|
||||
import unittest
|
||||
from uuid import uuid4
|
||||
@@ -60,18 +60,18 @@ class TestGitExport(CourseTestCase):
|
||||
test output.
|
||||
"""
|
||||
with self.assertRaisesRegexp(CommandError, 'Error: unrecognized arguments:*'):
|
||||
call_command('git_export', 'blah', 'blah', 'blah', stderr=StringIO.StringIO())
|
||||
call_command('git_export', 'blah', 'blah', 'blah', stderr=StringIO())
|
||||
|
||||
with self.assertRaisesMessage(CommandError, 'Error: too few arguments'):
|
||||
call_command('git_export', stderr=StringIO.StringIO())
|
||||
call_command('git_export', stderr=StringIO())
|
||||
|
||||
# Send bad url to get course not exported
|
||||
with self.assertRaisesRegexp(CommandError, six.text_type(GitExportError.URL_BAD)):
|
||||
call_command('git_export', 'foo/bar/baz', 'silly', stderr=StringIO.StringIO())
|
||||
call_command('git_export', 'foo/bar/baz', 'silly', stderr=StringIO())
|
||||
|
||||
# Send bad course_id to get course not exported
|
||||
with self.assertRaisesRegexp(CommandError, six.text_type(GitExportError.BAD_COURSE)):
|
||||
call_command('git_export', 'foo/bar:baz', 'silly', stderr=StringIO.StringIO())
|
||||
call_command('git_export', 'foo/bar:baz', 'silly', stderr=StringIO())
|
||||
|
||||
def test_error_output(self):
|
||||
"""
|
||||
|
||||
@@ -9,7 +9,7 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import tarfile
|
||||
import tempfile
|
||||
from uuid import uuid4
|
||||
@@ -574,7 +574,7 @@ class ExportTestCase(CourseTestCase):
|
||||
resp = self.client.get(output_url)
|
||||
self._verify_export_succeeded(resp)
|
||||
|
||||
buff = StringIO.StringIO(b"".join(resp.streaming_content))
|
||||
buff = StringIO("".join(resp.streaming_content))
|
||||
return tarfile.open(fileobj=buff)
|
||||
|
||||
def _verify_export_succeeded(self, resp):
|
||||
|
||||
@@ -10,6 +10,7 @@ import re
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime
|
||||
from functools import wraps
|
||||
from six import StringIO
|
||||
|
||||
import dateutil.parser
|
||||
import ddt
|
||||
@@ -1416,7 +1417,7 @@ class VideoUrlsCsvTestCase(VideoUploadTestMixin, CourseTestCase):
|
||||
response["Content-Disposition"],
|
||||
u"attachment; filename={course}_video_urls.csv".format(course=self.course.id.course)
|
||||
)
|
||||
response_reader = six.StringIO(response.content)
|
||||
response_reader = StringIO(response.content)
|
||||
reader = csv.DictReader(response_reader, dialect=csv.excel)
|
||||
self.assertEqual(
|
||||
reader.fieldnames,
|
||||
|
||||
@@ -6,7 +6,7 @@ from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
import ddt
|
||||
import six
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import re
|
||||
from cStringIO import StringIO
|
||||
from six import StringIO
|
||||
from six.moves.urllib.parse import parse_qsl, urlparse, urlunparse
|
||||
|
||||
import ddt
|
||||
@@ -192,7 +192,9 @@ def test_static_paths_out(mock_modulestore, mock_storage):
|
||||
static_course_url = '/c4x/org/course/asset/LAlec04_controller.swf?csConfigFile=%2Fc4x%2Forg%2Fcourse%2Fasset%2FLAlec04_config.xml&name1=value1&name2=value2'
|
||||
raw_url = '/static/js/capa/protex/protex.nocache.js?raw'
|
||||
xblock_url = '/static/xblock/resources/babys_first.lil_xblock/public/images/pacifier.png'
|
||||
# xss-lint: disable=python-wrap-html
|
||||
pre_text = 'EMBED src ="{}" xblock={} text <tag a="{}"/><div class="'.format(static_url, xblock_url, raw_url)
|
||||
# xss-lint: disable=python-wrap-html
|
||||
post_text = 'EMBED src ="{}" xblock={} text <tag a="{}"/><div class="'.format(static_course_url, xblock_url, raw_url)
|
||||
static_paths = []
|
||||
assert replace_static_urls(pre_text, DATA_DIRECTORY, COURSE_KEY, static_paths_out=static_paths) == post_text
|
||||
|
||||
@@ -6,7 +6,7 @@ from __future__ import absolute_import
|
||||
import sys
|
||||
import unittest
|
||||
from contextlib import contextmanager
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
from uuid import uuid4
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
|
||||
@@ -11,7 +11,7 @@ import random
|
||||
import textwrap
|
||||
import unittest
|
||||
import zipfile
|
||||
from cStringIO import StringIO
|
||||
from six import StringIO
|
||||
from datetime import datetime
|
||||
|
||||
import mock
|
||||
|
||||
@@ -9,7 +9,7 @@ import functools
|
||||
import json
|
||||
import logging
|
||||
from copy import deepcopy
|
||||
from cStringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
import pytz
|
||||
import six
|
||||
|
||||
@@ -7,7 +7,7 @@ Tests for Django management commands
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
import factory
|
||||
import six
|
||||
|
||||
@@ -8,7 +8,7 @@ from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import subprocess
|
||||
|
||||
import mongoengine
|
||||
@@ -261,7 +261,7 @@ def add_repo(repo, rdir_in, branch=None):
|
||||
ret_git += u'{0}Branch: {1}'.format(' \n', branch)
|
||||
|
||||
# Get XML logging logger and capture debug to parse results
|
||||
output = StringIO.StringIO()
|
||||
output = StringIO()
|
||||
import_log_handler = logging.StreamHandler(output)
|
||||
import_log_handler.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import subprocess
|
||||
import unittest
|
||||
from uuid import uuid4
|
||||
@@ -66,7 +66,7 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
|
||||
Convenience function for testing command failures
|
||||
"""
|
||||
with self.assertRaisesRegexp(CommandError, regex):
|
||||
call_command('git_add_course', *args, stderr=StringIO.StringIO())
|
||||
call_command('git_add_course', *args, stderr=StringIO())
|
||||
|
||||
def test_command_args(self):
|
||||
"""
|
||||
@@ -203,7 +203,7 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
|
||||
git_import.add_repo('file://{0}'.format(bare_repo), None, None)
|
||||
|
||||
# Get logger for checking strings in logs
|
||||
output = StringIO.StringIO()
|
||||
output = StringIO()
|
||||
test_log_handler = logging.StreamHandler(output)
|
||||
test_log_handler.setLevel(logging.DEBUG)
|
||||
glog = git_import.log
|
||||
|
||||
@@ -7,7 +7,7 @@ from __future__ import absolute_import
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import subprocess
|
||||
|
||||
import mongoengine
|
||||
@@ -78,7 +78,7 @@ class SysadminDashboardView(TemplateView):
|
||||
data should be iterable and is used to stream object over http
|
||||
"""
|
||||
|
||||
csv_file = StringIO.StringIO()
|
||||
csv_file = StringIO()
|
||||
writer = csv.writer(csv_file, dialect='excel', quotechar='"',
|
||||
quoting=csv.QUOTE_ALL)
|
||||
|
||||
@@ -293,7 +293,7 @@ class Courses(SysadminDashboardView):
|
||||
log.debug(u'Adding course using git repo %s', gitloc)
|
||||
|
||||
# Grab logging output for debugging imports
|
||||
output = StringIO.StringIO()
|
||||
output = StringIO()
|
||||
import_log_handler = logging.StreamHandler(output)
|
||||
import_log_handler.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import logging
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import time
|
||||
|
||||
import six
|
||||
@@ -1842,7 +1842,7 @@ def generate_registration_codes(request, course_id):
|
||||
invoice_attachment = render_to_string('emails/registration_codes_sale_invoice_attachment.txt', context)
|
||||
|
||||
#send_mail(subject, message, from_address, recipient_list, fail_silently=False)
|
||||
csv_file = StringIO.StringIO()
|
||||
csv_file = StringIO()
|
||||
csv_writer = csv.writer(csv_file)
|
||||
for registration_code in registration_codes:
|
||||
full_redeem_code_url = 'http://{base_url}{redeem_code_url}'.format(
|
||||
@@ -1867,7 +1867,7 @@ def generate_registration_codes(request, course_id):
|
||||
if pdf_file is not None:
|
||||
email.attach(u'Invoice.pdf', pdf_file.getvalue(), 'application/pdf')
|
||||
else:
|
||||
file_buffer = StringIO.StringIO(_('pdf download unavailable right now, please contact support.'))
|
||||
file_buffer = StringIO(_('pdf download unavailable right now, please contact support.'))
|
||||
email.attach(u'pdf_unavailable.txt', file_buffer.getvalue(), 'text/plain')
|
||||
email.send()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
from time import time
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import absolute_import
|
||||
|
||||
import copy
|
||||
import time
|
||||
from cStringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
import boto
|
||||
from django.conf import settings
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
from uuid import uuid4
|
||||
|
||||
from django.core.management import call_command
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests for the Shopping Cart Models
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
from textwrap import dedent
|
||||
|
||||
import pytz
|
||||
@@ -139,7 +139,7 @@ class ReportTypeTests(ModuleStoreTestCase):
|
||||
Tests that a generated purchase report CSV is as we expect
|
||||
"""
|
||||
report = initialize_report("refund_report", self.now - self.FIVE_MINS, self.now + self.FIVE_MINS)
|
||||
csv_file = StringIO.StringIO()
|
||||
csv_file = StringIO()
|
||||
report.write_csv(csv_file)
|
||||
csv = csv_file.getvalue()
|
||||
csv_file.close()
|
||||
@@ -148,14 +148,14 @@ class ReportTypeTests(ModuleStoreTestCase):
|
||||
|
||||
def test_basic_cert_status_csv(self):
|
||||
report = initialize_report("certificate_status", self.now - self.FIVE_MINS, self.now + self.FIVE_MINS, 'A', 'Z')
|
||||
csv_file = StringIO.StringIO()
|
||||
csv_file = StringIO()
|
||||
report.write_csv(csv_file)
|
||||
csv = csv_file.getvalue()
|
||||
self.assertEqual(csv.replace('\r\n', '\n').strip(), self.CORRECT_CERT_STATUS_CSV.strip())
|
||||
|
||||
def test_basic_uni_revenue_share_csv(self):
|
||||
report = initialize_report("university_revenue_share", self.now - self.FIVE_MINS, self.now + self.FIVE_MINS, 'A', 'Z')
|
||||
csv_file = StringIO.StringIO()
|
||||
csv_file = StringIO()
|
||||
report.write_csv(csv_file)
|
||||
csv = csv_file.getvalue()
|
||||
self.assertEqual(csv.replace('\r\n', '\n').strip(), self.CORRECT_UNI_REVENUE_SHARE_CSV.strip())
|
||||
@@ -227,7 +227,7 @@ class ItemizedPurchaseReportTest(ModuleStoreTestCase):
|
||||
Tests that a generated purchase report CSV is as we expect
|
||||
"""
|
||||
report = initialize_report("itemized_purchase_report", self.now - self.FIVE_MINS, self.now + self.FIVE_MINS)
|
||||
csv_file = StringIO.StringIO()
|
||||
csv_file = StringIO()
|
||||
report.write_csv(csv_file)
|
||||
csv = csv_file.getvalue()
|
||||
csv_file.close()
|
||||
|
||||
@@ -6,7 +6,7 @@ from __future__ import absolute_import
|
||||
import datetime
|
||||
import itertools
|
||||
import math
|
||||
from cStringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
|
||||
@@ -8,7 +8,7 @@ import os
|
||||
import sys
|
||||
import tempfile
|
||||
from contextlib import contextmanager
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
|
||||
import ddt
|
||||
import yaml
|
||||
|
||||
@@ -7,7 +7,7 @@ from __future__ import absolute_import
|
||||
|
||||
import itertools
|
||||
import json
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import unittest
|
||||
from copy import deepcopy
|
||||
|
||||
@@ -650,11 +650,11 @@ class TestRecommenderFileUploading(TestRecommender):
|
||||
happens or is rejected as expected.
|
||||
"""
|
||||
if 'magic_number' in test_case:
|
||||
f_handler = StringIO.StringIO(test_case['magic_number'].decode('hex'))
|
||||
f_handler = StringIO(test_case['magic_number'].decode('hex'))
|
||||
elif content is not None:
|
||||
f_handler = StringIO.StringIO(json.dumps(content, sort_keys=True))
|
||||
f_handler = StringIO(json.dumps(content, sort_keys=True))
|
||||
else:
|
||||
f_handler = StringIO.StringIO('')
|
||||
f_handler = StringIO('')
|
||||
|
||||
f_handler.content_type = test_case['mimetypes']
|
||||
f_handler.name = 'file' + test_case['suffixes']
|
||||
|
||||
@@ -429,7 +429,7 @@ class XBlockTestCase(XBlockStudentTestCaseMixin,
|
||||
usage_id = self.xblocks[block_urlname].scope_ids.usage_id
|
||||
encoded_id = usage_id.replace(";_", "/")
|
||||
Followed by:
|
||||
page_xml = defusedxml.ElementTree.parse(StringIO.StringIO(response_content))
|
||||
page_xml = defusedxml.ElementTree.parse(StringIO(response_content))
|
||||
page_xml.find("//[@data-usage-id={usage}]".format(usage=encoded_id))
|
||||
or
|
||||
soup_html = BeautifulSoup(response_content, 'html.parser')
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests for main.py
|
||||
from __future__ import absolute_import
|
||||
|
||||
import re
|
||||
from StringIO import StringIO
|
||||
from six import StringIO
|
||||
from unittest import TestCase
|
||||
|
||||
import mock
|
||||
|
||||
Reference in New Issue
Block a user