Skip to content

Commit e13a296

Browse files
committed
fixes to make tests pass
1 parent 91ed731 commit e13a296

File tree

11 files changed

+383
-15
lines changed

11 files changed

+383
-15
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif
2020
EXIF_PY := $(if $(shell which EXIF.py),EXIF.py,./EXIF.py)
2121

2222
# Find images, support multiple case insensitive extensions and file names with spaces
23-
FIND_IMAGES := find tests/resources -regextype posix-egrep -iregex ".*\.(bmp|gif|heic|heif|jpg|jpeg|png|tiff|webp|arw|avif|jxl)" -print0 | LC_COLLATE=C sort -fz | xargs -0
23+
FIND_IMAGES := find tests/resources -type f -regextype posix-egrep -not -iregex ".*\.(txt|rst)" -print0 | LC_COLLATE=C sort -fz | xargs -0
2424

2525

2626
.PHONY: help

exifread/__init__.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
logger = get_logger()
1919

2020

21+
def _extract_xmp_data(hdr: ExifHeader, fh: BinaryIO):
22+
# Easy we already have them
23+
xmp_tag = hdr.tags.get("Image ApplicationNotes")
24+
if xmp_tag:
25+
logger.debug("XMP present in Exif")
26+
xmp_bytes = bytes(xmp_tag.values)
27+
# We need to look in the entire file for the XML
28+
else:
29+
xmp_bytes = find_xmp_data(fh)
30+
if xmp_bytes:
31+
hdr.parse_xmp(xmp_bytes)
32+
33+
2134
def process_file(
2235
fh: BinaryIO,
2336
stop_tag: str = DEFAULT_STOP_TAG,
@@ -93,10 +106,13 @@ def process_file(
93106
hdr.dump_ifd(ifd=exif_off.values[0], ifd_name="EXIF", stop_tag=stop_tag)
94107

95108
# EXIF SubIFD
96-
if details and "Image SubIFDs" in hdr.tags:
97-
for subifd_id, subifd_offset in enumerate(hdr.tags.get("Image SubIFDs").values):
109+
sub_ifds = hdr.tags.get("Image SubIFDs")
110+
if details and sub_ifds:
111+
for subifd_id, subifd_offset in enumerate(sub_ifds.values):
98112
logger.debug("Exif SubIFD%d at offset %d:", subifd_id, subifd_offset)
99-
hdr.dump_ifd(ifd=subifd_offset, ifd_name=f"EXIF SubIFD{subifd_id}", stop_tag=stop_tag)
113+
hdr.dump_ifd(
114+
ifd=subifd_offset, ifd_name=f"EXIF SubIFD{subifd_id}", stop_tag=stop_tag
115+
)
100116

101117
# deal with MakerNote contained in EXIF IFD
102118
# (Some apps use MakerNote tags but do not use a format for which we
@@ -111,16 +127,7 @@ def process_file(
111127

112128
# parse XMP tags (experimental)
113129
if debug and details:
114-
# Easy we already have them
115-
xmp_tag = hdr.tags.get("Image ApplicationNotes")
116-
if xmp_tag:
117-
logger.debug("XMP present in Exif")
118-
xmp_bytes = bytes(xmp_tag.values)
119-
# We need to look in the entire file for the XML
120-
else:
121-
xmp_bytes = find_xmp_data(fh)
122-
if xmp_bytes:
123-
hdr.parse_xmp(xmp_bytes)
130+
_extract_xmp_data(hdr=hdr, fh=fh)
124131

125132
if builtin_types:
126133
return convert_types(hdr.tags)

tests/resources/dump.txt

Lines changed: 359 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/resources/jpg/invalid/README

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Invalid / broken images.
2+
3+
The script should not go into an endless loop trying to read these.

0 commit comments

Comments
 (0)