MCPcopy Create free account
hub / github.com/python-pillow/Pillow / __init__

Method __init__

src/PIL/ImageFile.py:117–171  ·  view source on GitHub ↗
(
        self, fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None
    )

Source from the content-addressed store, hash-verified

115 """Base class for image file format handlers."""
116
117 def __init__(
118 self, fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None
119 ) -> None:
120 super().__init__()
121
122 self._min_frame = 0
123
124 self.custom_mimetype: str | None = None
125
126 self.tile: list[_Tile] = []
127 """ A list of tile descriptors """
128
129 self.readonly = 1 # until we know better
130
131 self.decoderconfig: tuple[Any, ...] = ()
132 self.decodermaxblock = MAXBLOCK
133
134 self.fp: IO[bytes] | None
135 self._fp: IO[bytes] | DeferredError
136 if is_path(fp):
137 # filename
138 self.fp = open(fp, "rb")
139 self.filename = os.fspath(fp)
140 self._exclusive_fp = True
141 else:
142 # stream
143 self.fp = cast(IO[bytes], fp)
144 self.filename = filename if filename is not None else ""
145 # can be overridden
146 self._exclusive_fp = False
147
148 try:
149 try:
150 self._open()
151
152 if isinstance(self, StubImageFile):
153 if loader := self._load():
154 loader.open(self)
155 except (
156 IndexError, # end of data
157 TypeError, # end of data (ord)
158 KeyError, # unsupported mode
159 EOFError, # got header but not the first frame
160 struct.error,
161 ) as v:
162 raise SyntaxError(v) from v
163
164 if not self.mode or self.size[0] <= 0 or self.size[1] <= 0:
165 msg = "not identified by this driver"
166 raise SyntaxError(msg)
167 except BaseException:
168 # close the file only if we have opened it this constructor
169 if self._exclusive_fp:
170 self.fp.close()
171 raise
172
173 def _open(self) -> None:
174 pass

Callers

nothing calls this directly

Calls 7

_openMethod · 0.95
is_pathFunction · 0.85
openFunction · 0.70
__init__Method · 0.45
_loadMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected