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

Method wrap_file

rich/progress.py:1237–1277  ·  view source on GitHub ↗

Track progress file reading from a binary file. Args: file (BinaryIO): A file-like object opened in binary mode. total (int, optional): Total number of bytes to read. This must be provided unless a task with a total is also given. task_id (TaskID): Task t

(
        self,
        file: BinaryIO,
        total: Optional[int] = None,
        *,
        task_id: Optional[TaskID] = None,
        description: str = "Reading...",
    )

Source from the content-addressed store, hash-verified

1235 refresh()
1236
1237 def wrap_file(
1238 self,
1239 file: BinaryIO,
1240 total: Optional[int] = None,
1241 *,
1242 task_id: Optional[TaskID] = None,
1243 description: str = "Reading...",
1244 ) -> BinaryIO:
1245 """Track progress file reading from a binary file.
1246
1247 Args:
1248 file (BinaryIO): A file-like object opened in binary mode.
1249 total (int, optional): Total number of bytes to read. This must be provided unless a task with a total is also given.
1250 task_id (TaskID): Task to track. Default is new task.
1251 description (str, optional): Description of task, if new task is created.
1252
1253 Returns:
1254 BinaryIO: A readable file-like object in binary mode.
1255
1256 Raises:
1257 ValueError: When no total value can be extracted from the arguments or the task.
1258 """
1259 # attempt to recover the total from the task
1260 total_bytes: Optional[float] = None
1261 if total is not None:
1262 total_bytes = total
1263 elif task_id is not None:
1264 with self._lock:
1265 total_bytes = self._tasks[task_id].total
1266 if total_bytes is None:
1267 raise ValueError(
1268 f"unable to get the total number of bytes, please specify 'total'"
1269 )
1270
1271 # update total of task or create new task
1272 if task_id is None:
1273 task_id = self.add_task(description, total=total_bytes)
1274 else:
1275 self.update(task_id, total=total_bytes)
1276
1277 return _Reader(file, self, task_id, close_handle=False)
1278
1279 @typing.overload
1280 def open(

Callers 3

wrap_fileFunction · 0.95
test_wrap_fileFunction · 0.80

Calls 3

add_taskMethod · 0.95
updateMethod · 0.95
_ReaderClass · 0.85

Tested by 2

test_wrap_fileFunction · 0.64