Add utils to print/display binary maker notes and other EXIF Undefined tags

Bug #959908 reported by Hobson Lane
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyexiv2
In Progress
Wishlist
Hobson Lane

Bug Description

Per discussion of Bug #942595 it would be nice to be able to display EXIF "Undefined" strings without garbling a terminal with control codes or ValueError faulting on non-ascii characters, e.g. ord()>128

Ideally, the following code should display human-readable text,

 exif = im.exif_keys
 for k in im.exif_keys:
  print "{0}: {1}".format(k,str(im[k].value))
 print '------------- Comment -------------------'
 print im.comment
 print '-----------------------------------------------'

However, these new utils methods won't help unless they are incorporated into the python string output interface for exif tag classes ( ExifTag.convert_to_python() ).

Related branches

Revision history for this message
Hobson Lane (hobs) wrote :

Here's the patch utils.py that provides functions like

    undefined_to_human(python_string)
    latin_to_ascii(python_string)
    escape_unprintable(python_string)
    try_int(python_string)

The core exif.py string interface functions are unchanged. And try_int is an alternative more robust fix for Bug #942595, but again it too is not incorporated in the core exif.py. That's left as an exercise for the user (until a later patch or branch).

Revision history for this message
Hobson Lane (hobs) wrote :

Patch above is as "malformed" as the tags it's trying to protect against... it deletes utils.undefined_to_string() and leaves exif.py hanging out to dry. A better patch will follow shortly.

Revision history for this message
Hobson Lane (hobs) wrote :

Here's the patch that Oliver requested (I think). It only provides additional utilities for creating human-readable strings out of Undefined type tags like MakerNote.

    undefined_to_human(python_string)
    latin_to_ascii(python_string)
    escape_unprintable(python_string)
    try_int(python_string)

None of the existing pyexiv2 behavior is altered, so malformed tags (non ASCII bytes) can still cause trouble if printed.

Revision history for this message
Hobson Lane (hobs) wrote :

Here's the patch that actually incorporates undefined_to_human() into exif.py string conversion of Undefined type tags. Warning, this does change the output (for the better).

The output for included test images like smiley1.jpg are unchanged becasue they have no Undefined tags ( MakerNotes ) ...

    metadata = pyexiv2.ImageMetadata('test/data/smiley1.jpg')
    metadata.read()
    for k in metadata.exif_keys():
        print metadata[k]

Works just as before

description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.