Merge pull request #21075 from edx/INCR-410
INCR-410 Python 3 compatibility
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
# -----------------------------------------------------------------------------
|
||||
# class used to store graded responses to CAPA questions
|
||||
#
|
||||
# Used by responsetypes and capa_problem
|
||||
@@ -22,6 +22,7 @@ class CorrectMap(object):
|
||||
|
||||
Behaves as a dict.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# start with empty dict
|
||||
self.cmap = dict()
|
||||
@@ -46,7 +47,7 @@ class CorrectMap(object):
|
||||
hint='',
|
||||
hintmode=None,
|
||||
queuestate=None,
|
||||
answervariable=None, # pylint: disable=C0330
|
||||
answervariable=None, # pylint: disable=C0330
|
||||
**kwargs
|
||||
):
|
||||
|
||||
@@ -95,7 +96,7 @@ class CorrectMap(object):
|
||||
return
|
||||
|
||||
# create new dict entries
|
||||
if not isinstance(correct_map.values()[0], dict):
|
||||
if not isinstance(list(correct_map.values())[0], dict):
|
||||
# special migration
|
||||
for k in correct_map:
|
||||
self.set(k, correctness=correct_map[k])
|
||||
|
||||
@@ -6,6 +6,8 @@ These tags do not have state, so they just get passed the system (for access to
|
||||
and the xml element.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import re
|
||||
import xml.sax.saxutils as saxutils
|
||||
@@ -19,7 +21,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
registry = TagRegistry()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MathRenderer(object):
|
||||
@@ -54,16 +57,19 @@ class MathRenderer(object):
|
||||
Return the contents of this tag, rendered to html, as an etree element.
|
||||
"""
|
||||
# TODO: why are there nested html tags here?? Why are there html tags at all, in fact?
|
||||
# xss-lint: disable=python-interpolate-html
|
||||
html = '<html><html>%s</html><html>%s</html></html>' % (
|
||||
self.mathstr, saxutils.escape(self.xml.tail))
|
||||
try:
|
||||
xhtml = etree.XML(html)
|
||||
except Exception as err:
|
||||
if self.system.DEBUG:
|
||||
# xss-lint: disable=python-interpolate-html
|
||||
msg = '<html><div class="inline-error"><p>Error %s</p>' % (
|
||||
str(err).replace('<', '<'))
|
||||
str(err).replace('<', '<')) # xss-lint: disable=python-custom-escape
|
||||
# xss-lint: disable=python-interpolate-html
|
||||
msg += ('<p>Failed to construct math expression from <pre>%s</pre></p>' %
|
||||
html.replace('<', '<'))
|
||||
html.replace('<', '<')) # xss-lint: disable=python-custom-escape
|
||||
msg += "</div></html>"
|
||||
log.error(msg)
|
||||
return etree.XML(msg)
|
||||
@@ -74,7 +80,8 @@ class MathRenderer(object):
|
||||
|
||||
registry.register(MathRenderer)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
class SolutionRenderer(object):
|
||||
@@ -96,9 +103,11 @@ class SolutionRenderer(object):
|
||||
html = self.system.render_template("solutionspan.html", context)
|
||||
return etree.XML(html)
|
||||
|
||||
|
||||
registry.register(SolutionRenderer)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TargetedFeedbackRenderer(object):
|
||||
@@ -116,11 +125,14 @@ class TargetedFeedbackRenderer(object):
|
||||
"""
|
||||
Return the contents of this tag, rendered to html, as an etree element.
|
||||
"""
|
||||
# xss-lint: disable=python-wrap-html
|
||||
html = '<section class="targeted-feedback-span"><span>{}</span></section>'.format(etree.tostring(self.xml))
|
||||
try:
|
||||
xhtml = etree.XML(html)
|
||||
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
if self.system.DEBUG:
|
||||
# xss-lint: disable=python-wrap-html
|
||||
msg = """
|
||||
<html>
|
||||
<div class="inline-error">
|
||||
@@ -135,9 +147,11 @@ class TargetedFeedbackRenderer(object):
|
||||
raise
|
||||
return xhtml
|
||||
|
||||
|
||||
registry.register(TargetedFeedbackRenderer)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
class ClarificationRenderer(object):
|
||||
@@ -167,4 +181,5 @@ class ClarificationRenderer(object):
|
||||
xml.tail = self.tail
|
||||
return xml
|
||||
|
||||
|
||||
registry.register(ClarificationRenderer)
|
||||
|
||||
@@ -11,10 +11,10 @@ import unittest
|
||||
|
||||
import pytest
|
||||
import six
|
||||
from six import text_type, unichr
|
||||
from six.moves import range
|
||||
from codejail.jail_code import is_configured
|
||||
from codejail.safe_exec import SafeExecException
|
||||
from six import text_type, unichr
|
||||
from six.moves import range
|
||||
|
||||
from capa.safe_exec import safe_exec, update_hash
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#
|
||||
# LMS Interface to external queueing system (xqueue)
|
||||
#
|
||||
from __future__ import absolute_import
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
dateformat = '%Y%m%d%H%M%S'
|
||||
@@ -70,7 +72,7 @@ class XQueueInterface(object):
|
||||
"""
|
||||
|
||||
def __init__(self, url, django_auth, requests_auth=None):
|
||||
self.url = unicode(url)
|
||||
self.url = six.text_type(url)
|
||||
self.auth = django_auth
|
||||
self.session = requests.Session()
|
||||
self.session.auth = requests_auth
|
||||
@@ -111,7 +113,7 @@ class XQueueInterface(object):
|
||||
f.seek(0)
|
||||
(error, msg) = self._send_to_queue(header, body, files_to_upload)
|
||||
|
||||
return (error, msg)
|
||||
return error, msg
|
||||
|
||||
def _login(self):
|
||||
payload = {
|
||||
@@ -139,13 +141,13 @@ class XQueueInterface(object):
|
||||
)
|
||||
except requests.exceptions.ConnectionError as err:
|
||||
log.error(err)
|
||||
return (1, 'cannot connect to server')
|
||||
return 1, 'cannot connect to server'
|
||||
|
||||
except requests.exceptions.ReadTimeout as err:
|
||||
log.error(err)
|
||||
return (1, 'failed to read from the server')
|
||||
return 1, 'failed to read from the server'
|
||||
|
||||
if response.status_code not in [200]:
|
||||
return (1, 'unexpected HTTP status code [%d]' % response.status_code)
|
||||
return 1, 'unexpected HTTP status code [%d]' % response.status_code
|
||||
|
||||
return parse_xreply(response.text)
|
||||
|
||||
Reference in New Issue
Block a user