INCR-170: Run python-modernize on common/lib [safe_lxml, sandbox-packages] (#20508)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Defuse vulnerabilities in XML packages.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
||||
def defuse_xml_libs():
|
||||
|
||||
@@ -11,6 +11,8 @@ For processing xml always prefer this over using lxml.etree directly.
|
||||
# lxml.etree. The names are not used here, so disable the pylint warning.
|
||||
# pylint: disable=unused-import, wildcard-import, unused-wildcard-import
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from lxml.etree import XMLParser as _XMLParser
|
||||
from lxml.etree import *
|
||||
from lxml.etree import _Element, _ElementTree
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Test that we have defused XML."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import defusedxml
|
||||
from lxml import etree
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Setup.py for safe_lxml.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ values in parameterized problems. For details, see:
|
||||
|
||||
http://en.wikipedia.org/wiki/Electronic_color_code
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
# r is standard name for a resistor. We would like to use it as such.
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
# Python functions which duplicate the standard comparison functions available to LON-CAPA problems.
|
||||
# Used in translating LON-CAPA problems to i4x problem specification language.
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import, division
|
||||
|
||||
import math
|
||||
import random
|
||||
from six.moves import range
|
||||
|
||||
|
||||
def lc_random(lower, upper, stepsize):
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
|
||||
@@ -23,8 +23,11 @@ or:
|
||||
}
|
||||
values are (x, y) coordinates of centers of dragged images.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
import six
|
||||
from six.moves import zip
|
||||
|
||||
|
||||
def flat_user_answer(user_answer):
|
||||
@@ -39,8 +42,8 @@ def flat_user_answer(user_answer):
|
||||
"""
|
||||
|
||||
def parse_user_answer(answer):
|
||||
key = answer.keys()[0]
|
||||
value = answer.values()[0]
|
||||
key = list(answer.keys())[0]
|
||||
value = list(answer.values())[0]
|
||||
if isinstance(value, dict):
|
||||
|
||||
# Make complex value:
|
||||
@@ -49,8 +52,8 @@ def flat_user_answer(user_answer):
|
||||
complex_value_list = []
|
||||
v_value = value
|
||||
while isinstance(v_value, dict):
|
||||
v_key = v_value.keys()[0]
|
||||
v_value = v_value.values()[0]
|
||||
v_key = list(v_value.keys())[0]
|
||||
v_value = list(v_value.values())[0]
|
||||
complex_value_list.append(v_key)
|
||||
|
||||
complex_value = '{0}'.format(v_value)
|
||||
@@ -101,8 +104,8 @@ class PositionsCompare(list):
|
||||
isinstance(other[0], (list, int, float))):
|
||||
return self.coordinate_positions_compare(other)
|
||||
|
||||
elif (isinstance(self[0], (unicode, str)) and
|
||||
isinstance(other[0], (unicode, str))):
|
||||
elif (isinstance(self[0], (six.text_type, str)) and
|
||||
isinstance(other[0], (six.text_type, str))):
|
||||
return ''.join(self) == ''.join(other)
|
||||
else: # improper argument types: no (float / int or lists of list
|
||||
#and float / int pair) or two string / unicode lists pair
|
||||
@@ -165,7 +168,7 @@ class DragAndDrop(object):
|
||||
# {'1': [u'2', u'2', u'2'], '0': [u'1', u'1'], '2': [u'3']}
|
||||
# if '+number' is in rule - do not remove duplicates and strip
|
||||
# '+number' from rule
|
||||
current_rule = self.correct_positions[index].keys()[0]
|
||||
current_rule = list(self.correct_positions[index].keys())[0]
|
||||
if 'number' in current_rule:
|
||||
rule_values = self.correct_positions[index][current_rule]
|
||||
# clean rule, do not do clean duplicate items
|
||||
@@ -353,7 +356,7 @@ class DragAndDrop(object):
|
||||
# correct_answer entry, the value is False.
|
||||
# default to consider every user answer excess until proven otherwise.
|
||||
self.excess_draggables = dict(
|
||||
(users_draggable.keys()[0], True)
|
||||
(list(users_draggable.keys())[0], True)
|
||||
for users_draggable in user_answer
|
||||
)
|
||||
|
||||
@@ -366,7 +369,7 @@ class DragAndDrop(object):
|
||||
user_positions_data = []
|
||||
for draggable_dict in user_answer:
|
||||
# Draggable_dict is 1-to-1 {draggable_name: position}.
|
||||
draggable_name = draggable_dict.keys()[0]
|
||||
draggable_name = list(draggable_dict.keys())[0]
|
||||
if draggable_name in answer['draggables']:
|
||||
user_groups_data.append(draggable_name)
|
||||
user_positions_data.append(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
import draganddrop
|
||||
from . import draganddrop
|
||||
|
||||
from .draganddrop import PositionsCompare
|
||||
|
||||
|
||||
Reference in New Issue
Block a user