Method: rich.progress.open
Calls: 2, Exceptions: 0, Paths: 1Back
Path 1: 2 calls (1.0)
'/var/folders/yp/qx0crmvd4sbck7chb52sws500000gn/T/tmp64e9b1we' (1) '/var/folders/yp/qx0crmvd4sbck7chb52sws500000gn/T/tmpaf7shnw1' (1)
'r' (2)
-1 (2)
None (2)
None (2)
None (2)
None (2)
'Reading...' (2)
True (2)
None (2)
False (2)
None (2)
10 (2)
'bar.back' (2)
'bar.complete' (2)
'bar.finished' (2)
'bar.pulse' (2)
False (2)
_ReadContext (2)
1def open(
2 file: Union[str, "PathLike[str]", bytes],
3 mode: Union[Literal["rb"], Literal["rt"], Literal["r"]] = "r",
4 buffering: int = -1,
5 encoding: Optional[str] = None,
6 errors: Optional[str] = None,
7 newline: Optional[str] = None,
8 *,
9 total: Optional[int] = None,
10 description: str = "Reading...",
11 auto_refresh: bool = True,
12 console: Optional[Console] = None,
13 transient: bool = False,
14 get_time: Optional[Callable[[], float]] = None,
15 refresh_per_second: float = 10,
16 style: StyleType = "bar.back",
17 complete_style: StyleType = "bar.complete",
18 finished_style: StyleType = "bar.finished",
19 pulse_style: StyleType = "bar.pulse",
20 disable: bool = False,
21) -> Union[ContextManager[BinaryIO], ContextManager[TextIO]]:
22 """Read bytes from a file while tracking progress.
23
24 Args:
25 path (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode.
26 mode (str): The mode to use to open the file. Only supports "r", "rb" or "rt".
27 buffering (int): The buffering strategy to use, see :func:`io.open`.
28 encoding (str, optional): The encoding to use when reading in text mode, see :func:`io.open`.
29 errors (str, optional): The error handling strategy for decoding errors, see :func:`io.open`.
30 newline (str, optional): The strategy for handling newlines in text mode, see :func:`io.open`
31 total: (int, optional): Total number of bytes to read. Must be provided if reading from a file handle. Default for a path is os.stat(file).st_size.
32 description (str, optional): Description of task show next to progress bar. Defaults to "Reading".
33 auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
34 transient: (bool, optional): Clear the progress on exit. Defaults to False.
35 console (Console, optional): Console to write to. Default creates internal Console instance.
36 refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10.
37 style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
38 complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
39 finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
40 pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
41 disable (bool, optional): Disable display of progress.
42 encoding (str, optional): The encoding to use when reading in text mode.
43
44 Returns:
45 ContextManager[BinaryIO]: A context manager yielding a progress reader.
46
47 """
48
49 columns: List["ProgressColumn"] = (
50 [TextColumn("[progress.description]{task.description}")] if description else []
51 )
52 columns.extend(
53 (
54 BarColumn(
55 style=style,
56 complete_style=complete_style,
57 finished_style=finished_style,
58 pulse_style=pulse_style,
59 ),
60 DownloadColumn(),
61 TimeRemainingColumn(),
62 )
63 )
64 progress = Progress(
65 *columns,
66 auto_refresh=auto_refresh,
67 console=console,
68 transient=transient,
69 get_time=get_time,
70 refresh_per_second=refresh_per_second or 10,
71 disable=disable,
72 )
73
74 reader = progress.open(
75 file,
76 mode=mode,
77 buffering=buffering,
78 encoding=encoding,
79 errors=errors,
80 newline=newline,
81 total=total,
82 description=description,
83 )
84 return _ReadContext(progress, reader) # type: ignore[return-value, type-var]