Skip to content

Commit 80c395d

Browse files
author
Steve Canny
committed
img: add _Tiff.content_type
1 parent fdeb44f commit 80c395d

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

docx/image/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ def is_standalone(cls, marker_code):
9595

9696
class MIME_TYPE(object):
9797
"""
98-
Image content types.
98+
Image content types
9999
"""
100100
JPEG = 'image/jpeg'
101101
PNG = 'image/png'
102+
TIFF = 'image/tiff'
102103

103104

104105
class TAG(object):

docx/image/tiff.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import absolute_import, division, print_function
44

5-
from .constants import TIFF_FLD, TIFF_TAG
5+
from .constants import MIME_TYPE, TIFF_FLD, TIFF_TAG
66
from .helpers import BIG_ENDIAN, LITTLE_ENDIAN, StreamReader
77
from .image import Image
88

@@ -12,6 +12,19 @@ class Tiff(Image):
1212
Image header parser for TIFF images. Handles both big and little endian
1313
byte ordering.
1414
"""
15+
def __init__(self, blob, filename, cx, cy, horz_dpi, vert_dpi):
16+
super(Tiff, self).__init__(blob, filename, cx, cy, {})
17+
self._horz_dpi = horz_dpi
18+
self._vert_dpi = vert_dpi
19+
20+
@property
21+
def content_type(self):
22+
"""
23+
Return the MIME type of this TIFF image, unconditionally the string
24+
``image/tiff``.
25+
"""
26+
return MIME_TYPE.TIFF
27+
1528
@classmethod
1629
def from_stream(cls, stream, blob, filename):
1730
"""

tests/image/test_tiff.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from mock import call
1212

1313
from docx.compat import BytesIO
14-
from docx.image.constants import TIFF_TAG
14+
from docx.image.constants import MIME_TYPE, TIFF_TAG
1515
from docx.image.helpers import BIG_ENDIAN, LITTLE_ENDIAN, StreamReader
1616
from docx.image.tiff import (
1717
_IfdEntries, _IfdEntry, _IfdEntryFactory, _IfdParser, Tiff, _TiffParser
@@ -35,6 +35,10 @@ def it_can_construct_from_a_tiff_stream(self, from_stream_fixture):
3535
)
3636
assert isinstance(tiff, Tiff)
3737

38+
def it_knows_its_content_type(self):
39+
tiff = Tiff(None, None, None, None, None, None)
40+
assert tiff.content_type == MIME_TYPE.TIFF
41+
3842
# fixtures -------------------------------------------------------
3943

4044
@pytest.fixture

0 commit comments

Comments
 (0)