Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _decode_exif_data(data):
try:
import exifread
except:
warnings.warn("EXIF data is ignored. Install exifread to decode.")
return data
fp = io.BytesIO(data)
tags = exifread.process_file(fp)
exif = {}
for key in tags.keys():
ifd = tags[key]
if isinstance(ifd, exifread.classes.IfdTag):
field_type = exifread.tags.FIELD_TYPES[ifd.field_type - 1]
if isinstance(ifd.printable, bytes):
try:
value = ifd.printable.decode('utf-8')
except UnicodeDecodeError:
value = ifd.printable.encode('string_escape')
else:
value = ifd.printable
if field_type[1] in ('A', 'B'):
exif[key] = value
else:
try:
exif[key] = int(value)
except ValueError:
exif[key] = value
else: