Python unicode is awful

This commit is contained in:
Jason A. Donenfeld 2015-01-19 13:08:45 +01:00
parent 2b8918dd7c
commit 7d2528280b

View File

@ -145,9 +145,9 @@ class Photo(object):
exif = {} exif = {}
for tag, value in info.items(): for tag, value in info.items():
decoded = TAGS.get(tag, tag) decoded = TAGS.get(tag, tag)
if isinstance(value, str): if isinstance(value, str) or isinstance(value, unicode):
value = value.strip().partition("\x00")[0] value = value.strip().partition("\x00")[0]
if isinstance(decoded, str) and decoded.startswith("DateTime"): if (isinstance(decoded, str) or isinstance(value, unicode)) and decoded.startswith("DateTime"):
try: try:
value = datetime.strptime(value, '%Y:%m:%d %H:%M:%S') value = datetime.strptime(value, '%Y:%m:%d %H:%M:%S')
except KeyboardInterrupt: except KeyboardInterrupt:
@ -315,8 +315,6 @@ class Photo(object):
correct_date = self._attributes["dateTime"] correct_date = self._attributes["dateTime"]
else: else:
correct_date = self._attributes["dateTimeFile"] correct_date = self._attributes["dateTimeFile"]
if isinstance(correct_date, unicode):
correct_date = datetime.strptime(correct_date, '%Y:%m:%d %H:%M:%S')
return correct_date return correct_date
def __cmp__(self, other): def __cmp__(self, other):