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

Class _Chunks

src/docx/image/png.py:92–126  ·  view source on GitHub ↗

Collection of the chunks parsed from a PNG image stream.

Source from the content-addressed store, hash-verified

90
91
92class _Chunks:
93 """Collection of the chunks parsed from a PNG image stream."""
94
95 def __init__(self, chunk_iterable):
96 super(_Chunks, self).__init__()
97 self._chunks = list(chunk_iterable)
98
99 @classmethod
100 def from_stream(cls, stream):
101 """Return a |_Chunks| instance containing the PNG chunks in `stream`."""
102 chunk_parser = _ChunkParser.from_stream(stream)
103 chunks = list(chunk_parser.iter_chunks())
104 return cls(chunks)
105
106 @property
107 def IHDR(self):
108 """IHDR chunk in PNG image."""
109 match = lambda chunk: chunk.type_name == PNG_CHUNK_TYPE.IHDR # noqa
110 IHDR = self._find_first(match)
111 if IHDR is None:
112 raise InvalidImageStreamError("no IHDR chunk in PNG image")
113 return IHDR
114
115 @property
116 def pHYs(self):
117 """PHYs chunk in PNG image, or |None| if not present."""
118 match = lambda chunk: chunk.type_name == PNG_CHUNK_TYPE.pHYs # noqa
119 return self._find_first(match)
120
121 def _find_first(self, match):
122 """Return first chunk in stream order returning True for function `match`."""
123 for chunk in self._chunks:
124 if match(chunk):
125 return chunk
126 return None
127
128
129class _ChunkParser:

Callers 3

IHDR_fixtureMethod · 0.90
no_IHDR_fixtureMethod · 0.90
pHYs_fixtureMethod · 0.90

Calls

no outgoing calls

Tested by 3

IHDR_fixtureMethod · 0.72
no_IHDR_fixtureMethod · 0.72
pHYs_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…