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

Method __init__

src/click/utils.py:128–151  ·  view source on GitHub ↗
(
        self,
        filename: str | os.PathLike[str],
        mode: str = "r",
        encoding: str | None = None,
        errors: str | None = "strict",
        atomic: bool = False,
    )

Source from the content-addressed store, hash-verified

126 should_close: bool
127
128 def __init__(
129 self,
130 filename: str | os.PathLike[str],
131 mode: str = "r",
132 encoding: str | None = None,
133 errors: str | None = "strict",
134 atomic: bool = False,
135 ) -> None:
136 self.name = os.fspath(filename)
137 self.mode = mode
138 self.encoding = encoding
139 self.errors = errors
140 self.atomic = atomic
141
142 if self.name == "-":
143 self._f, self.should_close = open_stream(filename, mode, encoding, errors)
144 else:
145 if "r" in mode:
146 # Open and close the file in case we're opening it for
147 # reading so that we can catch at least some errors in
148 # some cases early.
149 open(filename, mode).close()
150 self._f = None
151 self.should_close = True
152
153 def __getattr__(self, name: str) -> t.Any:
154 return getattr(self.open(), name)

Callers

nothing calls this directly

Calls 3

open_streamFunction · 0.85
openFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected