Guard the string lookups better.

This commit is contained in:
Jason A. Donenfeld 2011-05-09 18:08:07 -04:00
parent ddba74b57c
commit fb01d666b8

View File

@ -152,6 +152,7 @@ class Photo(object):
self._orientation = exif["Orientation"]; self._orientation = exif["Orientation"];
if self._orientation in range(5, 9): if self._orientation in range(5, 9):
self._attributes["size"] = (self._attributes["size"][1], self._attributes["size"][0]) self._attributes["size"] = (self._attributes["size"][1], self._attributes["size"][0])
if self._orientation - 1 < len(self._metadata.orientation_list):
self._attributes["orientation"] = self._metadata.orientation_list[self._orientation - 1] self._attributes["orientation"] = self._metadata.orientation_list[self._orientation - 1]
if "Make" in exif: if "Make" in exif:
self._attributes["make"] = exif["Make"] self._attributes["make"] = exif["Make"]
@ -171,21 +172,16 @@ class Photo(object):
self._attributes["iso"] = exif["PhotographicSensitivity"] self._attributes["iso"] = exif["PhotographicSensitivity"]
if "ExposureTime" in exif: if "ExposureTime" in exif:
self._attributes["exposureTime"] = exif["ExposureTime"] self._attributes["exposureTime"] = exif["ExposureTime"]
if "MeteringMode" in exif: if "Flash" in exif and exif["Flash"] in self._metadata.flash_dictionary:
self._attributes["meteringMode"] = exif["MeteringMode"]
if "Flash" in exif:
try: try:
self._attributes["flash"] = self._metadata.flash_dictionary[exif["Flash"]] self._attributes["flash"] = self._metadata.flash_dictionary[exif["Flash"]]
except: except:
pass pass
if "ExposureProgram" in exif: if "ExposureProgram" in exif and exif["ExposureProgram"] < len(self._metadata.exposure_list):
self._attributes["exposureProgram"] = self._metadata.exposure_list[exif["ExposureProgram"]] self._attributes["exposureProgram"] = self._metadata.exposure_list[exif["ExposureProgram"]]
if "SpectralSensitivity" in exif: if "SpectralSensitivity" in exif:
self._attributes["spectralSensitivity"] = exif["SpectralSensitivity"] self._attributes["spectralSensitivity"] = exif["SpectralSensitivity"]
if "MeteringMode" in exif: if "MeteringMode" in exif and exif["MeteringMode"] < len(self._metadata.metering_list):
if exif["MeteringMode"] == 255:
self._attributes["meteringMode"] = "Other"
else:
self._attributes["meteringMode"] = self._metadata.metering_list[exif["MeteringMode"]] self._attributes["meteringMode"] = self._metadata.metering_list[exif["MeteringMode"]]
if "ExposureCompensation" in exif: if "ExposureCompensation" in exif:
self._attributes["exposureCompensation"] = exif["ExposureCompensation"] self._attributes["exposureCompensation"] = exif["ExposureCompensation"]