From 6e3eff304e956442d18283784b70b1ac4c604bec Mon Sep 17 00:00:00 2001 From: ichuang Date: Thu, 16 Aug 2012 16:22:26 -0400 Subject: [PATCH] {} -> {0} etc in .format statements --- common/djangoapps/static_replace.py | 2 +- common/lib/xmodule/xmodule/modulestore/xml.py | 6 +++--- .../lib/xmodule/xmodule/tests/test_import.py | 2 +- common/lib/xmodule/xmodule/x_module.py | 2 +- common/xml_cleanup.py | 8 ++++---- lms/djangoapps/courseware/access.py | 4 ++-- .../management/commands/metadata_to_json.py | 2 +- lms/djangoapps/courseware/module_render.py | 4 ++-- lms/djangoapps/courseware/tests/tests.py | 20 +++++++++---------- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/common/djangoapps/static_replace.py b/common/djangoapps/static_replace.py index ce3dc55031..58e2c8da15 100644 --- a/common/djangoapps/static_replace.py +++ b/common/djangoapps/static_replace.py @@ -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 diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index 971124e413..a77266113f 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -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 = {} diff --git a/common/lib/xmodule/xmodule/tests/test_import.py b/common/lib/xmodule/xmodule/tests/test_import.py index dfa75f9137..2061b63fb6 100644 --- a/common/lib/xmodule/xmodule/tests/test_import.py +++ b/common/lib/xmodule/xmodule/tests/test_import.py @@ -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) diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index d4d61f4aa1..c581911c03 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -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 diff --git a/common/xml_cleanup.py b/common/xml_cleanup.py index 8e794b97c2..15890fb99e 100755 --- a/common/xml_cleanup.py +++ b/common/xml_cleanup.py @@ -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: diff --git a/lms/djangoapps/courseware/access.py b/lms/djangoapps/courseware/access.py index e588f807da..eaf70d7814 100644 --- a/lms/djangoapps/courseware/access.py +++ b/lms/djangoapps/courseware/access.py @@ -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): diff --git a/lms/djangoapps/courseware/management/commands/metadata_to_json.py b/lms/djangoapps/courseware/management/commands/metadata_to_json.py index 0f48e93319..dcbcdc0df3 100644 --- a/lms/djangoapps/courseware/management/commands/metadata_to_json.py +++ b/lms/djangoapps/courseware/management/commands/metadata_to_json.py @@ -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 diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 9a6ba8c323..558f6deeb2 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -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) diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index 9682040b36..22a65267c9 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -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