Skip to content

Commit

Permalink
Update make_string util to clean up bad values (#128)
Browse files Browse the repository at this point in the history
* Update make_string util to clean up bad values
* Order tags alphabetically
  • Loading branch information
EtiennePelletier authored Nov 5, 2020
1 parent d0654ca commit 31d1d51
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions exifread/tags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# To ignore when quick processing
IGNORE_TAGS = (
0x9286, # user comment
0x927C, # MakerNote Tags
0x02BC, # XPM
0x927C, # MakerNote Tags
0x9286, # user comment
)
3 changes: 1 addition & 2 deletions exifread/tags/exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,9 @@
0xA435: ('LensSerialNumber', ),
0xA500: ('Gamma', ),
0xC4A5: ('PrintIM', ),
0xC61A: ('BlackLevel', ),
0xEA1C: ('Padding', ),
0xEA1D: ('OffsetSchema', ),
0xFDE8: ('OwnerName', ),
0xFDE9: ('SerialNumber', ),
0xC61A: ('BlackLevel', ),

}
2 changes: 1 addition & 1 deletion exifread/tags/makernote/nikon.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def ev_bias(seq) -> str:
# Nikon E99x MakerNote Tags
TAGS_NEW = {
0x0001: ('MakernoteVersion', make_string), # Sometimes binary
0x0002: ('ISOSetting', make_string),
0x0002: ('ISOSetting', ),
0x0003: ('ColorMode', ),
0x0004: ('Quality', ),
0x0005: ('Whitebalance', ),
Expand Down
16 changes: 13 additions & 3 deletions exifread/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from fractions import Fraction
from typing import Union


def ord_(dta):
Expand All @@ -11,7 +12,7 @@ def ord_(dta):
return dta


def make_string(seq: bytes) -> str:
def make_string(seq: Union[bytes, list]) -> str:
"""
Don't throw an exception when given an out of range character.
"""
Expand All @@ -23,10 +24,19 @@ def make_string(seq: bytes) -> str:
string += chr(char)
except TypeError:
pass

# If no printing chars
if not string:
return str(seq)
return string
if isinstance(seq, list):
string = ''.join(map(str, seq))
# Some UserComment lists only contain null bytes, nothing valueable to return
if set(string) == {'0'}:
return ''
else:
string = str(seq)

# Clean undesirable characters on any end
return string.strip(' \x00')


def make_string_uc(seq) -> str:
Expand Down

0 comments on commit 31d1d51

Please sign in to comment.