Files
edx-platform/lms/djangoapps/verify_student/image.py
Feanil Patel 9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00

38 lines
685 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
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