Merge pull request #438 from MITx/feature/ichuang/minor-py26-compat-fix-part2
{} -> {0} etc in .format statements
This commit is contained in:
@@ -15,7 +15,7 @@ def try_staticfiles_lookup(path):
|
||||
try:
|
||||
url = staticfiles_storage.url(path)
|
||||
except Exception as err:
|
||||
log.warning("staticfiles_storage couldn't find path {}: {}".format(
|
||||
log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
|
||||
path, str(err)))
|
||||
# Just return the original path; don't kill everything.
|
||||
url = path
|
||||
|
||||
@@ -187,11 +187,11 @@ class XMLModuleStore(ModuleStoreBase):
|
||||
if not os.path.exists(policy_path):
|
||||
return {}
|
||||
try:
|
||||
log.debug("Loading policy from {}".format(policy_path))
|
||||
log.debug("Loading policy from {0}".format(policy_path))
|
||||
with open(policy_path) as f:
|
||||
return json.load(f)
|
||||
except (IOError, ValueError) as err:
|
||||
msg = "Error loading course policy from {}".format(policy_path)
|
||||
msg = "Error loading course policy from {0}".format(policy_path)
|
||||
tracker(msg)
|
||||
log.warning(msg + " " + str(err))
|
||||
return {}
|
||||
@@ -238,7 +238,7 @@ class XMLModuleStore(ModuleStoreBase):
|
||||
|
||||
url_name = course_data.get('url_name')
|
||||
if url_name:
|
||||
policy_path = self.data_dir / course_dir / 'policies' / '{}.json'.format(url_name)
|
||||
policy_path = self.data_dir / course_dir / 'policies' / '{0}.json'.format(url_name)
|
||||
policy = self.load_policy(policy_path, tracker)
|
||||
else:
|
||||
policy = {}
|
||||
|
||||
@@ -201,7 +201,7 @@ class ImportTestCase(unittest.TestCase):
|
||||
|
||||
def check_for_key(key, node):
|
||||
"recursive check for presence of key"
|
||||
print "Checking {}".format(node.location.url())
|
||||
print "Checking {0}".format(node.location.url())
|
||||
self.assertTrue(key in node.metadata)
|
||||
for c in node.get_children():
|
||||
check_for_key(key, c)
|
||||
|
||||
@@ -629,7 +629,7 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
|
||||
try:
|
||||
return parse_time(self.metadata[key])
|
||||
except ValueError as e:
|
||||
msg = "Descriptor {} loaded with a bad metadata key '{}': '{}'".format(
|
||||
msg = "Descriptor {0} loaded with a bad metadata key '{1}': '{2}'".format(
|
||||
self.location.url(), self.metadata[key], e)
|
||||
log.warning(msg)
|
||||
return None
|
||||
|
||||
@@ -47,12 +47,12 @@ def cleanup(filepath, remove_meta):
|
||||
'ispublic', 'xqa_key')
|
||||
|
||||
try:
|
||||
print "Cleaning {}".format(filepath)
|
||||
print "Cleaning {0}".format(filepath)
|
||||
with open(filepath) as f:
|
||||
parser = etree.XMLParser(remove_comments=False)
|
||||
xml = etree.parse(filepath, parser=parser)
|
||||
except:
|
||||
print "Error parsing file {}".format(filepath)
|
||||
print "Error parsing file {0}".format(filepath)
|
||||
return
|
||||
|
||||
for node in xml.iter(tag=etree.Element):
|
||||
@@ -67,12 +67,12 @@ def cleanup(filepath, remove_meta):
|
||||
del attrs['name']
|
||||
|
||||
if 'url_name' in attrs and 'slug' in attrs:
|
||||
print "WARNING: {} has both slug and url_name"
|
||||
print "WARNING: {0} has both slug and url_name".format(node)
|
||||
|
||||
if ('url_name' in attrs and 'filename' in attrs and
|
||||
len(attrs)==2 and attrs['url_name'] == attrs['filename']):
|
||||
# This is a pointer tag in disguise. Get rid of the filename.
|
||||
print 'turning {}.{} into a pointer tag'.format(node.tag, attrs['url_name'])
|
||||
print 'turning {0}.{1} into a pointer tag'.format(node.tag, attrs['url_name'])
|
||||
del attrs['filename']
|
||||
|
||||
if remove_meta:
|
||||
|
||||
@@ -65,7 +65,7 @@ def has_access(user, obj, action):
|
||||
|
||||
# Passing an unknown object here is a coding error, so rather than
|
||||
# returning a default, complain.
|
||||
raise TypeError("Unknown object type in has_access(): '{}'"
|
||||
raise TypeError("Unknown object type in has_access(): '{0}'"
|
||||
.format(type(obj)))
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ def _dispatch(table, action, user, obj):
|
||||
action)
|
||||
return result
|
||||
|
||||
raise ValueError("Unknown action for object type '{}': '{}'".format(
|
||||
raise ValueError("Unknown action for object type '{0}': '{1}'".format(
|
||||
type(obj), action))
|
||||
|
||||
def _course_staff_group_name(location):
|
||||
|
||||
@@ -41,7 +41,7 @@ def import_course(course_dir, verbose=True):
|
||||
course = courses[0]
|
||||
errors = modulestore.get_item_errors(course.location)
|
||||
if len(errors) != 0:
|
||||
sys.stderr.write('ERRORs during import: {}\n'.format('\n'.join(map(str_of_err, errors))))
|
||||
sys.stderr.write('ERRORs during import: {0}\n'.format('\n'.join(map(str_of_err, errors))))
|
||||
|
||||
return course
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ def xqueue_callback(request, course_id, userid, id, dispatch):
|
||||
user, modulestore().get_item(id), depth=0, select_for_update=True)
|
||||
instance = get_module(user, request, id, student_module_cache)
|
||||
if instance is None:
|
||||
log.debug("No module {} for user {}--access denied?".format(id, user))
|
||||
log.debug("No module {0} for user {1}--access denied?".format(id, user))
|
||||
raise Http404
|
||||
|
||||
instance_module = get_instance_module(user, instance, student_module_cache)
|
||||
@@ -390,7 +390,7 @@ def modx_dispatch(request, dispatch=None, id=None, course_id=None):
|
||||
if instance is None:
|
||||
# Either permissions just changed, or someone is trying to be clever
|
||||
# and load something they shouldn't have access to.
|
||||
log.debug("No module {} for user {}--access denied?".format(id, user))
|
||||
log.debug("No module {0} for user {1}--access denied?".format(id, user))
|
||||
raise Http404
|
||||
|
||||
instance_module = get_instance_module(request.user, instance, student_module_cache)
|
||||
|
||||
@@ -177,7 +177,7 @@ class PageLoader(ActivateLoginTestCase):
|
||||
def try_enroll(self, course):
|
||||
"""Try to enroll. Return bool success instead of asserting it."""
|
||||
data = self._enroll(course)
|
||||
print 'Enrollment in {} result: {}'.format(course.location.url(), data)
|
||||
print 'Enrollment in {0} result: {1}'.format(course.location.url(), data)
|
||||
return data['success']
|
||||
|
||||
def enroll(self, course):
|
||||
@@ -309,7 +309,7 @@ class TestViewAuth(PageLoader):
|
||||
|
||||
# shouldn't be able to get to the instructor pages
|
||||
for url in instructor_urls(self.toy) + instructor_urls(self.full):
|
||||
print 'checking for 404 on {}'.format(url)
|
||||
print 'checking for 404 on {0}'.format(url)
|
||||
self.check_for_get_code(404, url)
|
||||
|
||||
# Make the instructor staff in the toy course
|
||||
@@ -322,11 +322,11 @@ class TestViewAuth(PageLoader):
|
||||
|
||||
# Now should be able to get to the toy course, but not the full course
|
||||
for url in instructor_urls(self.toy):
|
||||
print 'checking for 200 on {}'.format(url)
|
||||
print 'checking for 200 on {0}'.format(url)
|
||||
self.check_for_get_code(200, url)
|
||||
|
||||
for url in instructor_urls(self.full):
|
||||
print 'checking for 404 on {}'.format(url)
|
||||
print 'checking for 404 on {0}'.format(url)
|
||||
self.check_for_get_code(404, url)
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ class TestViewAuth(PageLoader):
|
||||
|
||||
# and now should be able to load both
|
||||
for url in instructor_urls(self.toy) + instructor_urls(self.full):
|
||||
print 'checking for 200 on {}'.format(url)
|
||||
print 'checking for 200 on {0}'.format(url)
|
||||
self.check_for_get_code(200, url)
|
||||
|
||||
|
||||
@@ -413,22 +413,22 @@ class TestViewAuth(PageLoader):
|
||||
|
||||
def check_non_staff(course):
|
||||
"""Check that access is right for non-staff in course"""
|
||||
print '=== Checking non-staff access for {}'.format(course.id)
|
||||
print '=== Checking non-staff access for {0}'.format(course.id)
|
||||
for url in instructor_urls(course) + dark_student_urls(course):
|
||||
print 'checking for 404 on {}'.format(url)
|
||||
print 'checking for 404 on {0}'.format(url)
|
||||
self.check_for_get_code(404, url)
|
||||
|
||||
for url in light_student_urls(course):
|
||||
print 'checking for 200 on {}'.format(url)
|
||||
print 'checking for 200 on {0}'.format(url)
|
||||
self.check_for_get_code(200, url)
|
||||
|
||||
def check_staff(course):
|
||||
"""Check that access is right for staff in course"""
|
||||
print '=== Checking staff access for {}'.format(course.id)
|
||||
print '=== Checking staff access for {0}'.format(course.id)
|
||||
for url in (instructor_urls(course) +
|
||||
dark_student_urls(course) +
|
||||
light_student_urls(course)):
|
||||
print 'checking for 200 on {}'.format(url)
|
||||
print 'checking for 200 on {0}'.format(url)
|
||||
self.check_for_get_code(200, url)
|
||||
|
||||
# First, try with an enrolled student
|
||||
|
||||
Reference in New Issue
Block a user