MCPcopy
hub / github.com/Textualize/rich / _Reader

Class _Reader

rich/progress.py:182–282  ·  view source on GitHub ↗

A reader that tracks progress while it's being read from.

Source from the content-addressed store, hash-verified

180
181
182class _Reader(RawIOBase, BinaryIO):
183 """A reader that tracks progress while it's being read from."""
184
185 def __init__(
186 self,
187 handle: BinaryIO,
188 progress: "Progress",
189 task: TaskID,
190 close_handle: bool = True,
191 ) -> None:
192 self.handle = handle
193 self.progress = progress
194 self.task = task
195 self.close_handle = close_handle
196 self._closed = False
197
198 def __enter__(self) -> "_Reader":
199 self.handle.__enter__()
200 return self
201
202 def __exit__(
203 self,
204 exc_type: Optional[Type[BaseException]],
205 exc_val: Optional[BaseException],
206 exc_tb: Optional[TracebackType],
207 ) -> None:
208 self.close()
209
210 def __iter__(self) -> BinaryIO:
211 return self
212
213 def __next__(self) -> bytes:
214 line = next(self.handle)
215 self.progress.advance(self.task, advance=len(line))
216 return line
217
218 @property
219 def closed(self) -> bool:
220 return self._closed
221
222 def fileno(self) -> int:
223 return self.handle.fileno()
224
225 def isatty(self) -> bool:
226 return self.handle.isatty()
227
228 @property
229 def mode(self) -> str:
230 return self.handle.mode
231
232 @property
233 def name(self) -> str:
234 return self.handle.name
235
236 def readable(self) -> bool:
237 return self.handle.readable()
238
239 def seekable(self) -> bool:

Callers 2

wrap_fileMethod · 0.85
openMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected