Skip to content

Commit 73cbcba

Browse files
author
Steve Canny
committed
img: add _JfifMarkers.app1
1 parent bd91474 commit 73cbcba

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

docx/image/jpeg.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ def app1(self):
138138
"""
139139
First APP1 marker in image markers.
140140
"""
141-
raise NotImplementedError
141+
for m in self._markers:
142+
if m.marker_code == JPEG_MARKER_CODE.APP1:
143+
return m
144+
raise KeyError('no APP1 marker in image')
142145

143146
@property
144147
def sof(self):
@@ -387,6 +390,12 @@ def from_stream(cls, stream, marker_code, offset):
387390
)
388391

389392

393+
class _App1Marker(_Marker):
394+
"""
395+
Represents a JFIF APP1 (Exif) marker segment.
396+
"""
397+
398+
390399
class _SofMarker(_Marker):
391400
"""
392401
Represents a JFIF start of frame (SOFx) marker segment.

tests/image/test_jpeg.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from docx.image.constants import JPEG_MARKER_CODE, MIME_TYPE
1515
from docx.image.helpers import BIG_ENDIAN, StreamReader
1616
from docx.image.jpeg import (
17-
_App0Marker, Exif, Jfif, _JfifMarkers, Jpeg, _Marker, _MarkerFactory,
18-
_MarkerFinder, _MarkerParser, _SofMarker
17+
_App0Marker, _App1Marker, Exif, Jfif, _JfifMarkers, Jpeg, _Marker,
18+
_MarkerFactory, _MarkerFinder, _MarkerParser, _SofMarker
1919
)
2020

2121
from ..unitutil import class_mock, initializer_mock, instance_mock
@@ -154,6 +154,11 @@ def it_can_find_the_APP0_marker(self, app0_fixture):
154154
app0 = jfif_markers.app0
155155
assert app0 is app0_
156156

157+
def it_can_find_the_APP1_marker(self, app1_fixture):
158+
jfif_markers, app1_ = app1_fixture
159+
app1 = jfif_markers.app1
160+
assert app1 is app1_
161+
157162
def it_raises_if_it_cant_find_the_APP0_marker(self, no_app0_fixture):
158163
jfif_markers = no_app0_fixture
159164
with pytest.raises(KeyError):
@@ -177,12 +182,24 @@ def app0_(self, request):
177182
request, _App0Marker, marker_code=JPEG_MARKER_CODE.APP0
178183
)
179184

185+
@pytest.fixture
186+
def app1_(self, request):
187+
return instance_mock(
188+
request, _App1Marker, marker_code=JPEG_MARKER_CODE.APP1
189+
)
190+
180191
@pytest.fixture
181192
def app0_fixture(self, soi_, app0_, eoi_):
182193
markers = (soi_, app0_, eoi_)
183194
jfif_markers = _JfifMarkers(markers)
184195
return jfif_markers, app0_
185196

197+
@pytest.fixture
198+
def app1_fixture(self, soi_, app1_, eoi_):
199+
markers = (soi_, app1_, eoi_)
200+
jfif_markers = _JfifMarkers(markers)
201+
return jfif_markers, app1_
202+
186203
@pytest.fixture
187204
def eoi_(self, request):
188205
return instance_mock(

0 commit comments

Comments
 (0)