MCPcopy Index your code
hub / github.com/python-openxml/python-docx / _ImageHeaderFactory

Function _ImageHeaderFactory

src/docx/image/image.py:168–182  ·  view source on GitHub ↗

A |BaseImageHeader| subclass instance that can parse headers of image in `stream`.

(stream: IO[bytes])

Source from the content-addressed store, hash-verified

166
167
168def _ImageHeaderFactory(stream: IO[bytes]):
169 """A |BaseImageHeader| subclass instance that can parse headers of image in `stream`."""
170 from docx.image import SIGNATURES
171
172 def read_32(stream: IO[bytes]):
173 stream.seek(0)
174 return stream.read(32)
175
176 header = read_32(stream)
177 for cls, offset, signature_bytes in SIGNATURES:
178 end = offset + len(signature_bytes)
179 found_bytes = header[offset:end]
180 if found_bytes == signature_bytes:
181 return cls.from_stream(stream)
182 raise UnrecognizedImageError
183
184
185class BaseImageHeader:

Calls 2

read_32Function · 0.85
from_streamMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…