MCPcopy
hub / github.com/pallets/click / open

Method open

src/click/utils.py:161–177  ·  view source on GitHub ↗

Opens the file if it's not yet open. This call might fail with a :exc:`FileError`. Not handling this error will produce an error that Click shows.

(self)

Source from the content-addressed store, hash-verified

159 return f"<unopened file '{format_filename(self.name)}' {self.mode}>"
160
161 def open(self) -> t.IO[t.Any]:
162 """Opens the file if it&#x27;s not yet open. This call might fail with
163 a :exc:`FileError`. Not handling this error will produce an error
164 that Click shows.
165 """
166 if self._f is not None:
167 return self._f
168 try:
169 rv, self.should_close = open_stream(
170 self.name, self.mode, self.encoding, self.errors, atomic=self.atomic
171 )
172 except OSError as e:
173 from .exceptions import FileError
174
175 raise FileError(self.name, hint=e.strerror) from e
176 self._f = rv
177 return rv
178
179 def close(self) -> None:
180 """Closes the underlying file, no matter what."""

Calls 2

open_streamFunction · 0.85
FileErrorClass · 0.85