Skip to content

Commit

Permalink
Fix unicode errors in python2 (issue #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianare committed Feb 9, 2015
1 parent 6a5c977 commit 024016f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
==========

Development
* Represent the IFD as a string to fix formatting errors
* Represent the IFD as a string to fix formatting errors (issue #45)
* Fix unicode errors in python2 (issue #46)

2.0.0 — 2014-11-27
* Drop support for Python 2.5
Expand Down
13 changes: 11 additions & 2 deletions exifread/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ def dump_ifd(self, ifd, ifd_name, tag_dict=EXIF_TAGS, relative=0, stop_tag=DEFAU
elif count > 50 and len(values) > 20:
printable = str(values[0:20])[0:-1] + ", ... ]"
else:
printable = str(values)
try:
printable = str(values)
# fix for python2's handling of unicode values
except UnicodeEncodeError:
printable = unicode(values)

# compute printable version of values
if tag_entry:
Expand All @@ -252,7 +256,12 @@ def dump_ifd(self, ifd, ifd_name, tag_dict=EXIF_TAGS, relative=0, stop_tag=DEFAU
field_type,
values, field_offset,
count * type_length)
logger.debug(' %s %s: %s', ifd_name, tag_name, repr(self.tags[ifd_name][tag_name]))
try:
tag_value = repr(self.tags[ifd_name][tag_name])
# fix for python2's handling of unicode values
except UnicodeEncodeError:
tag_value = unicode(self.tags[ifd_name][tag_name])
logger.debug(' %s %s: %s', tag_name, tag_name, tag_value)

if tag_name == stop_tag:
break
Expand Down

0 comments on commit 024016f

Please sign in to comment.