A |BaseImageHeader| subclass instance that can parse headers of image in `stream`.
(stream: IO[bytes])
| 166 | |
| 167 | |
| 168 | def _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 | |
| 185 | class BaseImageHeader: |
searching dependent graphs…