Old style exceptions --> new style for Python 3

This commit is contained in:
cclauss
2019-01-17 15:42:05 +01:00
parent 9a5b2108b8
commit c0c935b685
24 changed files with 60 additions and 58 deletions

View File

@@ -56,7 +56,7 @@ class BasketsView(APIView):
try:
course_key = CourseKey.from_string(course_id)
courses.get_course(course_key)
except (InvalidKeyError, ValueError)as ex:
except (InvalidKeyError, ValueError) as ex:
log.exception(u'Unable to locate course matching %s.', course_id)
return False, None, text_type(ex)

View File

@@ -97,7 +97,7 @@ class CommandsTestBase(SharedModuleStoreTestCase):
try:
output = self.call_command('dump_course_structure', *args, **kwargs)
except TypeError, exception:
except TypeError as exception:
self.fail(exception)
dump = json.loads(output)

View File

@@ -285,7 +285,7 @@ def _add_timed_exam_info(user, course, section, section_context):
unicode(course.id),
unicode(section.location)
)
except Exception, ex: # pylint: disable=broad-except
except Exception as ex: # pylint: disable=broad-except
# safety net in case something blows up in edx_proctoring
# as this is just informational descriptions, it is better
# to log and continue (which is safe) than to have it be an

View File

@@ -489,7 +489,7 @@ class ProfileImageTestMixin(object):
Mixin with utility methods for user profile image
"""
TEST_PROFILE_IMAGE_UPLOADED_AT = datetime(2002, 1, 9, 15, 43, 01, tzinfo=UTC)
TEST_PROFILE_IMAGE_UPLOADED_AT = datetime(2002, 1, 9, 15, 43, 1, tzinfo=UTC)
def create_profile_image(self, user, storage):
"""

View File

@@ -770,9 +770,9 @@ def upload(request, course_id): # ajax upload file to a question or answer
max_file_size=cc_settings.MAX_UPLOAD_FILE_SIZE
)
except exceptions.PermissionDenied, err:
except exceptions.PermissionDenied as err:
error = unicode(err)
except Exception, err: # pylint: disable=broad-except
except Exception as err: # pylint: disable=broad-except
print(err)
logging.critical(unicode(err))
error = _('Error uploading file. Please contact the site administrator. Thank you.')

View File

@@ -671,13 +671,13 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u"quote": u"quote text1",
u"text": u"text1",
u"usage_id": unicode(self.html_module_1.location),
u"updated": datetime(2016, 01, 26, 8, 5, 16, 00000).isoformat(),
u"updated": datetime(2016, 1, 26, 8, 5, 16, 00000).isoformat(),
},
{
u"quote": u"quote text2",
u"text": u"text2",
u"usage_id": unicode(self.html_module_2.location),
u"updated": datetime(2016, 01, 26, 9, 6, 17, 00000).isoformat(),
u"updated": datetime(2016, 1, 26, 9, 6, 17, 00000).isoformat(),
},
]
@@ -695,7 +695,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u'text': u'text1',
u'quote': u'quote text1',
u'usage_id': unicode(self.html_module_1.location),
u'updated': datetime(2016, 01, 26, 8, 5, 16)
u'updated': datetime(2016, 1, 26, 8, 5, 16)
},
{
'section': {},
@@ -708,7 +708,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u'text': u'text2',
u'quote': u'quote text2',
u'usage_id': unicode(self.html_module_2.location),
u'updated': datetime(2016, 01, 26, 9, 6, 17)
u'updated': datetime(2016, 1, 26, 9, 6, 17)
}
],
helpers.preprocess_collection(self.user, self.course, initial_collection)

View File

@@ -48,7 +48,7 @@ def handle_dashboard_error(view):
"""
try:
return view(request, course_id=course_id)
except DashboardError, error:
except DashboardError as error:
return error.response()
return wrapper

View File

@@ -33,13 +33,13 @@ class TestAppVersionUpgradeMiddleware(CacheIsolationTestCase):
AppVersionConfig(
platform="iOS",
version="2.2.2",
expire_at=datetime(2014, 01, 01, tzinfo=UTC),
expire_at=datetime(2014, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(
platform="iOS",
version="4.4.4",
expire_at=datetime(9000, 01, 01, tzinfo=UTC),
expire_at=datetime(9000, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(platform="iOS", version="6.6.6", expire_at=None, enabled=True).save()
@@ -48,13 +48,13 @@ class TestAppVersionUpgradeMiddleware(CacheIsolationTestCase):
AppVersionConfig(
platform="Android",
version="2.2.2",
expire_at=datetime(2014, 01, 01, tzinfo=UTC),
expire_at=datetime(2014, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(
platform="Android",
version="4.4.4",
expire_at=datetime(5000, 01, 01, tzinfo=UTC),
expire_at=datetime(5000, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(platform="Android", version="8.8.8", expire_at=None, enabled=True).save()

View File

@@ -22,19 +22,19 @@ class TestAppVersionConfigModel(TestCase):
AppVersionConfig(
platform="ios",
version="2.2.2",
expire_at=datetime(2014, 01, 01, tzinfo=UTC),
expire_at=datetime(2014, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(
platform="ios",
version="4.1.1",
expire_at=datetime(5000, 01, 01, tzinfo=UTC),
expire_at=datetime(5000, 1, 1, tzinfo=UTC),
enabled=False
).save()
AppVersionConfig(
platform="ios",
version="4.4.4",
expire_at=datetime(9000, 01, 01, tzinfo=UTC),
expire_at=datetime(9000, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(platform="ios", version="6.6.6", expire_at=None, enabled=True).save()
@@ -44,13 +44,13 @@ class TestAppVersionConfigModel(TestCase):
AppVersionConfig(
platform="android",
version="2.2.2",
expire_at=datetime(2014, 01, 01, tzinfo=UTC),
expire_at=datetime(2014, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(
platform="android",
version="4.4.4",
expire_at=datetime(9000, 01, 01, tzinfo=UTC),
expire_at=datetime(9000, 1, 1, tzinfo=UTC),
enabled=True
).save()
AppVersionConfig(platform="android", version="8.8.8", expire_at=None, enabled=True).save()

View File

@@ -180,7 +180,7 @@ class PDFInvoice(object):
"""
try:
img = Image.open(img_path)
except IOError, ex:
except IOError as ex:
log.exception(u'Pdf unable to open the image file: %s', str(ex))
img = None