Files
edx-platform/lms/djangoapps/verify_student/image.py
M. Zulqarnain feaf5011c8 BOM-2287 : Pylint amnesty in teams,tests,survey and verify_student (#26305)
* lint amnesty in teams,tests,survey and verify_student
2021-02-03 18:15:03 +05:00

38 lines
787 B
Python

"""
Image encoding helpers for the verification app.
"""
import base64
import logging
log = logging.getLogger(__name__)
class InvalidImageData(Exception):
"""
The provided image data could not be decoded.
"""
pass # lint-amnesty, pylint: disable=unnecessary-pass
def decode_image_data(data):
"""
Decode base64-encoded image data.
Arguments:
data (str): The raw image data, base64-encoded.
Returns:
str
Raises:
InvalidImageData: The image data could not be decoded.
"""
try:
return base64.b64decode(data.split(",")[1])
except (IndexError, UnicodeEncodeError):
log.exception("Could not decode image data")
raise InvalidImageData # lint-amnesty, pylint: disable=raise-missing-from