ZTWHHH commited on
Commit
125c515
·
verified ·
1 Parent(s): 63d7f48

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/__main__.cpython-310.pyc +0 -0
  2. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_extension.cpython-310.pyc +0 -0
  3. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_inspect.cpython-310.pyc +0 -0
  4. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_ratio.cpython-310.pyc +0 -0
  5. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_spinners.cpython-310.pyc +0 -0
  6. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_windows.cpython-310.pyc +0 -0
  7. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_windows_renderer.cpython-310.pyc +0 -0
  8. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_wrap.cpython-310.pyc +0 -0
  9. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/abc.cpython-310.pyc +0 -0
  10. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/color.cpython-310.pyc +0 -0
  11. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/color_triplet.cpython-310.pyc +0 -0
  12. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/columns.cpython-310.pyc +0 -0
  13. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/containers.cpython-310.pyc +0 -0
  14. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/control.cpython-310.pyc +0 -0
  15. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/highlighter.cpython-310.pyc +0 -0
  16. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/markup.cpython-310.pyc +0 -0
  17. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/measure.cpython-310.pyc +0 -0
  18. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/padding.cpython-310.pyc +0 -0
  19. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/palette.cpython-310.pyc +0 -0
  20. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/panel.cpython-310.pyc +0 -0
  21. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/progress_bar.cpython-310.pyc +0 -0
  22. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/region.cpython-310.pyc +0 -0
  23. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/repr.cpython-310.pyc +0 -0
  24. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/screen.cpython-310.pyc +0 -0
  25. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/segment.cpython-310.pyc +0 -0
  26. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/spinner.cpython-310.pyc +0 -0
  27. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/style.cpython-310.pyc +0 -0
  28. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/table.cpython-310.pyc +0 -0
  29. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/theme.cpython-310.pyc +0 -0
  30. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/themes.cpython-310.pyc +0 -0
  31. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/traceback.cpython-310.pyc +0 -0
  32. llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/tree.cpython-310.pyc +0 -0
  33. llava/lib/python3.10/site-packages/pip/_vendor/rich/_fileno.py +24 -0
  34. llava/lib/python3.10/site-packages/pip/_vendor/rich/_windows_renderer.py +56 -0
  35. llava/lib/python3.10/site-packages/pip/_vendor/rich/align.py +312 -0
  36. llava/lib/python3.10/site-packages/pip/_vendor/rich/bar.py +93 -0
  37. llava/lib/python3.10/site-packages/pip/_vendor/rich/box.py +480 -0
  38. llava/lib/python3.10/site-packages/pip/_vendor/rich/control.py +225 -0
  39. llava/lib/python3.10/site-packages/pip/_vendor/rich/highlighter.py +232 -0
  40. llava/lib/python3.10/site-packages/pip/_vendor/rich/json.py +139 -0
  41. llava/lib/python3.10/site-packages/pip/_vendor/rich/palette.py +100 -0
  42. llava/lib/python3.10/site-packages/pip/_vendor/rich/panel.py +318 -0
  43. llava/lib/python3.10/site-packages/pip/_vendor/rich/progress_bar.py +223 -0
  44. llava/lib/python3.10/site-packages/pip/_vendor/rich/prompt.py +400 -0
  45. llava/lib/python3.10/site-packages/pip/_vendor/rich/protocol.py +42 -0
  46. llava/lib/python3.10/site-packages/pip/_vendor/rich/segment.py +752 -0
  47. llava/lib/python3.10/site-packages/pip/_vendor/rich/themes.py +5 -0
  48. llava/lib/python3.10/site-packages/pip/_vendor/rich/tree.py +257 -0
  49. minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/parser_inline.cpython-310.pyc +0 -0
  50. minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/token.cpython-310.pyc +0 -0
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/__main__.cpython-310.pyc ADDED
Binary file (7.16 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_extension.cpython-310.pyc ADDED
Binary file (474 Bytes). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_inspect.cpython-310.pyc ADDED
Binary file (8.6 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_ratio.cpython-310.pyc ADDED
Binary file (5.14 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_spinners.cpython-310.pyc ADDED
Binary file (12.3 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_windows.cpython-310.pyc ADDED
Binary file (1.77 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_windows_renderer.cpython-310.pyc ADDED
Binary file (2.02 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/_wrap.cpython-310.pyc ADDED
Binary file (2.45 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/abc.cpython-310.pyc ADDED
Binary file (1.29 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/color.cpython-310.pyc ADDED
Binary file (17.7 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/color_triplet.cpython-310.pyc ADDED
Binary file (1.42 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/columns.cpython-310.pyc ADDED
Binary file (6.18 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/containers.cpython-310.pyc ADDED
Binary file (6.47 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/control.cpython-310.pyc ADDED
Binary file (8.14 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/highlighter.cpython-310.pyc ADDED
Binary file (8.04 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/markup.cpython-310.pyc ADDED
Binary file (6.14 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/measure.cpython-310.pyc ADDED
Binary file (5.06 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/padding.cpython-310.pyc ADDED
Binary file (4.4 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/palette.cpython-310.pyc ADDED
Binary file (3.69 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/panel.cpython-310.pyc ADDED
Binary file (7.93 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/progress_bar.cpython-310.pyc ADDED
Binary file (6.89 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/region.cpython-310.pyc ADDED
Binary file (506 Bytes). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/repr.cpython-310.pyc ADDED
Binary file (4.08 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/screen.cpython-310.pyc ADDED
Binary file (1.86 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/segment.cpython-310.pyc ADDED
Binary file (21.2 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/spinner.cpython-310.pyc ADDED
Binary file (4.39 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/style.cpython-310.pyc ADDED
Binary file (21.3 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/table.cpython-310.pyc ADDED
Binary file (30.2 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/theme.cpython-310.pyc ADDED
Binary file (4.81 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/themes.cpython-310.pyc ADDED
Binary file (272 Bytes). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/traceback.cpython-310.pyc ADDED
Binary file (22.6 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/__pycache__/tree.cpython-310.pyc ADDED
Binary file (7.62 kB). View file
 
llava/lib/python3.10/site-packages/pip/_vendor/rich/_fileno.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from typing import IO, Callable
4
+
5
+
6
+ def get_fileno(file_like: IO[str]) -> int | None:
7
+ """Get fileno() from a file, accounting for poorly implemented file-like objects.
8
+
9
+ Args:
10
+ file_like (IO): A file-like object.
11
+
12
+ Returns:
13
+ int | None: The result of fileno if available, or None if operation failed.
14
+ """
15
+ fileno: Callable[[], int] | None = getattr(file_like, "fileno", None)
16
+ if fileno is not None:
17
+ try:
18
+ return fileno()
19
+ except Exception:
20
+ # `fileno` is documented as potentially raising a OSError
21
+ # Alas, from the issues, there are so many poorly implemented file-like objects,
22
+ # that `fileno()` can raise just about anything.
23
+ return None
24
+ return None
llava/lib/python3.10/site-packages/pip/_vendor/rich/_windows_renderer.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Iterable, Sequence, Tuple, cast
2
+
3
+ from pip._vendor.rich._win32_console import LegacyWindowsTerm, WindowsCoordinates
4
+ from pip._vendor.rich.segment import ControlCode, ControlType, Segment
5
+
6
+
7
+ def legacy_windows_render(buffer: Iterable[Segment], term: LegacyWindowsTerm) -> None:
8
+ """Makes appropriate Windows Console API calls based on the segments in the buffer.
9
+
10
+ Args:
11
+ buffer (Iterable[Segment]): Iterable of Segments to convert to Win32 API calls.
12
+ term (LegacyWindowsTerm): Used to call the Windows Console API.
13
+ """
14
+ for text, style, control in buffer:
15
+ if not control:
16
+ if style:
17
+ term.write_styled(text, style)
18
+ else:
19
+ term.write_text(text)
20
+ else:
21
+ control_codes: Sequence[ControlCode] = control
22
+ for control_code in control_codes:
23
+ control_type = control_code[0]
24
+ if control_type == ControlType.CURSOR_MOVE_TO:
25
+ _, x, y = cast(Tuple[ControlType, int, int], control_code)
26
+ term.move_cursor_to(WindowsCoordinates(row=y - 1, col=x - 1))
27
+ elif control_type == ControlType.CARRIAGE_RETURN:
28
+ term.write_text("\r")
29
+ elif control_type == ControlType.HOME:
30
+ term.move_cursor_to(WindowsCoordinates(0, 0))
31
+ elif control_type == ControlType.CURSOR_UP:
32
+ term.move_cursor_up()
33
+ elif control_type == ControlType.CURSOR_DOWN:
34
+ term.move_cursor_down()
35
+ elif control_type == ControlType.CURSOR_FORWARD:
36
+ term.move_cursor_forward()
37
+ elif control_type == ControlType.CURSOR_BACKWARD:
38
+ term.move_cursor_backward()
39
+ elif control_type == ControlType.CURSOR_MOVE_TO_COLUMN:
40
+ _, column = cast(Tuple[ControlType, int], control_code)
41
+ term.move_cursor_to_column(column - 1)
42
+ elif control_type == ControlType.HIDE_CURSOR:
43
+ term.hide_cursor()
44
+ elif control_type == ControlType.SHOW_CURSOR:
45
+ term.show_cursor()
46
+ elif control_type == ControlType.ERASE_IN_LINE:
47
+ _, mode = cast(Tuple[ControlType, int], control_code)
48
+ if mode == 0:
49
+ term.erase_end_of_line()
50
+ elif mode == 1:
51
+ term.erase_start_of_line()
52
+ elif mode == 2:
53
+ term.erase_line()
54
+ elif control_type == ControlType.SET_WINDOW_TITLE:
55
+ _, title = cast(Tuple[ControlType, str], control_code)
56
+ term.set_title(title)
llava/lib/python3.10/site-packages/pip/_vendor/rich/align.py ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from itertools import chain
3
+ from typing import TYPE_CHECKING, Iterable, Optional
4
+
5
+ if sys.version_info >= (3, 8):
6
+ from typing import Literal
7
+ else:
8
+ from pip._vendor.typing_extensions import Literal # pragma: no cover
9
+
10
+ from .constrain import Constrain
11
+ from .jupyter import JupyterMixin
12
+ from .measure import Measurement
13
+ from .segment import Segment
14
+ from .style import StyleType
15
+
16
+ if TYPE_CHECKING:
17
+ from .console import Console, ConsoleOptions, RenderableType, RenderResult
18
+
19
+ AlignMethod = Literal["left", "center", "right"]
20
+ VerticalAlignMethod = Literal["top", "middle", "bottom"]
21
+
22
+
23
+ class Align(JupyterMixin):
24
+ """Align a renderable by adding spaces if necessary.
25
+
26
+ Args:
27
+ renderable (RenderableType): A console renderable.
28
+ align (AlignMethod): One of "left", "center", or "right""
29
+ style (StyleType, optional): An optional style to apply to the background.
30
+ vertical (Optional[VerticalAlignMethod], optional): Optional vertical align, one of "top", "middle", or "bottom". Defaults to None.
31
+ pad (bool, optional): Pad the right with spaces. Defaults to True.
32
+ width (int, optional): Restrict contents to given width, or None to use default width. Defaults to None.
33
+ height (int, optional): Set height of align renderable, or None to fit to contents. Defaults to None.
34
+
35
+ Raises:
36
+ ValueError: if ``align`` is not one of the expected values.
37
+ """
38
+
39
+ def __init__(
40
+ self,
41
+ renderable: "RenderableType",
42
+ align: AlignMethod = "left",
43
+ style: Optional[StyleType] = None,
44
+ *,
45
+ vertical: Optional[VerticalAlignMethod] = None,
46
+ pad: bool = True,
47
+ width: Optional[int] = None,
48
+ height: Optional[int] = None,
49
+ ) -> None:
50
+ if align not in ("left", "center", "right"):
51
+ raise ValueError(
52
+ f'invalid value for align, expected "left", "center", or "right" (not {align!r})'
53
+ )
54
+ if vertical is not None and vertical not in ("top", "middle", "bottom"):
55
+ raise ValueError(
56
+ f'invalid value for vertical, expected "top", "middle", or "bottom" (not {vertical!r})'
57
+ )
58
+ self.renderable = renderable
59
+ self.align = align
60
+ self.style = style
61
+ self.vertical = vertical
62
+ self.pad = pad
63
+ self.width = width
64
+ self.height = height
65
+
66
+ def __repr__(self) -> str:
67
+ return f"Align({self.renderable!r}, {self.align!r})"
68
+
69
+ @classmethod
70
+ def left(
71
+ cls,
72
+ renderable: "RenderableType",
73
+ style: Optional[StyleType] = None,
74
+ *,
75
+ vertical: Optional[VerticalAlignMethod] = None,
76
+ pad: bool = True,
77
+ width: Optional[int] = None,
78
+ height: Optional[int] = None,
79
+ ) -> "Align":
80
+ """Align a renderable to the left."""
81
+ return cls(
82
+ renderable,
83
+ "left",
84
+ style=style,
85
+ vertical=vertical,
86
+ pad=pad,
87
+ width=width,
88
+ height=height,
89
+ )
90
+
91
+ @classmethod
92
+ def center(
93
+ cls,
94
+ renderable: "RenderableType",
95
+ style: Optional[StyleType] = None,
96
+ *,
97
+ vertical: Optional[VerticalAlignMethod] = None,
98
+ pad: bool = True,
99
+ width: Optional[int] = None,
100
+ height: Optional[int] = None,
101
+ ) -> "Align":
102
+ """Align a renderable to the center."""
103
+ return cls(
104
+ renderable,
105
+ "center",
106
+ style=style,
107
+ vertical=vertical,
108
+ pad=pad,
109
+ width=width,
110
+ height=height,
111
+ )
112
+
113
+ @classmethod
114
+ def right(
115
+ cls,
116
+ renderable: "RenderableType",
117
+ style: Optional[StyleType] = None,
118
+ *,
119
+ vertical: Optional[VerticalAlignMethod] = None,
120
+ pad: bool = True,
121
+ width: Optional[int] = None,
122
+ height: Optional[int] = None,
123
+ ) -> "Align":
124
+ """Align a renderable to the right."""
125
+ return cls(
126
+ renderable,
127
+ "right",
128
+ style=style,
129
+ vertical=vertical,
130
+ pad=pad,
131
+ width=width,
132
+ height=height,
133
+ )
134
+
135
+ def __rich_console__(
136
+ self, console: "Console", options: "ConsoleOptions"
137
+ ) -> "RenderResult":
138
+ align = self.align
139
+ width = console.measure(self.renderable, options=options).maximum
140
+ rendered = console.render(
141
+ Constrain(
142
+ self.renderable, width if self.width is None else min(width, self.width)
143
+ ),
144
+ options.update(height=None),
145
+ )
146
+ lines = list(Segment.split_lines(rendered))
147
+ width, height = Segment.get_shape(lines)
148
+ lines = Segment.set_shape(lines, width, height)
149
+ new_line = Segment.line()
150
+ excess_space = options.max_width - width
151
+ style = console.get_style(self.style) if self.style is not None else None
152
+
153
+ def generate_segments() -> Iterable[Segment]:
154
+ if excess_space <= 0:
155
+ # Exact fit
156
+ for line in lines:
157
+ yield from line
158
+ yield new_line
159
+
160
+ elif align == "left":
161
+ # Pad on the right
162
+ pad = Segment(" " * excess_space, style) if self.pad else None
163
+ for line in lines:
164
+ yield from line
165
+ if pad:
166
+ yield pad
167
+ yield new_line
168
+
169
+ elif align == "center":
170
+ # Pad left and right
171
+ left = excess_space // 2
172
+ pad = Segment(" " * left, style)
173
+ pad_right = (
174
+ Segment(" " * (excess_space - left), style) if self.pad else None
175
+ )
176
+ for line in lines:
177
+ if left:
178
+ yield pad
179
+ yield from line
180
+ if pad_right:
181
+ yield pad_right
182
+ yield new_line
183
+
184
+ elif align == "right":
185
+ # Padding on left
186
+ pad = Segment(" " * excess_space, style)
187
+ for line in lines:
188
+ yield pad
189
+ yield from line
190
+ yield new_line
191
+
192
+ blank_line = (
193
+ Segment(f"{' ' * (self.width or options.max_width)}\n", style)
194
+ if self.pad
195
+ else Segment("\n")
196
+ )
197
+
198
+ def blank_lines(count: int) -> Iterable[Segment]:
199
+ if count > 0:
200
+ for _ in range(count):
201
+ yield blank_line
202
+
203
+ vertical_height = self.height or options.height
204
+ iter_segments: Iterable[Segment]
205
+ if self.vertical and vertical_height is not None:
206
+ if self.vertical == "top":
207
+ bottom_space = vertical_height - height
208
+ iter_segments = chain(generate_segments(), blank_lines(bottom_space))
209
+ elif self.vertical == "middle":
210
+ top_space = (vertical_height - height) // 2
211
+ bottom_space = vertical_height - top_space - height
212
+ iter_segments = chain(
213
+ blank_lines(top_space),
214
+ generate_segments(),
215
+ blank_lines(bottom_space),
216
+ )
217
+ else: # self.vertical == "bottom":
218
+ top_space = vertical_height - height
219
+ iter_segments = chain(blank_lines(top_space), generate_segments())
220
+ else:
221
+ iter_segments = generate_segments()
222
+ if self.style:
223
+ style = console.get_style(self.style)
224
+ iter_segments = Segment.apply_style(iter_segments, style)
225
+ yield from iter_segments
226
+
227
+ def __rich_measure__(
228
+ self, console: "Console", options: "ConsoleOptions"
229
+ ) -> Measurement:
230
+ measurement = Measurement.get(console, options, self.renderable)
231
+ return measurement
232
+
233
+
234
+ class VerticalCenter(JupyterMixin):
235
+ """Vertically aligns a renderable.
236
+
237
+ Warn:
238
+ This class is deprecated and may be removed in a future version. Use Align class with
239
+ `vertical="middle"`.
240
+
241
+ Args:
242
+ renderable (RenderableType): A renderable object.
243
+ style (StyleType, optional): An optional style to apply to the background. Defaults to None.
244
+ """
245
+
246
+ def __init__(
247
+ self,
248
+ renderable: "RenderableType",
249
+ style: Optional[StyleType] = None,
250
+ ) -> None:
251
+ self.renderable = renderable
252
+ self.style = style
253
+
254
+ def __repr__(self) -> str:
255
+ return f"VerticalCenter({self.renderable!r})"
256
+
257
+ def __rich_console__(
258
+ self, console: "Console", options: "ConsoleOptions"
259
+ ) -> "RenderResult":
260
+ style = console.get_style(self.style) if self.style is not None else None
261
+ lines = console.render_lines(
262
+ self.renderable, options.update(height=None), pad=False
263
+ )
264
+ width, _height = Segment.get_shape(lines)
265
+ new_line = Segment.line()
266
+ height = options.height or options.size.height
267
+ top_space = (height - len(lines)) // 2
268
+ bottom_space = height - top_space - len(lines)
269
+ blank_line = Segment(f"{' ' * width}", style)
270
+
271
+ def blank_lines(count: int) -> Iterable[Segment]:
272
+ for _ in range(count):
273
+ yield blank_line
274
+ yield new_line
275
+
276
+ if top_space > 0:
277
+ yield from blank_lines(top_space)
278
+ for line in lines:
279
+ yield from line
280
+ yield new_line
281
+ if bottom_space > 0:
282
+ yield from blank_lines(bottom_space)
283
+
284
+ def __rich_measure__(
285
+ self, console: "Console", options: "ConsoleOptions"
286
+ ) -> Measurement:
287
+ measurement = Measurement.get(console, options, self.renderable)
288
+ return measurement
289
+
290
+
291
+ if __name__ == "__main__": # pragma: no cover
292
+ from pip._vendor.rich.console import Console, Group
293
+ from pip._vendor.rich.highlighter import ReprHighlighter
294
+ from pip._vendor.rich.panel import Panel
295
+
296
+ highlighter = ReprHighlighter()
297
+ console = Console()
298
+
299
+ panel = Panel(
300
+ Group(
301
+ Align.left(highlighter("align='left'")),
302
+ Align.center(highlighter("align='center'")),
303
+ Align.right(highlighter("align='right'")),
304
+ ),
305
+ width=60,
306
+ style="on dark_blue",
307
+ title="Align",
308
+ )
309
+
310
+ console.print(
311
+ Align.center(panel, vertical="middle", style="on red", height=console.height)
312
+ )
llava/lib/python3.10/site-packages/pip/_vendor/rich/bar.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Union
2
+
3
+ from .color import Color
4
+ from .console import Console, ConsoleOptions, RenderResult
5
+ from .jupyter import JupyterMixin
6
+ from .measure import Measurement
7
+ from .segment import Segment
8
+ from .style import Style
9
+
10
+ # There are left-aligned characters for 1/8 to 7/8, but
11
+ # the right-aligned characters exist only for 1/8 and 4/8.
12
+ BEGIN_BLOCK_ELEMENTS = ["█", "█", "█", "▐", "▐", "▐", "▕", "▕"]
13
+ END_BLOCK_ELEMENTS = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"]
14
+ FULL_BLOCK = "█"
15
+
16
+
17
+ class Bar(JupyterMixin):
18
+ """Renders a solid block bar.
19
+
20
+ Args:
21
+ size (float): Value for the end of the bar.
22
+ begin (float): Begin point (between 0 and size, inclusive).
23
+ end (float): End point (between 0 and size, inclusive).
24
+ width (int, optional): Width of the bar, or ``None`` for maximum width. Defaults to None.
25
+ color (Union[Color, str], optional): Color of the bar. Defaults to "default".
26
+ bgcolor (Union[Color, str], optional): Color of bar background. Defaults to "default".
27
+ """
28
+
29
+ def __init__(
30
+ self,
31
+ size: float,
32
+ begin: float,
33
+ end: float,
34
+ *,
35
+ width: Optional[int] = None,
36
+ color: Union[Color, str] = "default",
37
+ bgcolor: Union[Color, str] = "default",
38
+ ):
39
+ self.size = size
40
+ self.begin = max(begin, 0)
41
+ self.end = min(end, size)
42
+ self.width = width
43
+ self.style = Style(color=color, bgcolor=bgcolor)
44
+
45
+ def __repr__(self) -> str:
46
+ return f"Bar({self.size}, {self.begin}, {self.end})"
47
+
48
+ def __rich_console__(
49
+ self, console: Console, options: ConsoleOptions
50
+ ) -> RenderResult:
51
+ width = min(
52
+ self.width if self.width is not None else options.max_width,
53
+ options.max_width,
54
+ )
55
+
56
+ if self.begin >= self.end:
57
+ yield Segment(" " * width, self.style)
58
+ yield Segment.line()
59
+ return
60
+
61
+ prefix_complete_eights = int(width * 8 * self.begin / self.size)
62
+ prefix_bar_count = prefix_complete_eights // 8
63
+ prefix_eights_count = prefix_complete_eights % 8
64
+
65
+ body_complete_eights = int(width * 8 * self.end / self.size)
66
+ body_bar_count = body_complete_eights // 8
67
+ body_eights_count = body_complete_eights % 8
68
+
69
+ # When start and end fall into the same cell, we ideally should render
70
+ # a symbol that's "center-aligned", but there is no good symbol in Unicode.
71
+ # In this case, we fall back to right-aligned block symbol for simplicity.
72
+
73
+ prefix = " " * prefix_bar_count
74
+ if prefix_eights_count:
75
+ prefix += BEGIN_BLOCK_ELEMENTS[prefix_eights_count]
76
+
77
+ body = FULL_BLOCK * body_bar_count
78
+ if body_eights_count:
79
+ body += END_BLOCK_ELEMENTS[body_eights_count]
80
+
81
+ suffix = " " * (width - len(body))
82
+
83
+ yield Segment(prefix + body[len(prefix) :] + suffix, self.style)
84
+ yield Segment.line()
85
+
86
+ def __rich_measure__(
87
+ self, console: Console, options: ConsoleOptions
88
+ ) -> Measurement:
89
+ return (
90
+ Measurement(self.width, self.width)
91
+ if self.width is not None
92
+ else Measurement(4, options.max_width)
93
+ )
llava/lib/python3.10/site-packages/pip/_vendor/rich/box.py ADDED
@@ -0,0 +1,480 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from typing import TYPE_CHECKING, Iterable, List
3
+
4
+ if sys.version_info >= (3, 8):
5
+ from typing import Literal
6
+ else:
7
+ from pip._vendor.typing_extensions import Literal # pragma: no cover
8
+
9
+
10
+ from ._loop import loop_last
11
+
12
+ if TYPE_CHECKING:
13
+ from pip._vendor.rich.console import ConsoleOptions
14
+
15
+
16
+ class Box:
17
+ """Defines characters to render boxes.
18
+
19
+ ┌─┬┐ top
20
+ │ ││ head
21
+ ├─┼┤ head_row
22
+ │ ││ mid
23
+ ├─┼┤ row
24
+ ├─┼┤ foot_row
25
+ │ ││ foot
26
+ └─┴┘ bottom
27
+
28
+ Args:
29
+ box (str): Characters making up box.
30
+ ascii (bool, optional): True if this box uses ascii characters only. Default is False.
31
+ """
32
+
33
+ def __init__(self, box: str, *, ascii: bool = False) -> None:
34
+ self._box = box
35
+ self.ascii = ascii
36
+ line1, line2, line3, line4, line5, line6, line7, line8 = box.splitlines()
37
+ # top
38
+ self.top_left, self.top, self.top_divider, self.top_right = iter(line1)
39
+ # head
40
+ self.head_left, _, self.head_vertical, self.head_right = iter(line2)
41
+ # head_row
42
+ (
43
+ self.head_row_left,
44
+ self.head_row_horizontal,
45
+ self.head_row_cross,
46
+ self.head_row_right,
47
+ ) = iter(line3)
48
+
49
+ # mid
50
+ self.mid_left, _, self.mid_vertical, self.mid_right = iter(line4)
51
+ # row
52
+ self.row_left, self.row_horizontal, self.row_cross, self.row_right = iter(line5)
53
+ # foot_row
54
+ (
55
+ self.foot_row_left,
56
+ self.foot_row_horizontal,
57
+ self.foot_row_cross,
58
+ self.foot_row_right,
59
+ ) = iter(line6)
60
+ # foot
61
+ self.foot_left, _, self.foot_vertical, self.foot_right = iter(line7)
62
+ # bottom
63
+ self.bottom_left, self.bottom, self.bottom_divider, self.bottom_right = iter(
64
+ line8
65
+ )
66
+
67
+ def __repr__(self) -> str:
68
+ return "Box(...)"
69
+
70
+ def __str__(self) -> str:
71
+ return self._box
72
+
73
+ def substitute(self, options: "ConsoleOptions", safe: bool = True) -> "Box":
74
+ """Substitute this box for another if it won't render due to platform issues.
75
+
76
+ Args:
77
+ options (ConsoleOptions): Console options used in rendering.
78
+ safe (bool, optional): Substitute this for another Box if there are known problems
79
+ displaying on the platform (currently only relevant on Windows). Default is True.
80
+
81
+ Returns:
82
+ Box: A different Box or the same Box.
83
+ """
84
+ box = self
85
+ if options.legacy_windows and safe:
86
+ box = LEGACY_WINDOWS_SUBSTITUTIONS.get(box, box)
87
+ if options.ascii_only and not box.ascii:
88
+ box = ASCII
89
+ return box
90
+
91
+ def get_plain_headed_box(self) -> "Box":
92
+ """If this box uses special characters for the borders of the header, then
93
+ return the equivalent box that does not.
94
+
95
+ Returns:
96
+ Box: The most similar Box that doesn't use header-specific box characters.
97
+ If the current Box already satisfies this criterion, then it's returned.
98
+ """
99
+ return PLAIN_HEADED_SUBSTITUTIONS.get(self, self)
100
+
101
+ def get_top(self, widths: Iterable[int]) -> str:
102
+ """Get the top of a simple box.
103
+
104
+ Args:
105
+ widths (List[int]): Widths of columns.
106
+
107
+ Returns:
108
+ str: A string of box characters.
109
+ """
110
+
111
+ parts: List[str] = []
112
+ append = parts.append
113
+ append(self.top_left)
114
+ for last, width in loop_last(widths):
115
+ append(self.top * width)
116
+ if not last:
117
+ append(self.top_divider)
118
+ append(self.top_right)
119
+ return "".join(parts)
120
+
121
+ def get_row(
122
+ self,
123
+ widths: Iterable[int],
124
+ level: Literal["head", "row", "foot", "mid"] = "row",
125
+ edge: bool = True,
126
+ ) -> str:
127
+ """Get the top of a simple box.
128
+
129
+ Args:
130
+ width (List[int]): Widths of columns.
131
+
132
+ Returns:
133
+ str: A string of box characters.
134
+ """
135
+ if level == "head":
136
+ left = self.head_row_left
137
+ horizontal = self.head_row_horizontal
138
+ cross = self.head_row_cross
139
+ right = self.head_row_right
140
+ elif level == "row":
141
+ left = self.row_left
142
+ horizontal = self.row_horizontal
143
+ cross = self.row_cross
144
+ right = self.row_right
145
+ elif level == "mid":
146
+ left = self.mid_left
147
+ horizontal = " "
148
+ cross = self.mid_vertical
149
+ right = self.mid_right
150
+ elif level == "foot":
151
+ left = self.foot_row_left
152
+ horizontal = self.foot_row_horizontal
153
+ cross = self.foot_row_cross
154
+ right = self.foot_row_right
155
+ else:
156
+ raise ValueError("level must be 'head', 'row' or 'foot'")
157
+
158
+ parts: List[str] = []
159
+ append = parts.append
160
+ if edge:
161
+ append(left)
162
+ for last, width in loop_last(widths):
163
+ append(horizontal * width)
164
+ if not last:
165
+ append(cross)
166
+ if edge:
167
+ append(right)
168
+ return "".join(parts)
169
+
170
+ def get_bottom(self, widths: Iterable[int]) -> str:
171
+ """Get the bottom of a simple box.
172
+
173
+ Args:
174
+ widths (List[int]): Widths of columns.
175
+
176
+ Returns:
177
+ str: A string of box characters.
178
+ """
179
+
180
+ parts: List[str] = []
181
+ append = parts.append
182
+ append(self.bottom_left)
183
+ for last, width in loop_last(widths):
184
+ append(self.bottom * width)
185
+ if not last:
186
+ append(self.bottom_divider)
187
+ append(self.bottom_right)
188
+ return "".join(parts)
189
+
190
+
191
+ # fmt: off
192
+ ASCII: Box = Box(
193
+ "+--+\n"
194
+ "| ||\n"
195
+ "|-+|\n"
196
+ "| ||\n"
197
+ "|-+|\n"
198
+ "|-+|\n"
199
+ "| ||\n"
200
+ "+--+\n",
201
+ ascii=True,
202
+ )
203
+
204
+ ASCII2: Box = Box(
205
+ "+-++\n"
206
+ "| ||\n"
207
+ "+-++\n"
208
+ "| ||\n"
209
+ "+-++\n"
210
+ "+-++\n"
211
+ "| ||\n"
212
+ "+-++\n",
213
+ ascii=True,
214
+ )
215
+
216
+ ASCII_DOUBLE_HEAD: Box = Box(
217
+ "+-++\n"
218
+ "| ||\n"
219
+ "+=++\n"
220
+ "| ||\n"
221
+ "+-++\n"
222
+ "+-++\n"
223
+ "| ||\n"
224
+ "+-++\n",
225
+ ascii=True,
226
+ )
227
+
228
+ SQUARE: Box = Box(
229
+ "┌─┬┐\n"
230
+ "│ ││\n"
231
+ "├─┼┤\n"
232
+ "│ ││\n"
233
+ "├─┼┤\n"
234
+ "├─┼┤\n"
235
+ "│ ││\n"
236
+ "└─┴┘\n"
237
+ )
238
+
239
+ SQUARE_DOUBLE_HEAD: Box = Box(
240
+ "┌─┬┐\n"
241
+ "│ ││\n"
242
+ "╞═╪╡\n"
243
+ "│ ││\n"
244
+ "├─┼┤\n"
245
+ "├─┼┤\n"
246
+ "│ ││\n"
247
+ "└─┴┘\n"
248
+ )
249
+
250
+ MINIMAL: Box = Box(
251
+ " ╷ \n"
252
+ " │ \n"
253
+ "╶─┼╴\n"
254
+ " │ \n"
255
+ "╶─┼╴\n"
256
+ "╶─┼╴\n"
257
+ " │ \n"
258
+ " ╵ \n"
259
+ )
260
+
261
+
262
+ MINIMAL_HEAVY_HEAD: Box = Box(
263
+ " ╷ \n"
264
+ " │ \n"
265
+ "╺━┿╸\n"
266
+ " │ \n"
267
+ "╶─┼╴\n"
268
+ "╶─┼╴\n"
269
+ " │ \n"
270
+ " ╵ \n"
271
+ )
272
+
273
+ MINIMAL_DOUBLE_HEAD: Box = Box(
274
+ " ╷ \n"
275
+ " │ \n"
276
+ " ═╪ \n"
277
+ " │ \n"
278
+ " ─┼ \n"
279
+ " ─┼ \n"
280
+ " │ \n"
281
+ " ╵ \n"
282
+ )
283
+
284
+
285
+ SIMPLE: Box = Box(
286
+ " \n"
287
+ " \n"
288
+ " ── \n"
289
+ " \n"
290
+ " \n"
291
+ " ── \n"
292
+ " \n"
293
+ " \n"
294
+ )
295
+
296
+ SIMPLE_HEAD: Box = Box(
297
+ " \n"
298
+ " \n"
299
+ " ── \n"
300
+ " \n"
301
+ " \n"
302
+ " \n"
303
+ " \n"
304
+ " \n"
305
+ )
306
+
307
+
308
+ SIMPLE_HEAVY: Box = Box(
309
+ " \n"
310
+ " \n"
311
+ " ━━ \n"
312
+ " \n"
313
+ " \n"
314
+ " ━━ \n"
315
+ " \n"
316
+ " \n"
317
+ )
318
+
319
+
320
+ HORIZONTALS: Box = Box(
321
+ " ── \n"
322
+ " \n"
323
+ " ── \n"
324
+ " \n"
325
+ " ── \n"
326
+ " ── \n"
327
+ " \n"
328
+ " ── \n"
329
+ )
330
+
331
+ ROUNDED: Box = Box(
332
+ "╭─┬╮\n"
333
+ "│ ││\n"
334
+ "├─┼┤\n"
335
+ "│ ││\n"
336
+ "├─┼┤\n"
337
+ "├─┼┤\n"
338
+ "│ ││\n"
339
+ "╰─┴╯\n"
340
+ )
341
+
342
+ HEAVY: Box = Box(
343
+ "┏━┳┓\n"
344
+ "┃ ┃┃\n"
345
+ "┣━╋┫\n"
346
+ "┃ ┃┃\n"
347
+ "┣━╋┫\n"
348
+ "┣━╋┫\n"
349
+ "┃ ┃┃\n"
350
+ "┗━┻┛\n"
351
+ )
352
+
353
+ HEAVY_EDGE: Box = Box(
354
+ "┏━┯┓\n"
355
+ "┃ │┃\n"
356
+ "┠─┼┨\n"
357
+ "┃ │┃\n"
358
+ "┠─┼┨\n"
359
+ "┠─┼┨\n"
360
+ "┃ │┃\n"
361
+ "┗━┷┛\n"
362
+ )
363
+
364
+ HEAVY_HEAD: Box = Box(
365
+ "┏━┳┓\n"
366
+ "┃ ┃┃\n"
367
+ "┡━╇┩\n"
368
+ "│ ││\n"
369
+ "├─┼┤\n"
370
+ "├─┼┤\n"
371
+ "│ ││\n"
372
+ "└─┴┘\n"
373
+ )
374
+
375
+ DOUBLE: Box = Box(
376
+ "╔═╦╗\n"
377
+ "║ ║║\n"
378
+ "╠═╬╣\n"
379
+ "║ ║║\n"
380
+ "╠═╬╣\n"
381
+ "╠═╬╣\n"
382
+ "║ ║║\n"
383
+ "╚═╩╝\n"
384
+ )
385
+
386
+ DOUBLE_EDGE: Box = Box(
387
+ "╔═╤╗\n"
388
+ "║ │║\n"
389
+ "╟─┼╢\n"
390
+ "║ │║\n"
391
+ "╟─┼╢\n"
392
+ "╟─┼╢\n"
393
+ "║ │║\n"
394
+ "╚═╧╝\n"
395
+ )
396
+
397
+ MARKDOWN: Box = Box(
398
+ " \n"
399
+ "| ||\n"
400
+ "|-||\n"
401
+ "| ||\n"
402
+ "|-||\n"
403
+ "|-||\n"
404
+ "| ||\n"
405
+ " \n",
406
+ ascii=True,
407
+ )
408
+ # fmt: on
409
+
410
+ # Map Boxes that don't render with raster fonts on to equivalent that do
411
+ LEGACY_WINDOWS_SUBSTITUTIONS = {
412
+ ROUNDED: SQUARE,
413
+ MINIMAL_HEAVY_HEAD: MINIMAL,
414
+ SIMPLE_HEAVY: SIMPLE,
415
+ HEAVY: SQUARE,
416
+ HEAVY_EDGE: SQUARE,
417
+ HEAVY_HEAD: SQUARE,
418
+ }
419
+
420
+ # Map headed boxes to their headerless equivalents
421
+ PLAIN_HEADED_SUBSTITUTIONS = {
422
+ HEAVY_HEAD: SQUARE,
423
+ SQUARE_DOUBLE_HEAD: SQUARE,
424
+ MINIMAL_DOUBLE_HEAD: MINIMAL,
425
+ MINIMAL_HEAVY_HEAD: MINIMAL,
426
+ ASCII_DOUBLE_HEAD: ASCII2,
427
+ }
428
+
429
+
430
+ if __name__ == "__main__": # pragma: no cover
431
+ from pip._vendor.rich.columns import Columns
432
+ from pip._vendor.rich.panel import Panel
433
+
434
+ from . import box as box
435
+ from .console import Console
436
+ from .table import Table
437
+ from .text import Text
438
+
439
+ console = Console(record=True)
440
+
441
+ BOXES = [
442
+ "ASCII",
443
+ "ASCII2",
444
+ "ASCII_DOUBLE_HEAD",
445
+ "SQUARE",
446
+ "SQUARE_DOUBLE_HEAD",
447
+ "MINIMAL",
448
+ "MINIMAL_HEAVY_HEAD",
449
+ "MINIMAL_DOUBLE_HEAD",
450
+ "SIMPLE",
451
+ "SIMPLE_HEAD",
452
+ "SIMPLE_HEAVY",
453
+ "HORIZONTALS",
454
+ "ROUNDED",
455
+ "HEAVY",
456
+ "HEAVY_EDGE",
457
+ "HEAVY_HEAD",
458
+ "DOUBLE",
459
+ "DOUBLE_EDGE",
460
+ "MARKDOWN",
461
+ ]
462
+
463
+ console.print(Panel("[bold green]Box Constants", style="green"), justify="center")
464
+ console.print()
465
+
466
+ columns = Columns(expand=True, padding=2)
467
+ for box_name in sorted(BOXES):
468
+ table = Table(
469
+ show_footer=True, style="dim", border_style="not dim", expand=True
470
+ )
471
+ table.add_column("Header 1", "Footer 1")
472
+ table.add_column("Header 2", "Footer 2")
473
+ table.add_row("Cell", "Cell")
474
+ table.add_row("Cell", "Cell")
475
+ table.box = getattr(box, box_name)
476
+ table.title = Text(f"box.{box_name}", style="magenta")
477
+ columns.add_renderable(table)
478
+ console.print(columns)
479
+
480
+ # console.save_svg("box.svg")
llava/lib/python3.10/site-packages/pip/_vendor/rich/control.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import time
3
+ from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Union
4
+
5
+ if sys.version_info >= (3, 8):
6
+ from typing import Final
7
+ else:
8
+ from pip._vendor.typing_extensions import Final # pragma: no cover
9
+
10
+ from .segment import ControlCode, ControlType, Segment
11
+
12
+ if TYPE_CHECKING:
13
+ from .console import Console, ConsoleOptions, RenderResult
14
+
15
+ STRIP_CONTROL_CODES: Final = [
16
+ 7, # Bell
17
+ 8, # Backspace
18
+ 11, # Vertical tab
19
+ 12, # Form feed
20
+ 13, # Carriage return
21
+ ]
22
+ _CONTROL_STRIP_TRANSLATE: Final = {
23
+ _codepoint: None for _codepoint in STRIP_CONTROL_CODES
24
+ }
25
+
26
+ CONTROL_ESCAPE: Final = {
27
+ 7: "\\a",
28
+ 8: "\\b",
29
+ 11: "\\v",
30
+ 12: "\\f",
31
+ 13: "\\r",
32
+ }
33
+
34
+ CONTROL_CODES_FORMAT: Dict[int, Callable[..., str]] = {
35
+ ControlType.BELL: lambda: "\x07",
36
+ ControlType.CARRIAGE_RETURN: lambda: "\r",
37
+ ControlType.HOME: lambda: "\x1b[H",
38
+ ControlType.CLEAR: lambda: "\x1b[2J",
39
+ ControlType.ENABLE_ALT_SCREEN: lambda: "\x1b[?1049h",
40
+ ControlType.DISABLE_ALT_SCREEN: lambda: "\x1b[?1049l",
41
+ ControlType.SHOW_CURSOR: lambda: "\x1b[?25h",
42
+ ControlType.HIDE_CURSOR: lambda: "\x1b[?25l",
43
+ ControlType.CURSOR_UP: lambda param: f"\x1b[{param}A",
44
+ ControlType.CURSOR_DOWN: lambda param: f"\x1b[{param}B",
45
+ ControlType.CURSOR_FORWARD: lambda param: f"\x1b[{param}C",
46
+ ControlType.CURSOR_BACKWARD: lambda param: f"\x1b[{param}D",
47
+ ControlType.CURSOR_MOVE_TO_COLUMN: lambda param: f"\x1b[{param+1}G",
48
+ ControlType.ERASE_IN_LINE: lambda param: f"\x1b[{param}K",
49
+ ControlType.CURSOR_MOVE_TO: lambda x, y: f"\x1b[{y+1};{x+1}H",
50
+ ControlType.SET_WINDOW_TITLE: lambda title: f"\x1b]0;{title}\x07",
51
+ }
52
+
53
+
54
+ class Control:
55
+ """A renderable that inserts a control code (non printable but may move cursor).
56
+
57
+ Args:
58
+ *codes (str): Positional arguments are either a :class:`~rich.segment.ControlType` enum or a
59
+ tuple of ControlType and an integer parameter
60
+ """
61
+
62
+ __slots__ = ["segment"]
63
+
64
+ def __init__(self, *codes: Union[ControlType, ControlCode]) -> None:
65
+ control_codes: List[ControlCode] = [
66
+ (code,) if isinstance(code, ControlType) else code for code in codes
67
+ ]
68
+ _format_map = CONTROL_CODES_FORMAT
69
+ rendered_codes = "".join(
70
+ _format_map[code](*parameters) for code, *parameters in control_codes
71
+ )
72
+ self.segment = Segment(rendered_codes, None, control_codes)
73
+
74
+ @classmethod
75
+ def bell(cls) -> "Control":
76
+ """Ring the 'bell'."""
77
+ return cls(ControlType.BELL)
78
+
79
+ @classmethod
80
+ def home(cls) -> "Control":
81
+ """Move cursor to 'home' position."""
82
+ return cls(ControlType.HOME)
83
+
84
+ @classmethod
85
+ def move(cls, x: int = 0, y: int = 0) -> "Control":
86
+ """Move cursor relative to current position.
87
+
88
+ Args:
89
+ x (int): X offset.
90
+ y (int): Y offset.
91
+
92
+ Returns:
93
+ ~Control: Control object.
94
+
95
+ """
96
+
97
+ def get_codes() -> Iterable[ControlCode]:
98
+ control = ControlType
99
+ if x:
100
+ yield (
101
+ control.CURSOR_FORWARD if x > 0 else control.CURSOR_BACKWARD,
102
+ abs(x),
103
+ )
104
+ if y:
105
+ yield (
106
+ control.CURSOR_DOWN if y > 0 else control.CURSOR_UP,
107
+ abs(y),
108
+ )
109
+
110
+ control = cls(*get_codes())
111
+ return control
112
+
113
+ @classmethod
114
+ def move_to_column(cls, x: int, y: int = 0) -> "Control":
115
+ """Move to the given column, optionally add offset to row.
116
+
117
+ Returns:
118
+ x (int): absolute x (column)
119
+ y (int): optional y offset (row)
120
+
121
+ Returns:
122
+ ~Control: Control object.
123
+ """
124
+
125
+ return (
126
+ cls(
127
+ (ControlType.CURSOR_MOVE_TO_COLUMN, x),
128
+ (
129
+ ControlType.CURSOR_DOWN if y > 0 else ControlType.CURSOR_UP,
130
+ abs(y),
131
+ ),
132
+ )
133
+ if y
134
+ else cls((ControlType.CURSOR_MOVE_TO_COLUMN, x))
135
+ )
136
+
137
+ @classmethod
138
+ def move_to(cls, x: int, y: int) -> "Control":
139
+ """Move cursor to absolute position.
140
+
141
+ Args:
142
+ x (int): x offset (column)
143
+ y (int): y offset (row)
144
+
145
+ Returns:
146
+ ~Control: Control object.
147
+ """
148
+ return cls((ControlType.CURSOR_MOVE_TO, x, y))
149
+
150
+ @classmethod
151
+ def clear(cls) -> "Control":
152
+ """Clear the screen."""
153
+ return cls(ControlType.CLEAR)
154
+
155
+ @classmethod
156
+ def show_cursor(cls, show: bool) -> "Control":
157
+ """Show or hide the cursor."""
158
+ return cls(ControlType.SHOW_CURSOR if show else ControlType.HIDE_CURSOR)
159
+
160
+ @classmethod
161
+ def alt_screen(cls, enable: bool) -> "Control":
162
+ """Enable or disable alt screen."""
163
+ if enable:
164
+ return cls(ControlType.ENABLE_ALT_SCREEN, ControlType.HOME)
165
+ else:
166
+ return cls(ControlType.DISABLE_ALT_SCREEN)
167
+
168
+ @classmethod
169
+ def title(cls, title: str) -> "Control":
170
+ """Set the terminal window title
171
+
172
+ Args:
173
+ title (str): The new terminal window title
174
+ """
175
+ return cls((ControlType.SET_WINDOW_TITLE, title))
176
+
177
+ def __str__(self) -> str:
178
+ return self.segment.text
179
+
180
+ def __rich_console__(
181
+ self, console: "Console", options: "ConsoleOptions"
182
+ ) -> "RenderResult":
183
+ if self.segment.text:
184
+ yield self.segment
185
+
186
+
187
+ def strip_control_codes(
188
+ text: str, _translate_table: Dict[int, None] = _CONTROL_STRIP_TRANSLATE
189
+ ) -> str:
190
+ """Remove control codes from text.
191
+
192
+ Args:
193
+ text (str): A string possibly contain control codes.
194
+
195
+ Returns:
196
+ str: String with control codes removed.
197
+ """
198
+ return text.translate(_translate_table)
199
+
200
+
201
+ def escape_control_codes(
202
+ text: str,
203
+ _translate_table: Dict[int, str] = CONTROL_ESCAPE,
204
+ ) -> str:
205
+ """Replace control codes with their "escaped" equivalent in the given text.
206
+ (e.g. "\b" becomes "\\b")
207
+
208
+ Args:
209
+ text (str): A string possibly containing control codes.
210
+
211
+ Returns:
212
+ str: String with control codes replaced with their escaped version.
213
+ """
214
+ return text.translate(_translate_table)
215
+
216
+
217
+ if __name__ == "__main__": # pragma: no cover
218
+ from pip._vendor.rich.console import Console
219
+
220
+ console = Console()
221
+ console.print("Look at the title of your terminal window ^")
222
+ # console.print(Control((ControlType.SET_WINDOW_TITLE, "Hello, world!")))
223
+ for i in range(10):
224
+ console.set_window_title("🚀 Loading" + "." * i)
225
+ time.sleep(0.5)
llava/lib/python3.10/site-packages/pip/_vendor/rich/highlighter.py ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from abc import ABC, abstractmethod
3
+ from typing import List, Union
4
+
5
+ from .text import Span, Text
6
+
7
+
8
+ def _combine_regex(*regexes: str) -> str:
9
+ """Combine a number of regexes in to a single regex.
10
+
11
+ Returns:
12
+ str: New regex with all regexes ORed together.
13
+ """
14
+ return "|".join(regexes)
15
+
16
+
17
+ class Highlighter(ABC):
18
+ """Abstract base class for highlighters."""
19
+
20
+ def __call__(self, text: Union[str, Text]) -> Text:
21
+ """Highlight a str or Text instance.
22
+
23
+ Args:
24
+ text (Union[str, ~Text]): Text to highlight.
25
+
26
+ Raises:
27
+ TypeError: If not called with text or str.
28
+
29
+ Returns:
30
+ Text: A test instance with highlighting applied.
31
+ """
32
+ if isinstance(text, str):
33
+ highlight_text = Text(text)
34
+ elif isinstance(text, Text):
35
+ highlight_text = text.copy()
36
+ else:
37
+ raise TypeError(f"str or Text instance required, not {text!r}")
38
+ self.highlight(highlight_text)
39
+ return highlight_text
40
+
41
+ @abstractmethod
42
+ def highlight(self, text: Text) -> None:
43
+ """Apply highlighting in place to text.
44
+
45
+ Args:
46
+ text (~Text): A text object highlight.
47
+ """
48
+
49
+
50
+ class NullHighlighter(Highlighter):
51
+ """A highlighter object that doesn't highlight.
52
+
53
+ May be used to disable highlighting entirely.
54
+
55
+ """
56
+
57
+ def highlight(self, text: Text) -> None:
58
+ """Nothing to do"""
59
+
60
+
61
+ class RegexHighlighter(Highlighter):
62
+ """Applies highlighting from a list of regular expressions."""
63
+
64
+ highlights: List[str] = []
65
+ base_style: str = ""
66
+
67
+ def highlight(self, text: Text) -> None:
68
+ """Highlight :class:`rich.text.Text` using regular expressions.
69
+
70
+ Args:
71
+ text (~Text): Text to highlighted.
72
+
73
+ """
74
+
75
+ highlight_regex = text.highlight_regex
76
+ for re_highlight in self.highlights:
77
+ highlight_regex(re_highlight, style_prefix=self.base_style)
78
+
79
+
80
+ class ReprHighlighter(RegexHighlighter):
81
+ """Highlights the text typically produced from ``__repr__`` methods."""
82
+
83
+ base_style = "repr."
84
+ highlights = [
85
+ r"(?P<tag_start><)(?P<tag_name>[-\w.:|]*)(?P<tag_contents>[\w\W]*)(?P<tag_end>>)",
86
+ r'(?P<attrib_name>[\w_]{1,50})=(?P<attrib_value>"?[\w_]+"?)?',
87
+ r"(?P<brace>[][{}()])",
88
+ _combine_regex(
89
+ r"(?P<ipv4>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})",
90
+ r"(?P<ipv6>([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4})",
91
+ r"(?P<eui64>(?:[0-9A-Fa-f]{1,2}-){7}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{1,2}:){7}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{4}\.){3}[0-9A-Fa-f]{4})",
92
+ r"(?P<eui48>(?:[0-9A-Fa-f]{1,2}-){5}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{1,2}:){5}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4})",
93
+ r"(?P<uuid>[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})",
94
+ r"(?P<call>[\w.]*?)\(",
95
+ r"\b(?P<bool_true>True)\b|\b(?P<bool_false>False)\b|\b(?P<none>None)\b",
96
+ r"(?P<ellipsis>\.\.\.)",
97
+ r"(?P<number_complex>(?<!\w)(?:\-?[0-9]+\.?[0-9]*(?:e[-+]?\d+?)?)(?:[-+](?:[0-9]+\.?[0-9]*(?:e[-+]?\d+)?))?j)",
98
+ r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[-+]?\d+?)?\b|0x[0-9a-fA-F]*)",
99
+ r"(?P<path>\B(/[-\w._+]+)*\/)(?P<filename>[-\w._+]*)?",
100
+ r"(?<![\\\w])(?P<str>b?'''.*?(?<!\\)'''|b?'.*?(?<!\\)'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
101
+ r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~@]*)",
102
+ ),
103
+ ]
104
+
105
+
106
+ class JSONHighlighter(RegexHighlighter):
107
+ """Highlights JSON"""
108
+
109
+ # Captures the start and end of JSON strings, handling escaped quotes
110
+ JSON_STR = r"(?<![\\\w])(?P<str>b?\".*?(?<!\\)\")"
111
+ JSON_WHITESPACE = {" ", "\n", "\r", "\t"}
112
+
113
+ base_style = "json."
114
+ highlights = [
115
+ _combine_regex(
116
+ r"(?P<brace>[\{\[\(\)\]\}])",
117
+ r"\b(?P<bool_true>true)\b|\b(?P<bool_false>false)\b|\b(?P<null>null)\b",
118
+ r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[\-\+]?\d+?)?\b|0x[0-9a-fA-F]*)",
119
+ JSON_STR,
120
+ ),
121
+ ]
122
+
123
+ def highlight(self, text: Text) -> None:
124
+ super().highlight(text)
125
+
126
+ # Additional work to handle highlighting JSON keys
127
+ plain = text.plain
128
+ append = text.spans.append
129
+ whitespace = self.JSON_WHITESPACE
130
+ for match in re.finditer(self.JSON_STR, plain):
131
+ start, end = match.span()
132
+ cursor = end
133
+ while cursor < len(plain):
134
+ char = plain[cursor]
135
+ cursor += 1
136
+ if char == ":":
137
+ append(Span(start, end, "json.key"))
138
+ elif char in whitespace:
139
+ continue
140
+ break
141
+
142
+
143
+ class ISO8601Highlighter(RegexHighlighter):
144
+ """Highlights the ISO8601 date time strings.
145
+ Regex reference: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html
146
+ """
147
+
148
+ base_style = "iso8601."
149
+ highlights = [
150
+ #
151
+ # Dates
152
+ #
153
+ # Calendar month (e.g. 2008-08). The hyphen is required
154
+ r"^(?P<year>[0-9]{4})-(?P<month>1[0-2]|0[1-9])$",
155
+ # Calendar date w/o hyphens (e.g. 20080830)
156
+ r"^(?P<date>(?P<year>[0-9]{4})(?P<month>1[0-2]|0[1-9])(?P<day>3[01]|0[1-9]|[12][0-9]))$",
157
+ # Ordinal date (e.g. 2008-243). The hyphen is optional
158
+ r"^(?P<date>(?P<year>[0-9]{4})-?(?P<day>36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9]))$",
159
+ #
160
+ # Weeks
161
+ #
162
+ # Week of the year (e.g., 2008-W35). The hyphen is optional
163
+ r"^(?P<date>(?P<year>[0-9]{4})-?W(?P<week>5[0-3]|[1-4][0-9]|0[1-9]))$",
164
+ # Week date (e.g., 2008-W35-6). The hyphens are optional
165
+ r"^(?P<date>(?P<year>[0-9]{4})-?W(?P<week>5[0-3]|[1-4][0-9]|0[1-9])-?(?P<day>[1-7]))$",
166
+ #
167
+ # Times
168
+ #
169
+ # Hours and minutes (e.g., 17:21). The colon is optional
170
+ r"^(?P<time>(?P<hour>2[0-3]|[01][0-9]):?(?P<minute>[0-5][0-9]))$",
171
+ # Hours, minutes, and seconds w/o colons (e.g., 172159)
172
+ r"^(?P<time>(?P<hour>2[0-3]|[01][0-9])(?P<minute>[0-5][0-9])(?P<second>[0-5][0-9]))$",
173
+ # Time zone designator (e.g., Z, +07 or +07:00). The colons and the minutes are optional
174
+ r"^(?P<timezone>(Z|[+-](?:2[0-3]|[01][0-9])(?::?(?:[0-5][0-9]))?))$",
175
+ # Hours, minutes, and seconds with time zone designator (e.g., 17:21:59+07:00).
176
+ # All the colons are optional. The minutes in the time zone designator are also optional
177
+ r"^(?P<time>(?P<hour>2[0-3]|[01][0-9])(?P<minute>[0-5][0-9])(?P<second>[0-5][0-9]))(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9])(?::?(?:[0-5][0-9]))?)$",
178
+ #
179
+ # Date and Time
180
+ #
181
+ # Calendar date with hours, minutes, and seconds (e.g., 2008-08-30 17:21:59 or 20080830 172159).
182
+ # A space is required between the date and the time. The hyphens and colons are optional.
183
+ # This regex matches dates and times that specify some hyphens or colons but omit others.
184
+ # This does not follow ISO 8601
185
+ r"^(?P<date>(?P<year>[0-9]{4})(?P<hyphen>-)?(?P<month>1[0-2]|0[1-9])(?(hyphen)-)(?P<day>3[01]|0[1-9]|[12][0-9])) (?P<time>(?P<hour>2[0-3]|[01][0-9])(?(hyphen):)(?P<minute>[0-5][0-9])(?(hyphen):)(?P<second>[0-5][0-9]))$",
186
+ #
187
+ # XML Schema dates and times
188
+ #
189
+ # Date, with optional time zone (e.g., 2008-08-30 or 2008-08-30+07:00).
190
+ # Hyphens are required. This is the XML Schema 'date' type
191
+ r"^(?P<date>(?P<year>-?(?:[1-9][0-9]*)?[0-9]{4})-(?P<month>1[0-2]|0[1-9])-(?P<day>3[01]|0[1-9]|[12][0-9]))(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$",
192
+ # Time, with optional fractional seconds and time zone (e.g., 01:45:36 or 01:45:36.123+07:00).
193
+ # There is no limit on the number of digits for the fractional seconds. This is the XML Schema 'time' type
194
+ r"^(?P<time>(?P<hour>2[0-3]|[01][0-9]):(?P<minute>[0-5][0-9]):(?P<second>[0-5][0-9])(?P<frac>\.[0-9]+)?)(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$",
195
+ # Date and time, with optional fractional seconds and time zone (e.g., 2008-08-30T01:45:36 or 2008-08-30T01:45:36.123Z).
196
+ # This is the XML Schema 'dateTime' type
197
+ r"^(?P<date>(?P<year>-?(?:[1-9][0-9]*)?[0-9]{4})-(?P<month>1[0-2]|0[1-9])-(?P<day>3[01]|0[1-9]|[12][0-9]))T(?P<time>(?P<hour>2[0-3]|[01][0-9]):(?P<minute>[0-5][0-9]):(?P<second>[0-5][0-9])(?P<ms>\.[0-9]+)?)(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$",
198
+ ]
199
+
200
+
201
+ if __name__ == "__main__": # pragma: no cover
202
+ from .console import Console
203
+
204
+ console = Console()
205
+ console.print("[bold green]hello world![/bold green]")
206
+ console.print("'[bold green]hello world![/bold green]'")
207
+
208
+ console.print(" /foo")
209
+ console.print("/foo/")
210
+ console.print("/foo/bar")
211
+ console.print("foo/bar/baz")
212
+
213
+ console.print("/foo/bar/baz?foo=bar+egg&egg=baz")
214
+ console.print("/foo/bar/baz/")
215
+ console.print("/foo/bar/baz/egg")
216
+ console.print("/foo/bar/baz/egg.py")
217
+ console.print("/foo/bar/baz/egg.py word")
218
+ console.print(" /foo/bar/baz/egg.py word")
219
+ console.print("foo /foo/bar/baz/egg.py word")
220
+ console.print("foo /foo/bar/ba._++z/egg+.py word")
221
+ console.print("https://example.org?foo=bar#header")
222
+
223
+ console.print(1234567.34)
224
+ console.print(1 / 2)
225
+ console.print(-1 / 123123123123)
226
+
227
+ console.print(
228
+ "127.0.1.1 bar 192.168.1.4 2001:0db8:85a3:0000:0000:8a2e:0370:7334 foo"
229
+ )
230
+ import json
231
+
232
+ console.print_json(json.dumps(obj={"name": "apple", "count": 1}), indent=None)
llava/lib/python3.10/site-packages/pip/_vendor/rich/json.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from json import loads, dumps
3
+ from typing import Any, Callable, Optional, Union
4
+
5
+ from .text import Text
6
+ from .highlighter import JSONHighlighter, NullHighlighter
7
+
8
+
9
+ class JSON:
10
+ """A renderable which pretty prints JSON.
11
+
12
+ Args:
13
+ json (str): JSON encoded data.
14
+ indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
15
+ highlight (bool, optional): Enable highlighting. Defaults to True.
16
+ skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
17
+ ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
18
+ check_circular (bool, optional): Check for circular references. Defaults to True.
19
+ allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
20
+ default (Callable, optional): A callable that converts values that can not be encoded
21
+ in to something that can be JSON encoded. Defaults to None.
22
+ sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
23
+ """
24
+
25
+ def __init__(
26
+ self,
27
+ json: str,
28
+ indent: Union[None, int, str] = 2,
29
+ highlight: bool = True,
30
+ skip_keys: bool = False,
31
+ ensure_ascii: bool = False,
32
+ check_circular: bool = True,
33
+ allow_nan: bool = True,
34
+ default: Optional[Callable[[Any], Any]] = None,
35
+ sort_keys: bool = False,
36
+ ) -> None:
37
+ data = loads(json)
38
+ json = dumps(
39
+ data,
40
+ indent=indent,
41
+ skipkeys=skip_keys,
42
+ ensure_ascii=ensure_ascii,
43
+ check_circular=check_circular,
44
+ allow_nan=allow_nan,
45
+ default=default,
46
+ sort_keys=sort_keys,
47
+ )
48
+ highlighter = JSONHighlighter() if highlight else NullHighlighter()
49
+ self.text = highlighter(json)
50
+ self.text.no_wrap = True
51
+ self.text.overflow = None
52
+
53
+ @classmethod
54
+ def from_data(
55
+ cls,
56
+ data: Any,
57
+ indent: Union[None, int, str] = 2,
58
+ highlight: bool = True,
59
+ skip_keys: bool = False,
60
+ ensure_ascii: bool = False,
61
+ check_circular: bool = True,
62
+ allow_nan: bool = True,
63
+ default: Optional[Callable[[Any], Any]] = None,
64
+ sort_keys: bool = False,
65
+ ) -> "JSON":
66
+ """Encodes a JSON object from arbitrary data.
67
+
68
+ Args:
69
+ data (Any): An object that may be encoded in to JSON
70
+ indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
71
+ highlight (bool, optional): Enable highlighting. Defaults to True.
72
+ default (Callable, optional): Optional callable which will be called for objects that cannot be serialized. Defaults to None.
73
+ skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
74
+ ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
75
+ check_circular (bool, optional): Check for circular references. Defaults to True.
76
+ allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
77
+ default (Callable, optional): A callable that converts values that can not be encoded
78
+ in to something that can be JSON encoded. Defaults to None.
79
+ sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
80
+
81
+ Returns:
82
+ JSON: New JSON object from the given data.
83
+ """
84
+ json_instance: "JSON" = cls.__new__(cls)
85
+ json = dumps(
86
+ data,
87
+ indent=indent,
88
+ skipkeys=skip_keys,
89
+ ensure_ascii=ensure_ascii,
90
+ check_circular=check_circular,
91
+ allow_nan=allow_nan,
92
+ default=default,
93
+ sort_keys=sort_keys,
94
+ )
95
+ highlighter = JSONHighlighter() if highlight else NullHighlighter()
96
+ json_instance.text = highlighter(json)
97
+ json_instance.text.no_wrap = True
98
+ json_instance.text.overflow = None
99
+ return json_instance
100
+
101
+ def __rich__(self) -> Text:
102
+ return self.text
103
+
104
+
105
+ if __name__ == "__main__":
106
+ import argparse
107
+ import sys
108
+
109
+ parser = argparse.ArgumentParser(description="Pretty print json")
110
+ parser.add_argument(
111
+ "path",
112
+ metavar="PATH",
113
+ help="path to file, or - for stdin",
114
+ )
115
+ parser.add_argument(
116
+ "-i",
117
+ "--indent",
118
+ metavar="SPACES",
119
+ type=int,
120
+ help="Number of spaces in an indent",
121
+ default=2,
122
+ )
123
+ args = parser.parse_args()
124
+
125
+ from pip._vendor.rich.console import Console
126
+
127
+ console = Console()
128
+ error_console = Console(stderr=True)
129
+
130
+ try:
131
+ if args.path == "-":
132
+ json_data = sys.stdin.read()
133
+ else:
134
+ json_data = Path(args.path).read_text()
135
+ except Exception as error:
136
+ error_console.print(f"Unable to read {args.path!r}; {error}")
137
+ sys.exit(-1)
138
+
139
+ console.print(JSON(json_data, indent=args.indent), soft_wrap=True)
llava/lib/python3.10/site-packages/pip/_vendor/rich/palette.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from math import sqrt
2
+ from functools import lru_cache
3
+ from typing import Sequence, Tuple, TYPE_CHECKING
4
+
5
+ from .color_triplet import ColorTriplet
6
+
7
+ if TYPE_CHECKING:
8
+ from pip._vendor.rich.table import Table
9
+
10
+
11
+ class Palette:
12
+ """A palette of available colors."""
13
+
14
+ def __init__(self, colors: Sequence[Tuple[int, int, int]]):
15
+ self._colors = colors
16
+
17
+ def __getitem__(self, number: int) -> ColorTriplet:
18
+ return ColorTriplet(*self._colors[number])
19
+
20
+ def __rich__(self) -> "Table":
21
+ from pip._vendor.rich.color import Color
22
+ from pip._vendor.rich.style import Style
23
+ from pip._vendor.rich.text import Text
24
+ from pip._vendor.rich.table import Table
25
+
26
+ table = Table(
27
+ "index",
28
+ "RGB",
29
+ "Color",
30
+ title="Palette",
31
+ caption=f"{len(self._colors)} colors",
32
+ highlight=True,
33
+ caption_justify="right",
34
+ )
35
+ for index, color in enumerate(self._colors):
36
+ table.add_row(
37
+ str(index),
38
+ repr(color),
39
+ Text(" " * 16, style=Style(bgcolor=Color.from_rgb(*color))),
40
+ )
41
+ return table
42
+
43
+ # This is somewhat inefficient and needs caching
44
+ @lru_cache(maxsize=1024)
45
+ def match(self, color: Tuple[int, int, int]) -> int:
46
+ """Find a color from a palette that most closely matches a given color.
47
+
48
+ Args:
49
+ color (Tuple[int, int, int]): RGB components in range 0 > 255.
50
+
51
+ Returns:
52
+ int: Index of closes matching color.
53
+ """
54
+ red1, green1, blue1 = color
55
+ _sqrt = sqrt
56
+ get_color = self._colors.__getitem__
57
+
58
+ def get_color_distance(index: int) -> float:
59
+ """Get the distance to a color."""
60
+ red2, green2, blue2 = get_color(index)
61
+ red_mean = (red1 + red2) // 2
62
+ red = red1 - red2
63
+ green = green1 - green2
64
+ blue = blue1 - blue2
65
+ return _sqrt(
66
+ (((512 + red_mean) * red * red) >> 8)
67
+ + 4 * green * green
68
+ + (((767 - red_mean) * blue * blue) >> 8)
69
+ )
70
+
71
+ min_index = min(range(len(self._colors)), key=get_color_distance)
72
+ return min_index
73
+
74
+
75
+ if __name__ == "__main__": # pragma: no cover
76
+ import colorsys
77
+ from typing import Iterable
78
+ from pip._vendor.rich.color import Color
79
+ from pip._vendor.rich.console import Console, ConsoleOptions
80
+ from pip._vendor.rich.segment import Segment
81
+ from pip._vendor.rich.style import Style
82
+
83
+ class ColorBox:
84
+ def __rich_console__(
85
+ self, console: Console, options: ConsoleOptions
86
+ ) -> Iterable[Segment]:
87
+ height = console.size.height - 3
88
+ for y in range(0, height):
89
+ for x in range(options.max_width):
90
+ h = x / options.max_width
91
+ l = y / (height + 1)
92
+ r1, g1, b1 = colorsys.hls_to_rgb(h, l, 1.0)
93
+ r2, g2, b2 = colorsys.hls_to_rgb(h, l + (1 / height / 2), 1.0)
94
+ bgcolor = Color.from_rgb(r1 * 255, g1 * 255, b1 * 255)
95
+ color = Color.from_rgb(r2 * 255, g2 * 255, b2 * 255)
96
+ yield Segment("▄", Style(color=color, bgcolor=bgcolor))
97
+ yield Segment.line()
98
+
99
+ console = Console()
100
+ console.print(ColorBox())
llava/lib/python3.10/site-packages/pip/_vendor/rich/panel.py ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import TYPE_CHECKING, Optional
2
+
3
+ from .align import AlignMethod
4
+ from .box import ROUNDED, Box
5
+ from .cells import cell_len
6
+ from .jupyter import JupyterMixin
7
+ from .measure import Measurement, measure_renderables
8
+ from .padding import Padding, PaddingDimensions
9
+ from .segment import Segment
10
+ from .style import Style, StyleType
11
+ from .text import Text, TextType
12
+
13
+ if TYPE_CHECKING:
14
+ from .console import Console, ConsoleOptions, RenderableType, RenderResult
15
+
16
+
17
+ class Panel(JupyterMixin):
18
+ """A console renderable that draws a border around its contents.
19
+
20
+ Example:
21
+ >>> console.print(Panel("Hello, World!"))
22
+
23
+ Args:
24
+ renderable (RenderableType): A console renderable object.
25
+ box (Box, optional): A Box instance that defines the look of the border (see :ref:`appendix_box`. Defaults to box.ROUNDED.
26
+ title (Optional[TextType], optional): Optional title displayed in panel header. Defaults to None.
27
+ title_align (AlignMethod, optional): Alignment of title. Defaults to "center".
28
+ subtitle (Optional[TextType], optional): Optional subtitle displayed in panel footer. Defaults to None.
29
+ subtitle_align (AlignMethod, optional): Alignment of subtitle. Defaults to "center".
30
+ safe_box (bool, optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.
31
+ expand (bool, optional): If True the panel will stretch to fill the console width, otherwise it will be sized to fit the contents. Defaults to True.
32
+ style (str, optional): The style of the panel (border and contents). Defaults to "none".
33
+ border_style (str, optional): The style of the border. Defaults to "none".
34
+ width (Optional[int], optional): Optional width of panel. Defaults to None to auto-detect.
35
+ height (Optional[int], optional): Optional height of panel. Defaults to None to auto-detect.
36
+ padding (Optional[PaddingDimensions]): Optional padding around renderable. Defaults to 0.
37
+ highlight (bool, optional): Enable automatic highlighting of panel title (if str). Defaults to False.
38
+ """
39
+
40
+ def __init__(
41
+ self,
42
+ renderable: "RenderableType",
43
+ box: Box = ROUNDED,
44
+ *,
45
+ title: Optional[TextType] = None,
46
+ title_align: AlignMethod = "center",
47
+ subtitle: Optional[TextType] = None,
48
+ subtitle_align: AlignMethod = "center",
49
+ safe_box: Optional[bool] = None,
50
+ expand: bool = True,
51
+ style: StyleType = "none",
52
+ border_style: StyleType = "none",
53
+ width: Optional[int] = None,
54
+ height: Optional[int] = None,
55
+ padding: PaddingDimensions = (0, 1),
56
+ highlight: bool = False,
57
+ ) -> None:
58
+ self.renderable = renderable
59
+ self.box = box
60
+ self.title = title
61
+ self.title_align: AlignMethod = title_align
62
+ self.subtitle = subtitle
63
+ self.subtitle_align = subtitle_align
64
+ self.safe_box = safe_box
65
+ self.expand = expand
66
+ self.style = style
67
+ self.border_style = border_style
68
+ self.width = width
69
+ self.height = height
70
+ self.padding = padding
71
+ self.highlight = highlight
72
+
73
+ @classmethod
74
+ def fit(
75
+ cls,
76
+ renderable: "RenderableType",
77
+ box: Box = ROUNDED,
78
+ *,
79
+ title: Optional[TextType] = None,
80
+ title_align: AlignMethod = "center",
81
+ subtitle: Optional[TextType] = None,
82
+ subtitle_align: AlignMethod = "center",
83
+ safe_box: Optional[bool] = None,
84
+ style: StyleType = "none",
85
+ border_style: StyleType = "none",
86
+ width: Optional[int] = None,
87
+ height: Optional[int] = None,
88
+ padding: PaddingDimensions = (0, 1),
89
+ highlight: bool = False,
90
+ ) -> "Panel":
91
+ """An alternative constructor that sets expand=False."""
92
+ return cls(
93
+ renderable,
94
+ box,
95
+ title=title,
96
+ title_align=title_align,
97
+ subtitle=subtitle,
98
+ subtitle_align=subtitle_align,
99
+ safe_box=safe_box,
100
+ style=style,
101
+ border_style=border_style,
102
+ width=width,
103
+ height=height,
104
+ padding=padding,
105
+ highlight=highlight,
106
+ expand=False,
107
+ )
108
+
109
+ @property
110
+ def _title(self) -> Optional[Text]:
111
+ if self.title:
112
+ title_text = (
113
+ Text.from_markup(self.title)
114
+ if isinstance(self.title, str)
115
+ else self.title.copy()
116
+ )
117
+ title_text.end = ""
118
+ title_text.plain = title_text.plain.replace("\n", " ")
119
+ title_text.no_wrap = True
120
+ title_text.expand_tabs()
121
+ title_text.pad(1)
122
+ return title_text
123
+ return None
124
+
125
+ @property
126
+ def _subtitle(self) -> Optional[Text]:
127
+ if self.subtitle:
128
+ subtitle_text = (
129
+ Text.from_markup(self.subtitle)
130
+ if isinstance(self.subtitle, str)
131
+ else self.subtitle.copy()
132
+ )
133
+ subtitle_text.end = ""
134
+ subtitle_text.plain = subtitle_text.plain.replace("\n", " ")
135
+ subtitle_text.no_wrap = True
136
+ subtitle_text.expand_tabs()
137
+ subtitle_text.pad(1)
138
+ return subtitle_text
139
+ return None
140
+
141
+ def __rich_console__(
142
+ self, console: "Console", options: "ConsoleOptions"
143
+ ) -> "RenderResult":
144
+ _padding = Padding.unpack(self.padding)
145
+ renderable = (
146
+ Padding(self.renderable, _padding) if any(_padding) else self.renderable
147
+ )
148
+ style = console.get_style(self.style)
149
+ partial_border_style = console.get_style(self.border_style)
150
+ border_style = style + partial_border_style
151
+ width = (
152
+ options.max_width
153
+ if self.width is None
154
+ else min(options.max_width, self.width)
155
+ )
156
+
157
+ safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
158
+ box = self.box.substitute(options, safe=safe_box)
159
+
160
+ def align_text(
161
+ text: Text, width: int, align: str, character: str, style: Style
162
+ ) -> Text:
163
+ """Gets new aligned text.
164
+
165
+ Args:
166
+ text (Text): Title or subtitle text.
167
+ width (int): Desired width.
168
+ align (str): Alignment.
169
+ character (str): Character for alignment.
170
+ style (Style): Border style
171
+
172
+ Returns:
173
+ Text: New text instance
174
+ """
175
+ text = text.copy()
176
+ text.truncate(width)
177
+ excess_space = width - cell_len(text.plain)
178
+ if text.style:
179
+ text.stylize(console.get_style(text.style))
180
+
181
+ if excess_space:
182
+ if align == "left":
183
+ return Text.assemble(
184
+ text,
185
+ (character * excess_space, style),
186
+ no_wrap=True,
187
+ end="",
188
+ )
189
+ elif align == "center":
190
+ left = excess_space // 2
191
+ return Text.assemble(
192
+ (character * left, style),
193
+ text,
194
+ (character * (excess_space - left), style),
195
+ no_wrap=True,
196
+ end="",
197
+ )
198
+ else:
199
+ return Text.assemble(
200
+ (character * excess_space, style),
201
+ text,
202
+ no_wrap=True,
203
+ end="",
204
+ )
205
+ return text
206
+
207
+ title_text = self._title
208
+ if title_text is not None:
209
+ title_text.stylize_before(partial_border_style)
210
+
211
+ child_width = (
212
+ width - 2
213
+ if self.expand
214
+ else console.measure(
215
+ renderable, options=options.update_width(width - 2)
216
+ ).maximum
217
+ )
218
+ child_height = self.height or options.height or None
219
+ if child_height:
220
+ child_height -= 2
221
+ if title_text is not None:
222
+ child_width = min(
223
+ options.max_width - 2, max(child_width, title_text.cell_len + 2)
224
+ )
225
+
226
+ width = child_width + 2
227
+ child_options = options.update(
228
+ width=child_width, height=child_height, highlight=self.highlight
229
+ )
230
+ lines = console.render_lines(renderable, child_options, style=style)
231
+
232
+ line_start = Segment(box.mid_left, border_style)
233
+ line_end = Segment(f"{box.mid_right}", border_style)
234
+ new_line = Segment.line()
235
+ if title_text is None or width <= 4:
236
+ yield Segment(box.get_top([width - 2]), border_style)
237
+ else:
238
+ title_text = align_text(
239
+ title_text,
240
+ width - 4,
241
+ self.title_align,
242
+ box.top,
243
+ border_style,
244
+ )
245
+ yield Segment(box.top_left + box.top, border_style)
246
+ yield from console.render(title_text, child_options.update_width(width - 4))
247
+ yield Segment(box.top + box.top_right, border_style)
248
+
249
+ yield new_line
250
+ for line in lines:
251
+ yield line_start
252
+ yield from line
253
+ yield line_end
254
+ yield new_line
255
+
256
+ subtitle_text = self._subtitle
257
+ if subtitle_text is not None:
258
+ subtitle_text.stylize_before(partial_border_style)
259
+
260
+ if subtitle_text is None or width <= 4:
261
+ yield Segment(box.get_bottom([width - 2]), border_style)
262
+ else:
263
+ subtitle_text = align_text(
264
+ subtitle_text,
265
+ width - 4,
266
+ self.subtitle_align,
267
+ box.bottom,
268
+ border_style,
269
+ )
270
+ yield Segment(box.bottom_left + box.bottom, border_style)
271
+ yield from console.render(
272
+ subtitle_text, child_options.update_width(width - 4)
273
+ )
274
+ yield Segment(box.bottom + box.bottom_right, border_style)
275
+
276
+ yield new_line
277
+
278
+ def __rich_measure__(
279
+ self, console: "Console", options: "ConsoleOptions"
280
+ ) -> "Measurement":
281
+ _title = self._title
282
+ _, right, _, left = Padding.unpack(self.padding)
283
+ padding = left + right
284
+ renderables = [self.renderable, _title] if _title else [self.renderable]
285
+
286
+ if self.width is None:
287
+ width = (
288
+ measure_renderables(
289
+ console,
290
+ options.update_width(options.max_width - padding - 2),
291
+ renderables,
292
+ ).maximum
293
+ + padding
294
+ + 2
295
+ )
296
+ else:
297
+ width = self.width
298
+ return Measurement(width, width)
299
+
300
+
301
+ if __name__ == "__main__": # pragma: no cover
302
+ from .console import Console
303
+
304
+ c = Console()
305
+
306
+ from .box import DOUBLE, ROUNDED
307
+ from .padding import Padding
308
+
309
+ p = Panel(
310
+ "Hello, World!",
311
+ title="rich.Panel",
312
+ style="white on blue",
313
+ box=DOUBLE,
314
+ padding=1,
315
+ )
316
+
317
+ c.print()
318
+ c.print(p)
llava/lib/python3.10/site-packages/pip/_vendor/rich/progress_bar.py ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ from functools import lru_cache
3
+ from time import monotonic
4
+ from typing import Iterable, List, Optional
5
+
6
+ from .color import Color, blend_rgb
7
+ from .color_triplet import ColorTriplet
8
+ from .console import Console, ConsoleOptions, RenderResult
9
+ from .jupyter import JupyterMixin
10
+ from .measure import Measurement
11
+ from .segment import Segment
12
+ from .style import Style, StyleType
13
+
14
+ # Number of characters before 'pulse' animation repeats
15
+ PULSE_SIZE = 20
16
+
17
+
18
+ class ProgressBar(JupyterMixin):
19
+ """Renders a (progress) bar. Used by rich.progress.
20
+
21
+ Args:
22
+ total (float, optional): Number of steps in the bar. Defaults to 100. Set to None to render a pulsing animation.
23
+ completed (float, optional): Number of steps completed. Defaults to 0.
24
+ width (int, optional): Width of the bar, or ``None`` for maximum width. Defaults to None.
25
+ pulse (bool, optional): Enable pulse effect. Defaults to False. Will pulse if a None total was passed.
26
+ style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
27
+ complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
28
+ finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
29
+ pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
30
+ animation_time (Optional[float], optional): Time in seconds to use for animation, or None to use system time.
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ total: Optional[float] = 100.0,
36
+ completed: float = 0,
37
+ width: Optional[int] = None,
38
+ pulse: bool = False,
39
+ style: StyleType = "bar.back",
40
+ complete_style: StyleType = "bar.complete",
41
+ finished_style: StyleType = "bar.finished",
42
+ pulse_style: StyleType = "bar.pulse",
43
+ animation_time: Optional[float] = None,
44
+ ):
45
+ self.total = total
46
+ self.completed = completed
47
+ self.width = width
48
+ self.pulse = pulse
49
+ self.style = style
50
+ self.complete_style = complete_style
51
+ self.finished_style = finished_style
52
+ self.pulse_style = pulse_style
53
+ self.animation_time = animation_time
54
+
55
+ self._pulse_segments: Optional[List[Segment]] = None
56
+
57
+ def __repr__(self) -> str:
58
+ return f"<Bar {self.completed!r} of {self.total!r}>"
59
+
60
+ @property
61
+ def percentage_completed(self) -> Optional[float]:
62
+ """Calculate percentage complete."""
63
+ if self.total is None:
64
+ return None
65
+ completed = (self.completed / self.total) * 100.0
66
+ completed = min(100, max(0.0, completed))
67
+ return completed
68
+
69
+ @lru_cache(maxsize=16)
70
+ def _get_pulse_segments(
71
+ self,
72
+ fore_style: Style,
73
+ back_style: Style,
74
+ color_system: str,
75
+ no_color: bool,
76
+ ascii: bool = False,
77
+ ) -> List[Segment]:
78
+ """Get a list of segments to render a pulse animation.
79
+
80
+ Returns:
81
+ List[Segment]: A list of segments, one segment per character.
82
+ """
83
+ bar = "-" if ascii else "━"
84
+ segments: List[Segment] = []
85
+ if color_system not in ("standard", "eight_bit", "truecolor") or no_color:
86
+ segments += [Segment(bar, fore_style)] * (PULSE_SIZE // 2)
87
+ segments += [Segment(" " if no_color else bar, back_style)] * (
88
+ PULSE_SIZE - (PULSE_SIZE // 2)
89
+ )
90
+ return segments
91
+
92
+ append = segments.append
93
+ fore_color = (
94
+ fore_style.color.get_truecolor()
95
+ if fore_style.color
96
+ else ColorTriplet(255, 0, 255)
97
+ )
98
+ back_color = (
99
+ back_style.color.get_truecolor()
100
+ if back_style.color
101
+ else ColorTriplet(0, 0, 0)
102
+ )
103
+ cos = math.cos
104
+ pi = math.pi
105
+ _Segment = Segment
106
+ _Style = Style
107
+ from_triplet = Color.from_triplet
108
+
109
+ for index in range(PULSE_SIZE):
110
+ position = index / PULSE_SIZE
111
+ fade = 0.5 + cos(position * pi * 2) / 2.0
112
+ color = blend_rgb(fore_color, back_color, cross_fade=fade)
113
+ append(_Segment(bar, _Style(color=from_triplet(color))))
114
+ return segments
115
+
116
+ def update(self, completed: float, total: Optional[float] = None) -> None:
117
+ """Update progress with new values.
118
+
119
+ Args:
120
+ completed (float): Number of steps completed.
121
+ total (float, optional): Total number of steps, or ``None`` to not change. Defaults to None.
122
+ """
123
+ self.completed = completed
124
+ self.total = total if total is not None else self.total
125
+
126
+ def _render_pulse(
127
+ self, console: Console, width: int, ascii: bool = False
128
+ ) -> Iterable[Segment]:
129
+ """Renders the pulse animation.
130
+
131
+ Args:
132
+ console (Console): Console instance.
133
+ width (int): Width in characters of pulse animation.
134
+
135
+ Returns:
136
+ RenderResult: [description]
137
+
138
+ Yields:
139
+ Iterator[Segment]: Segments to render pulse
140
+ """
141
+ fore_style = console.get_style(self.pulse_style, default="white")
142
+ back_style = console.get_style(self.style, default="black")
143
+
144
+ pulse_segments = self._get_pulse_segments(
145
+ fore_style, back_style, console.color_system, console.no_color, ascii=ascii
146
+ )
147
+ segment_count = len(pulse_segments)
148
+ current_time = (
149
+ monotonic() if self.animation_time is None else self.animation_time
150
+ )
151
+ segments = pulse_segments * (int(width / segment_count) + 2)
152
+ offset = int(-current_time * 15) % segment_count
153
+ segments = segments[offset : offset + width]
154
+ yield from segments
155
+
156
+ def __rich_console__(
157
+ self, console: Console, options: ConsoleOptions
158
+ ) -> RenderResult:
159
+ width = min(self.width or options.max_width, options.max_width)
160
+ ascii = options.legacy_windows or options.ascii_only
161
+ should_pulse = self.pulse or self.total is None
162
+ if should_pulse:
163
+ yield from self._render_pulse(console, width, ascii=ascii)
164
+ return
165
+
166
+ completed: Optional[float] = (
167
+ min(self.total, max(0, self.completed)) if self.total is not None else None
168
+ )
169
+
170
+ bar = "-" if ascii else "━"
171
+ half_bar_right = " " if ascii else "╸"
172
+ half_bar_left = " " if ascii else "╺"
173
+ complete_halves = (
174
+ int(width * 2 * completed / self.total)
175
+ if self.total and completed is not None
176
+ else width * 2
177
+ )
178
+ bar_count = complete_halves // 2
179
+ half_bar_count = complete_halves % 2
180
+ style = console.get_style(self.style)
181
+ is_finished = self.total is None or self.completed >= self.total
182
+ complete_style = console.get_style(
183
+ self.finished_style if is_finished else self.complete_style
184
+ )
185
+ _Segment = Segment
186
+ if bar_count:
187
+ yield _Segment(bar * bar_count, complete_style)
188
+ if half_bar_count:
189
+ yield _Segment(half_bar_right * half_bar_count, complete_style)
190
+
191
+ if not console.no_color:
192
+ remaining_bars = width - bar_count - half_bar_count
193
+ if remaining_bars and console.color_system is not None:
194
+ if not half_bar_count and bar_count:
195
+ yield _Segment(half_bar_left, style)
196
+ remaining_bars -= 1
197
+ if remaining_bars:
198
+ yield _Segment(bar * remaining_bars, style)
199
+
200
+ def __rich_measure__(
201
+ self, console: Console, options: ConsoleOptions
202
+ ) -> Measurement:
203
+ return (
204
+ Measurement(self.width, self.width)
205
+ if self.width is not None
206
+ else Measurement(4, options.max_width)
207
+ )
208
+
209
+
210
+ if __name__ == "__main__": # pragma: no cover
211
+ console = Console()
212
+ bar = ProgressBar(width=50, total=100)
213
+
214
+ import time
215
+
216
+ console.show_cursor(False)
217
+ for n in range(0, 101, 1):
218
+ bar.update(n)
219
+ console.print(bar)
220
+ console.file.write("\r")
221
+ time.sleep(0.05)
222
+ console.show_cursor(True)
223
+ console.print()
llava/lib/python3.10/site-packages/pip/_vendor/rich/prompt.py ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Generic, List, Optional, TextIO, TypeVar, Union, overload
2
+
3
+ from . import get_console
4
+ from .console import Console
5
+ from .text import Text, TextType
6
+
7
+ PromptType = TypeVar("PromptType")
8
+ DefaultType = TypeVar("DefaultType")
9
+
10
+
11
+ class PromptError(Exception):
12
+ """Exception base class for prompt related errors."""
13
+
14
+
15
+ class InvalidResponse(PromptError):
16
+ """Exception to indicate a response was invalid. Raise this within process_response() to indicate an error
17
+ and provide an error message.
18
+
19
+ Args:
20
+ message (Union[str, Text]): Error message.
21
+ """
22
+
23
+ def __init__(self, message: TextType) -> None:
24
+ self.message = message
25
+
26
+ def __rich__(self) -> TextType:
27
+ return self.message
28
+
29
+
30
+ class PromptBase(Generic[PromptType]):
31
+ """Ask the user for input until a valid response is received. This is the base class, see one of
32
+ the concrete classes for examples.
33
+
34
+ Args:
35
+ prompt (TextType, optional): Prompt text. Defaults to "".
36
+ console (Console, optional): A Console instance or None to use global console. Defaults to None.
37
+ password (bool, optional): Enable password input. Defaults to False.
38
+ choices (List[str], optional): A list of valid choices. Defaults to None.
39
+ case_sensitive (bool, optional): Matching of choices should be case-sensitive. Defaults to True.
40
+ show_default (bool, optional): Show default in prompt. Defaults to True.
41
+ show_choices (bool, optional): Show choices in prompt. Defaults to True.
42
+ """
43
+
44
+ response_type: type = str
45
+
46
+ validate_error_message = "[prompt.invalid]Please enter a valid value"
47
+ illegal_choice_message = (
48
+ "[prompt.invalid.choice]Please select one of the available options"
49
+ )
50
+ prompt_suffix = ": "
51
+
52
+ choices: Optional[List[str]] = None
53
+
54
+ def __init__(
55
+ self,
56
+ prompt: TextType = "",
57
+ *,
58
+ console: Optional[Console] = None,
59
+ password: bool = False,
60
+ choices: Optional[List[str]] = None,
61
+ case_sensitive: bool = True,
62
+ show_default: bool = True,
63
+ show_choices: bool = True,
64
+ ) -> None:
65
+ self.console = console or get_console()
66
+ self.prompt = (
67
+ Text.from_markup(prompt, style="prompt")
68
+ if isinstance(prompt, str)
69
+ else prompt
70
+ )
71
+ self.password = password
72
+ if choices is not None:
73
+ self.choices = choices
74
+ self.case_sensitive = case_sensitive
75
+ self.show_default = show_default
76
+ self.show_choices = show_choices
77
+
78
+ @classmethod
79
+ @overload
80
+ def ask(
81
+ cls,
82
+ prompt: TextType = "",
83
+ *,
84
+ console: Optional[Console] = None,
85
+ password: bool = False,
86
+ choices: Optional[List[str]] = None,
87
+ case_sensitive: bool = True,
88
+ show_default: bool = True,
89
+ show_choices: bool = True,
90
+ default: DefaultType,
91
+ stream: Optional[TextIO] = None,
92
+ ) -> Union[DefaultType, PromptType]:
93
+ ...
94
+
95
+ @classmethod
96
+ @overload
97
+ def ask(
98
+ cls,
99
+ prompt: TextType = "",
100
+ *,
101
+ console: Optional[Console] = None,
102
+ password: bool = False,
103
+ choices: Optional[List[str]] = None,
104
+ case_sensitive: bool = True,
105
+ show_default: bool = True,
106
+ show_choices: bool = True,
107
+ stream: Optional[TextIO] = None,
108
+ ) -> PromptType:
109
+ ...
110
+
111
+ @classmethod
112
+ def ask(
113
+ cls,
114
+ prompt: TextType = "",
115
+ *,
116
+ console: Optional[Console] = None,
117
+ password: bool = False,
118
+ choices: Optional[List[str]] = None,
119
+ case_sensitive: bool = True,
120
+ show_default: bool = True,
121
+ show_choices: bool = True,
122
+ default: Any = ...,
123
+ stream: Optional[TextIO] = None,
124
+ ) -> Any:
125
+ """Shortcut to construct and run a prompt loop and return the result.
126
+
127
+ Example:
128
+ >>> filename = Prompt.ask("Enter a filename")
129
+
130
+ Args:
131
+ prompt (TextType, optional): Prompt text. Defaults to "".
132
+ console (Console, optional): A Console instance or None to use global console. Defaults to None.
133
+ password (bool, optional): Enable password input. Defaults to False.
134
+ choices (List[str], optional): A list of valid choices. Defaults to None.
135
+ case_sensitive (bool, optional): Matching of choices should be case-sensitive. Defaults to True.
136
+ show_default (bool, optional): Show default in prompt. Defaults to True.
137
+ show_choices (bool, optional): Show choices in prompt. Defaults to True.
138
+ stream (TextIO, optional): Optional text file open for reading to get input. Defaults to None.
139
+ """
140
+ _prompt = cls(
141
+ prompt,
142
+ console=console,
143
+ password=password,
144
+ choices=choices,
145
+ case_sensitive=case_sensitive,
146
+ show_default=show_default,
147
+ show_choices=show_choices,
148
+ )
149
+ return _prompt(default=default, stream=stream)
150
+
151
+ def render_default(self, default: DefaultType) -> Text:
152
+ """Turn the supplied default in to a Text instance.
153
+
154
+ Args:
155
+ default (DefaultType): Default value.
156
+
157
+ Returns:
158
+ Text: Text containing rendering of default value.
159
+ """
160
+ return Text(f"({default})", "prompt.default")
161
+
162
+ def make_prompt(self, default: DefaultType) -> Text:
163
+ """Make prompt text.
164
+
165
+ Args:
166
+ default (DefaultType): Default value.
167
+
168
+ Returns:
169
+ Text: Text to display in prompt.
170
+ """
171
+ prompt = self.prompt.copy()
172
+ prompt.end = ""
173
+
174
+ if self.show_choices and self.choices:
175
+ _choices = "/".join(self.choices)
176
+ choices = f"[{_choices}]"
177
+ prompt.append(" ")
178
+ prompt.append(choices, "prompt.choices")
179
+
180
+ if (
181
+ default != ...
182
+ and self.show_default
183
+ and isinstance(default, (str, self.response_type))
184
+ ):
185
+ prompt.append(" ")
186
+ _default = self.render_default(default)
187
+ prompt.append(_default)
188
+
189
+ prompt.append(self.prompt_suffix)
190
+
191
+ return prompt
192
+
193
+ @classmethod
194
+ def get_input(
195
+ cls,
196
+ console: Console,
197
+ prompt: TextType,
198
+ password: bool,
199
+ stream: Optional[TextIO] = None,
200
+ ) -> str:
201
+ """Get input from user.
202
+
203
+ Args:
204
+ console (Console): Console instance.
205
+ prompt (TextType): Prompt text.
206
+ password (bool): Enable password entry.
207
+
208
+ Returns:
209
+ str: String from user.
210
+ """
211
+ return console.input(prompt, password=password, stream=stream)
212
+
213
+ def check_choice(self, value: str) -> bool:
214
+ """Check value is in the list of valid choices.
215
+
216
+ Args:
217
+ value (str): Value entered by user.
218
+
219
+ Returns:
220
+ bool: True if choice was valid, otherwise False.
221
+ """
222
+ assert self.choices is not None
223
+ if self.case_sensitive:
224
+ return value.strip() in self.choices
225
+ return value.strip().lower() in [choice.lower() for choice in self.choices]
226
+
227
+ def process_response(self, value: str) -> PromptType:
228
+ """Process response from user, convert to prompt type.
229
+
230
+ Args:
231
+ value (str): String typed by user.
232
+
233
+ Raises:
234
+ InvalidResponse: If ``value`` is invalid.
235
+
236
+ Returns:
237
+ PromptType: The value to be returned from ask method.
238
+ """
239
+ value = value.strip()
240
+ try:
241
+ return_value: PromptType = self.response_type(value)
242
+ except ValueError:
243
+ raise InvalidResponse(self.validate_error_message)
244
+
245
+ if self.choices is not None:
246
+ if not self.check_choice(value):
247
+ raise InvalidResponse(self.illegal_choice_message)
248
+
249
+ if not self.case_sensitive:
250
+ # return the original choice, not the lower case version
251
+ return_value = self.response_type(
252
+ self.choices[
253
+ [choice.lower() for choice in self.choices].index(value.lower())
254
+ ]
255
+ )
256
+ return return_value
257
+
258
+ def on_validate_error(self, value: str, error: InvalidResponse) -> None:
259
+ """Called to handle validation error.
260
+
261
+ Args:
262
+ value (str): String entered by user.
263
+ error (InvalidResponse): Exception instance the initiated the error.
264
+ """
265
+ self.console.print(error)
266
+
267
+ def pre_prompt(self) -> None:
268
+ """Hook to display something before the prompt."""
269
+
270
+ @overload
271
+ def __call__(self, *, stream: Optional[TextIO] = None) -> PromptType:
272
+ ...
273
+
274
+ @overload
275
+ def __call__(
276
+ self, *, default: DefaultType, stream: Optional[TextIO] = None
277
+ ) -> Union[PromptType, DefaultType]:
278
+ ...
279
+
280
+ def __call__(self, *, default: Any = ..., stream: Optional[TextIO] = None) -> Any:
281
+ """Run the prompt loop.
282
+
283
+ Args:
284
+ default (Any, optional): Optional default value.
285
+
286
+ Returns:
287
+ PromptType: Processed value.
288
+ """
289
+ while True:
290
+ self.pre_prompt()
291
+ prompt = self.make_prompt(default)
292
+ value = self.get_input(self.console, prompt, self.password, stream=stream)
293
+ if value == "" and default != ...:
294
+ return default
295
+ try:
296
+ return_value = self.process_response(value)
297
+ except InvalidResponse as error:
298
+ self.on_validate_error(value, error)
299
+ continue
300
+ else:
301
+ return return_value
302
+
303
+
304
+ class Prompt(PromptBase[str]):
305
+ """A prompt that returns a str.
306
+
307
+ Example:
308
+ >>> name = Prompt.ask("Enter your name")
309
+
310
+
311
+ """
312
+
313
+ response_type = str
314
+
315
+
316
+ class IntPrompt(PromptBase[int]):
317
+ """A prompt that returns an integer.
318
+
319
+ Example:
320
+ >>> burrito_count = IntPrompt.ask("How many burritos do you want to order")
321
+
322
+ """
323
+
324
+ response_type = int
325
+ validate_error_message = "[prompt.invalid]Please enter a valid integer number"
326
+
327
+
328
+ class FloatPrompt(PromptBase[float]):
329
+ """A prompt that returns a float.
330
+
331
+ Example:
332
+ >>> temperature = FloatPrompt.ask("Enter desired temperature")
333
+
334
+ """
335
+
336
+ response_type = float
337
+ validate_error_message = "[prompt.invalid]Please enter a number"
338
+
339
+
340
+ class Confirm(PromptBase[bool]):
341
+ """A yes / no confirmation prompt.
342
+
343
+ Example:
344
+ >>> if Confirm.ask("Continue"):
345
+ run_job()
346
+
347
+ """
348
+
349
+ response_type = bool
350
+ validate_error_message = "[prompt.invalid]Please enter Y or N"
351
+ choices: List[str] = ["y", "n"]
352
+
353
+ def render_default(self, default: DefaultType) -> Text:
354
+ """Render the default as (y) or (n) rather than True/False."""
355
+ yes, no = self.choices
356
+ return Text(f"({yes})" if default else f"({no})", style="prompt.default")
357
+
358
+ def process_response(self, value: str) -> bool:
359
+ """Convert choices to a bool."""
360
+ value = value.strip().lower()
361
+ if value not in self.choices:
362
+ raise InvalidResponse(self.validate_error_message)
363
+ return value == self.choices[0]
364
+
365
+
366
+ if __name__ == "__main__": # pragma: no cover
367
+ from pip._vendor.rich import print
368
+
369
+ if Confirm.ask("Run [i]prompt[/i] tests?", default=True):
370
+ while True:
371
+ result = IntPrompt.ask(
372
+ ":rocket: Enter a number between [b]1[/b] and [b]10[/b]", default=5
373
+ )
374
+ if result >= 1 and result <= 10:
375
+ break
376
+ print(":pile_of_poo: [prompt.invalid]Number must be between 1 and 10")
377
+ print(f"number={result}")
378
+
379
+ while True:
380
+ password = Prompt.ask(
381
+ "Please enter a password [cyan](must be at least 5 characters)",
382
+ password=True,
383
+ )
384
+ if len(password) >= 5:
385
+ break
386
+ print("[prompt.invalid]password too short")
387
+ print(f"password={password!r}")
388
+
389
+ fruit = Prompt.ask("Enter a fruit", choices=["apple", "orange", "pear"])
390
+ print(f"fruit={fruit!r}")
391
+
392
+ doggie = Prompt.ask(
393
+ "What's the best Dog? (Case INSENSITIVE)",
394
+ choices=["Border Terrier", "Collie", "Labradoodle"],
395
+ case_sensitive=False,
396
+ )
397
+ print(f"doggie={doggie!r}")
398
+
399
+ else:
400
+ print("[b]OK :loudly_crying_face:")
llava/lib/python3.10/site-packages/pip/_vendor/rich/protocol.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, cast, Set, TYPE_CHECKING
2
+ from inspect import isclass
3
+
4
+ if TYPE_CHECKING:
5
+ from pip._vendor.rich.console import RenderableType
6
+
7
+ _GIBBERISH = """aihwerij235234ljsdnp34ksodfipwoe234234jlskjdf"""
8
+
9
+
10
+ def is_renderable(check_object: Any) -> bool:
11
+ """Check if an object may be rendered by Rich."""
12
+ return (
13
+ isinstance(check_object, str)
14
+ or hasattr(check_object, "__rich__")
15
+ or hasattr(check_object, "__rich_console__")
16
+ )
17
+
18
+
19
+ def rich_cast(renderable: object) -> "RenderableType":
20
+ """Cast an object to a renderable by calling __rich__ if present.
21
+
22
+ Args:
23
+ renderable (object): A potentially renderable object
24
+
25
+ Returns:
26
+ object: The result of recursively calling __rich__.
27
+ """
28
+ from pip._vendor.rich.console import RenderableType
29
+
30
+ rich_visited_set: Set[type] = set() # Prevent potential infinite loop
31
+ while hasattr(renderable, "__rich__") and not isclass(renderable):
32
+ # Detect object which claim to have all the attributes
33
+ if hasattr(renderable, _GIBBERISH):
34
+ return repr(renderable)
35
+ cast_method = getattr(renderable, "__rich__")
36
+ renderable = cast_method()
37
+ renderable_type = type(renderable)
38
+ if renderable_type in rich_visited_set:
39
+ break
40
+ rich_visited_set.add(renderable_type)
41
+
42
+ return cast(RenderableType, renderable)
llava/lib/python3.10/site-packages/pip/_vendor/rich/segment.py ADDED
@@ -0,0 +1,752 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from enum import IntEnum
2
+ from functools import lru_cache
3
+ from itertools import filterfalse
4
+ from logging import getLogger
5
+ from operator import attrgetter
6
+ from typing import (
7
+ TYPE_CHECKING,
8
+ Dict,
9
+ Iterable,
10
+ List,
11
+ NamedTuple,
12
+ Optional,
13
+ Sequence,
14
+ Tuple,
15
+ Type,
16
+ Union,
17
+ )
18
+
19
+ from .cells import (
20
+ _is_single_cell_widths,
21
+ cached_cell_len,
22
+ cell_len,
23
+ get_character_cell_size,
24
+ set_cell_size,
25
+ )
26
+ from .repr import Result, rich_repr
27
+ from .style import Style
28
+
29
+ if TYPE_CHECKING:
30
+ from .console import Console, ConsoleOptions, RenderResult
31
+
32
+ log = getLogger("rich")
33
+
34
+
35
+ class ControlType(IntEnum):
36
+ """Non-printable control codes which typically translate to ANSI codes."""
37
+
38
+ BELL = 1
39
+ CARRIAGE_RETURN = 2
40
+ HOME = 3
41
+ CLEAR = 4
42
+ SHOW_CURSOR = 5
43
+ HIDE_CURSOR = 6
44
+ ENABLE_ALT_SCREEN = 7
45
+ DISABLE_ALT_SCREEN = 8
46
+ CURSOR_UP = 9
47
+ CURSOR_DOWN = 10
48
+ CURSOR_FORWARD = 11
49
+ CURSOR_BACKWARD = 12
50
+ CURSOR_MOVE_TO_COLUMN = 13
51
+ CURSOR_MOVE_TO = 14
52
+ ERASE_IN_LINE = 15
53
+ SET_WINDOW_TITLE = 16
54
+
55
+
56
+ ControlCode = Union[
57
+ Tuple[ControlType],
58
+ Tuple[ControlType, Union[int, str]],
59
+ Tuple[ControlType, int, int],
60
+ ]
61
+
62
+
63
+ @rich_repr()
64
+ class Segment(NamedTuple):
65
+ """A piece of text with associated style. Segments are produced by the Console render process and
66
+ are ultimately converted in to strings to be written to the terminal.
67
+
68
+ Args:
69
+ text (str): A piece of text.
70
+ style (:class:`~rich.style.Style`, optional): An optional style to apply to the text.
71
+ control (Tuple[ControlCode], optional): Optional sequence of control codes.
72
+
73
+ Attributes:
74
+ cell_length (int): The cell length of this Segment.
75
+ """
76
+
77
+ text: str
78
+ style: Optional[Style] = None
79
+ control: Optional[Sequence[ControlCode]] = None
80
+
81
+ @property
82
+ def cell_length(self) -> int:
83
+ """The number of terminal cells required to display self.text.
84
+
85
+ Returns:
86
+ int: A number of cells.
87
+ """
88
+ text, _style, control = self
89
+ return 0 if control else cell_len(text)
90
+
91
+ def __rich_repr__(self) -> Result:
92
+ yield self.text
93
+ if self.control is None:
94
+ if self.style is not None:
95
+ yield self.style
96
+ else:
97
+ yield self.style
98
+ yield self.control
99
+
100
+ def __bool__(self) -> bool:
101
+ """Check if the segment contains text."""
102
+ return bool(self.text)
103
+
104
+ @property
105
+ def is_control(self) -> bool:
106
+ """Check if the segment contains control codes."""
107
+ return self.control is not None
108
+
109
+ @classmethod
110
+ @lru_cache(1024 * 16)
111
+ def _split_cells(cls, segment: "Segment", cut: int) -> Tuple["Segment", "Segment"]:
112
+ """Split a segment in to two at a given cell position.
113
+
114
+ Note that splitting a double-width character, may result in that character turning
115
+ into two spaces.
116
+
117
+ Args:
118
+ segment (Segment): A segment to split.
119
+ cut (int): A cell position to cut on.
120
+
121
+ Returns:
122
+ A tuple of two segments.
123
+ """
124
+ text, style, control = segment
125
+ _Segment = Segment
126
+ cell_length = segment.cell_length
127
+ if cut >= cell_length:
128
+ return segment, _Segment("", style, control)
129
+
130
+ cell_size = get_character_cell_size
131
+
132
+ pos = int((cut / cell_length) * len(text))
133
+
134
+ while True:
135
+ before = text[:pos]
136
+ cell_pos = cell_len(before)
137
+ out_by = cell_pos - cut
138
+ if not out_by:
139
+ return (
140
+ _Segment(before, style, control),
141
+ _Segment(text[pos:], style, control),
142
+ )
143
+ if out_by == -1 and cell_size(text[pos]) == 2:
144
+ return (
145
+ _Segment(text[:pos] + " ", style, control),
146
+ _Segment(" " + text[pos + 1 :], style, control),
147
+ )
148
+ if out_by == +1 and cell_size(text[pos - 1]) == 2:
149
+ return (
150
+ _Segment(text[: pos - 1] + " ", style, control),
151
+ _Segment(" " + text[pos:], style, control),
152
+ )
153
+ if cell_pos < cut:
154
+ pos += 1
155
+ else:
156
+ pos -= 1
157
+
158
+ def split_cells(self, cut: int) -> Tuple["Segment", "Segment"]:
159
+ """Split segment in to two segments at the specified column.
160
+
161
+ If the cut point falls in the middle of a 2-cell wide character then it is replaced
162
+ by two spaces, to preserve the display width of the parent segment.
163
+
164
+ Args:
165
+ cut (int): Offset within the segment to cut.
166
+
167
+ Returns:
168
+ Tuple[Segment, Segment]: Two segments.
169
+ """
170
+ text, style, control = self
171
+ assert cut >= 0
172
+
173
+ if _is_single_cell_widths(text):
174
+ # Fast path with all 1 cell characters
175
+ if cut >= len(text):
176
+ return self, Segment("", style, control)
177
+ return (
178
+ Segment(text[:cut], style, control),
179
+ Segment(text[cut:], style, control),
180
+ )
181
+
182
+ return self._split_cells(self, cut)
183
+
184
+ @classmethod
185
+ def line(cls) -> "Segment":
186
+ """Make a new line segment."""
187
+ return cls("\n")
188
+
189
+ @classmethod
190
+ def apply_style(
191
+ cls,
192
+ segments: Iterable["Segment"],
193
+ style: Optional[Style] = None,
194
+ post_style: Optional[Style] = None,
195
+ ) -> Iterable["Segment"]:
196
+ """Apply style(s) to an iterable of segments.
197
+
198
+ Returns an iterable of segments where the style is replaced by ``style + segment.style + post_style``.
199
+
200
+ Args:
201
+ segments (Iterable[Segment]): Segments to process.
202
+ style (Style, optional): Base style. Defaults to None.
203
+ post_style (Style, optional): Style to apply on top of segment style. Defaults to None.
204
+
205
+ Returns:
206
+ Iterable[Segments]: A new iterable of segments (possibly the same iterable).
207
+ """
208
+ result_segments = segments
209
+ if style:
210
+ apply = style.__add__
211
+ result_segments = (
212
+ cls(text, None if control else apply(_style), control)
213
+ for text, _style, control in result_segments
214
+ )
215
+ if post_style:
216
+ result_segments = (
217
+ cls(
218
+ text,
219
+ (
220
+ None
221
+ if control
222
+ else (_style + post_style if _style else post_style)
223
+ ),
224
+ control,
225
+ )
226
+ for text, _style, control in result_segments
227
+ )
228
+ return result_segments
229
+
230
+ @classmethod
231
+ def filter_control(
232
+ cls, segments: Iterable["Segment"], is_control: bool = False
233
+ ) -> Iterable["Segment"]:
234
+ """Filter segments by ``is_control`` attribute.
235
+
236
+ Args:
237
+ segments (Iterable[Segment]): An iterable of Segment instances.
238
+ is_control (bool, optional): is_control flag to match in search.
239
+
240
+ Returns:
241
+ Iterable[Segment]: And iterable of Segment instances.
242
+
243
+ """
244
+ if is_control:
245
+ return filter(attrgetter("control"), segments)
246
+ else:
247
+ return filterfalse(attrgetter("control"), segments)
248
+
249
+ @classmethod
250
+ def split_lines(cls, segments: Iterable["Segment"]) -> Iterable[List["Segment"]]:
251
+ """Split a sequence of segments in to a list of lines.
252
+
253
+ Args:
254
+ segments (Iterable[Segment]): Segments potentially containing line feeds.
255
+
256
+ Yields:
257
+ Iterable[List[Segment]]: Iterable of segment lists, one per line.
258
+ """
259
+ line: List[Segment] = []
260
+ append = line.append
261
+
262
+ for segment in segments:
263
+ if "\n" in segment.text and not segment.control:
264
+ text, style, _ = segment
265
+ while text:
266
+ _text, new_line, text = text.partition("\n")
267
+ if _text:
268
+ append(cls(_text, style))
269
+ if new_line:
270
+ yield line
271
+ line = []
272
+ append = line.append
273
+ else:
274
+ append(segment)
275
+ if line:
276
+ yield line
277
+
278
+ @classmethod
279
+ def split_and_crop_lines(
280
+ cls,
281
+ segments: Iterable["Segment"],
282
+ length: int,
283
+ style: Optional[Style] = None,
284
+ pad: bool = True,
285
+ include_new_lines: bool = True,
286
+ ) -> Iterable[List["Segment"]]:
287
+ """Split segments in to lines, and crop lines greater than a given length.
288
+
289
+ Args:
290
+ segments (Iterable[Segment]): An iterable of segments, probably
291
+ generated from console.render.
292
+ length (int): Desired line length.
293
+ style (Style, optional): Style to use for any padding.
294
+ pad (bool): Enable padding of lines that are less than `length`.
295
+
296
+ Returns:
297
+ Iterable[List[Segment]]: An iterable of lines of segments.
298
+ """
299
+ line: List[Segment] = []
300
+ append = line.append
301
+
302
+ adjust_line_length = cls.adjust_line_length
303
+ new_line_segment = cls("\n")
304
+
305
+ for segment in segments:
306
+ if "\n" in segment.text and not segment.control:
307
+ text, segment_style, _ = segment
308
+ while text:
309
+ _text, new_line, text = text.partition("\n")
310
+ if _text:
311
+ append(cls(_text, segment_style))
312
+ if new_line:
313
+ cropped_line = adjust_line_length(
314
+ line, length, style=style, pad=pad
315
+ )
316
+ if include_new_lines:
317
+ cropped_line.append(new_line_segment)
318
+ yield cropped_line
319
+ line.clear()
320
+ else:
321
+ append(segment)
322
+ if line:
323
+ yield adjust_line_length(line, length, style=style, pad=pad)
324
+
325
+ @classmethod
326
+ def adjust_line_length(
327
+ cls,
328
+ line: List["Segment"],
329
+ length: int,
330
+ style: Optional[Style] = None,
331
+ pad: bool = True,
332
+ ) -> List["Segment"]:
333
+ """Adjust a line to a given width (cropping or padding as required).
334
+
335
+ Args:
336
+ segments (Iterable[Segment]): A list of segments in a single line.
337
+ length (int): The desired width of the line.
338
+ style (Style, optional): The style of padding if used (space on the end). Defaults to None.
339
+ pad (bool, optional): Pad lines with spaces if they are shorter than `length`. Defaults to True.
340
+
341
+ Returns:
342
+ List[Segment]: A line of segments with the desired length.
343
+ """
344
+ line_length = sum(segment.cell_length for segment in line)
345
+ new_line: List[Segment]
346
+
347
+ if line_length < length:
348
+ if pad:
349
+ new_line = line + [cls(" " * (length - line_length), style)]
350
+ else:
351
+ new_line = line[:]
352
+ elif line_length > length:
353
+ new_line = []
354
+ append = new_line.append
355
+ line_length = 0
356
+ for segment in line:
357
+ segment_length = segment.cell_length
358
+ if line_length + segment_length < length or segment.control:
359
+ append(segment)
360
+ line_length += segment_length
361
+ else:
362
+ text, segment_style, _ = segment
363
+ text = set_cell_size(text, length - line_length)
364
+ append(cls(text, segment_style))
365
+ break
366
+ else:
367
+ new_line = line[:]
368
+ return new_line
369
+
370
+ @classmethod
371
+ def get_line_length(cls, line: List["Segment"]) -> int:
372
+ """Get the length of list of segments.
373
+
374
+ Args:
375
+ line (List[Segment]): A line encoded as a list of Segments (assumes no '\\\\n' characters),
376
+
377
+ Returns:
378
+ int: The length of the line.
379
+ """
380
+ _cell_len = cell_len
381
+ return sum(_cell_len(text) for text, style, control in line if not control)
382
+
383
+ @classmethod
384
+ def get_shape(cls, lines: List[List["Segment"]]) -> Tuple[int, int]:
385
+ """Get the shape (enclosing rectangle) of a list of lines.
386
+
387
+ Args:
388
+ lines (List[List[Segment]]): A list of lines (no '\\\\n' characters).
389
+
390
+ Returns:
391
+ Tuple[int, int]: Width and height in characters.
392
+ """
393
+ get_line_length = cls.get_line_length
394
+ max_width = max(get_line_length(line) for line in lines) if lines else 0
395
+ return (max_width, len(lines))
396
+
397
+ @classmethod
398
+ def set_shape(
399
+ cls,
400
+ lines: List[List["Segment"]],
401
+ width: int,
402
+ height: Optional[int] = None,
403
+ style: Optional[Style] = None,
404
+ new_lines: bool = False,
405
+ ) -> List[List["Segment"]]:
406
+ """Set the shape of a list of lines (enclosing rectangle).
407
+
408
+ Args:
409
+ lines (List[List[Segment]]): A list of lines.
410
+ width (int): Desired width.
411
+ height (int, optional): Desired height or None for no change.
412
+ style (Style, optional): Style of any padding added.
413
+ new_lines (bool, optional): Padded lines should include "\n". Defaults to False.
414
+
415
+ Returns:
416
+ List[List[Segment]]: New list of lines.
417
+ """
418
+ _height = height or len(lines)
419
+
420
+ blank = (
421
+ [cls(" " * width + "\n", style)] if new_lines else [cls(" " * width, style)]
422
+ )
423
+
424
+ adjust_line_length = cls.adjust_line_length
425
+ shaped_lines = lines[:_height]
426
+ shaped_lines[:] = [
427
+ adjust_line_length(line, width, style=style) for line in lines
428
+ ]
429
+ if len(shaped_lines) < _height:
430
+ shaped_lines.extend([blank] * (_height - len(shaped_lines)))
431
+ return shaped_lines
432
+
433
+ @classmethod
434
+ def align_top(
435
+ cls: Type["Segment"],
436
+ lines: List[List["Segment"]],
437
+ width: int,
438
+ height: int,
439
+ style: Style,
440
+ new_lines: bool = False,
441
+ ) -> List[List["Segment"]]:
442
+ """Aligns lines to top (adds extra lines to bottom as required).
443
+
444
+ Args:
445
+ lines (List[List[Segment]]): A list of lines.
446
+ width (int): Desired width.
447
+ height (int, optional): Desired height or None for no change.
448
+ style (Style): Style of any padding added.
449
+ new_lines (bool, optional): Padded lines should include "\n". Defaults to False.
450
+
451
+ Returns:
452
+ List[List[Segment]]: New list of lines.
453
+ """
454
+ extra_lines = height - len(lines)
455
+ if not extra_lines:
456
+ return lines[:]
457
+ lines = lines[:height]
458
+ blank = cls(" " * width + "\n", style) if new_lines else cls(" " * width, style)
459
+ lines = lines + [[blank]] * extra_lines
460
+ return lines
461
+
462
+ @classmethod
463
+ def align_bottom(
464
+ cls: Type["Segment"],
465
+ lines: List[List["Segment"]],
466
+ width: int,
467
+ height: int,
468
+ style: Style,
469
+ new_lines: bool = False,
470
+ ) -> List[List["Segment"]]:
471
+ """Aligns render to bottom (adds extra lines above as required).
472
+
473
+ Args:
474
+ lines (List[List[Segment]]): A list of lines.
475
+ width (int): Desired width.
476
+ height (int, optional): Desired height or None for no change.
477
+ style (Style): Style of any padding added. Defaults to None.
478
+ new_lines (bool, optional): Padded lines should include "\n". Defaults to False.
479
+
480
+ Returns:
481
+ List[List[Segment]]: New list of lines.
482
+ """
483
+ extra_lines = height - len(lines)
484
+ if not extra_lines:
485
+ return lines[:]
486
+ lines = lines[:height]
487
+ blank = cls(" " * width + "\n", style) if new_lines else cls(" " * width, style)
488
+ lines = [[blank]] * extra_lines + lines
489
+ return lines
490
+
491
+ @classmethod
492
+ def align_middle(
493
+ cls: Type["Segment"],
494
+ lines: List[List["Segment"]],
495
+ width: int,
496
+ height: int,
497
+ style: Style,
498
+ new_lines: bool = False,
499
+ ) -> List[List["Segment"]]:
500
+ """Aligns lines to middle (adds extra lines to above and below as required).
501
+
502
+ Args:
503
+ lines (List[List[Segment]]): A list of lines.
504
+ width (int): Desired width.
505
+ height (int, optional): Desired height or None for no change.
506
+ style (Style): Style of any padding added.
507
+ new_lines (bool, optional): Padded lines should include "\n". Defaults to False.
508
+
509
+ Returns:
510
+ List[List[Segment]]: New list of lines.
511
+ """
512
+ extra_lines = height - len(lines)
513
+ if not extra_lines:
514
+ return lines[:]
515
+ lines = lines[:height]
516
+ blank = cls(" " * width + "\n", style) if new_lines else cls(" " * width, style)
517
+ top_lines = extra_lines // 2
518
+ bottom_lines = extra_lines - top_lines
519
+ lines = [[blank]] * top_lines + lines + [[blank]] * bottom_lines
520
+ return lines
521
+
522
+ @classmethod
523
+ def simplify(cls, segments: Iterable["Segment"]) -> Iterable["Segment"]:
524
+ """Simplify an iterable of segments by combining contiguous segments with the same style.
525
+
526
+ Args:
527
+ segments (Iterable[Segment]): An iterable of segments.
528
+
529
+ Returns:
530
+ Iterable[Segment]: A possibly smaller iterable of segments that will render the same way.
531
+ """
532
+ iter_segments = iter(segments)
533
+ try:
534
+ last_segment = next(iter_segments)
535
+ except StopIteration:
536
+ return
537
+
538
+ _Segment = Segment
539
+ for segment in iter_segments:
540
+ if last_segment.style == segment.style and not segment.control:
541
+ last_segment = _Segment(
542
+ last_segment.text + segment.text, last_segment.style
543
+ )
544
+ else:
545
+ yield last_segment
546
+ last_segment = segment
547
+ yield last_segment
548
+
549
+ @classmethod
550
+ def strip_links(cls, segments: Iterable["Segment"]) -> Iterable["Segment"]:
551
+ """Remove all links from an iterable of styles.
552
+
553
+ Args:
554
+ segments (Iterable[Segment]): An iterable segments.
555
+
556
+ Yields:
557
+ Segment: Segments with link removed.
558
+ """
559
+ for segment in segments:
560
+ if segment.control or segment.style is None:
561
+ yield segment
562
+ else:
563
+ text, style, _control = segment
564
+ yield cls(text, style.update_link(None) if style else None)
565
+
566
+ @classmethod
567
+ def strip_styles(cls, segments: Iterable["Segment"]) -> Iterable["Segment"]:
568
+ """Remove all styles from an iterable of segments.
569
+
570
+ Args:
571
+ segments (Iterable[Segment]): An iterable segments.
572
+
573
+ Yields:
574
+ Segment: Segments with styles replace with None
575
+ """
576
+ for text, _style, control in segments:
577
+ yield cls(text, None, control)
578
+
579
+ @classmethod
580
+ def remove_color(cls, segments: Iterable["Segment"]) -> Iterable["Segment"]:
581
+ """Remove all color from an iterable of segments.
582
+
583
+ Args:
584
+ segments (Iterable[Segment]): An iterable segments.
585
+
586
+ Yields:
587
+ Segment: Segments with colorless style.
588
+ """
589
+
590
+ cache: Dict[Style, Style] = {}
591
+ for text, style, control in segments:
592
+ if style:
593
+ colorless_style = cache.get(style)
594
+ if colorless_style is None:
595
+ colorless_style = style.without_color
596
+ cache[style] = colorless_style
597
+ yield cls(text, colorless_style, control)
598
+ else:
599
+ yield cls(text, None, control)
600
+
601
+ @classmethod
602
+ def divide(
603
+ cls, segments: Iterable["Segment"], cuts: Iterable[int]
604
+ ) -> Iterable[List["Segment"]]:
605
+ """Divides an iterable of segments in to portions.
606
+
607
+ Args:
608
+ cuts (Iterable[int]): Cell positions where to divide.
609
+
610
+ Yields:
611
+ [Iterable[List[Segment]]]: An iterable of Segments in List.
612
+ """
613
+ split_segments: List["Segment"] = []
614
+ add_segment = split_segments.append
615
+
616
+ iter_cuts = iter(cuts)
617
+
618
+ while True:
619
+ cut = next(iter_cuts, -1)
620
+ if cut == -1:
621
+ return
622
+ if cut != 0:
623
+ break
624
+ yield []
625
+ pos = 0
626
+
627
+ segments_clear = split_segments.clear
628
+ segments_copy = split_segments.copy
629
+
630
+ _cell_len = cached_cell_len
631
+ for segment in segments:
632
+ text, _style, control = segment
633
+ while text:
634
+ end_pos = pos if control else pos + _cell_len(text)
635
+ if end_pos < cut:
636
+ add_segment(segment)
637
+ pos = end_pos
638
+ break
639
+
640
+ if end_pos == cut:
641
+ add_segment(segment)
642
+ yield segments_copy()
643
+ segments_clear()
644
+ pos = end_pos
645
+
646
+ cut = next(iter_cuts, -1)
647
+ if cut == -1:
648
+ if split_segments:
649
+ yield segments_copy()
650
+ return
651
+
652
+ break
653
+
654
+ else:
655
+ before, segment = segment.split_cells(cut - pos)
656
+ text, _style, control = segment
657
+ add_segment(before)
658
+ yield segments_copy()
659
+ segments_clear()
660
+ pos = cut
661
+
662
+ cut = next(iter_cuts, -1)
663
+ if cut == -1:
664
+ if split_segments:
665
+ yield segments_copy()
666
+ return
667
+
668
+ yield segments_copy()
669
+
670
+
671
+ class Segments:
672
+ """A simple renderable to render an iterable of segments. This class may be useful if
673
+ you want to print segments outside of a __rich_console__ method.
674
+
675
+ Args:
676
+ segments (Iterable[Segment]): An iterable of segments.
677
+ new_lines (bool, optional): Add new lines between segments. Defaults to False.
678
+ """
679
+
680
+ def __init__(self, segments: Iterable[Segment], new_lines: bool = False) -> None:
681
+ self.segments = list(segments)
682
+ self.new_lines = new_lines
683
+
684
+ def __rich_console__(
685
+ self, console: "Console", options: "ConsoleOptions"
686
+ ) -> "RenderResult":
687
+ if self.new_lines:
688
+ line = Segment.line()
689
+ for segment in self.segments:
690
+ yield segment
691
+ yield line
692
+ else:
693
+ yield from self.segments
694
+
695
+
696
+ class SegmentLines:
697
+ def __init__(self, lines: Iterable[List[Segment]], new_lines: bool = False) -> None:
698
+ """A simple renderable containing a number of lines of segments. May be used as an intermediate
699
+ in rendering process.
700
+
701
+ Args:
702
+ lines (Iterable[List[Segment]]): Lists of segments forming lines.
703
+ new_lines (bool, optional): Insert new lines after each line. Defaults to False.
704
+ """
705
+ self.lines = list(lines)
706
+ self.new_lines = new_lines
707
+
708
+ def __rich_console__(
709
+ self, console: "Console", options: "ConsoleOptions"
710
+ ) -> "RenderResult":
711
+ if self.new_lines:
712
+ new_line = Segment.line()
713
+ for line in self.lines:
714
+ yield from line
715
+ yield new_line
716
+ else:
717
+ for line in self.lines:
718
+ yield from line
719
+
720
+
721
+ if __name__ == "__main__": # pragma: no cover
722
+ from pip._vendor.rich.console import Console
723
+ from pip._vendor.rich.syntax import Syntax
724
+ from pip._vendor.rich.text import Text
725
+
726
+ code = """from rich.console import Console
727
+ console = Console()
728
+ text = Text.from_markup("Hello, [bold magenta]World[/]!")
729
+ console.print(text)"""
730
+
731
+ text = Text.from_markup("Hello, [bold magenta]World[/]!")
732
+
733
+ console = Console()
734
+
735
+ console.rule("rich.Segment")
736
+ console.print(
737
+ "A Segment is the last step in the Rich render process before generating text with ANSI codes."
738
+ )
739
+ console.print("\nConsider the following code:\n")
740
+ console.print(Syntax(code, "python", line_numbers=True))
741
+ console.print()
742
+ console.print(
743
+ "When you call [b]print()[/b], Rich [i]renders[/i] the object in to the following:\n"
744
+ )
745
+ fragments = list(console.render(text))
746
+ console.print(fragments)
747
+ console.print()
748
+ console.print("The Segments are then processed to produce the following output:\n")
749
+ console.print(text)
750
+ console.print(
751
+ "\nYou will only need to know this if you are implementing your own Rich renderables."
752
+ )
llava/lib/python3.10/site-packages/pip/_vendor/rich/themes.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from .default_styles import DEFAULT_STYLES
2
+ from .theme import Theme
3
+
4
+
5
+ DEFAULT = Theme(DEFAULT_STYLES)
llava/lib/python3.10/site-packages/pip/_vendor/rich/tree.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Iterator, List, Optional, Tuple
2
+
3
+ from ._loop import loop_first, loop_last
4
+ from .console import Console, ConsoleOptions, RenderableType, RenderResult
5
+ from .jupyter import JupyterMixin
6
+ from .measure import Measurement
7
+ from .segment import Segment
8
+ from .style import Style, StyleStack, StyleType
9
+ from .styled import Styled
10
+
11
+ GuideType = Tuple[str, str, str, str]
12
+
13
+
14
+ class Tree(JupyterMixin):
15
+ """A renderable for a tree structure.
16
+
17
+ Attributes:
18
+ ASCII_GUIDES (GuideType): Guide lines used when Console.ascii_only is True.
19
+ TREE_GUIDES (List[GuideType, GuideType, GuideType]): Default guide lines.
20
+
21
+ Args:
22
+ label (RenderableType): The renderable or str for the tree label.
23
+ style (StyleType, optional): Style of this tree. Defaults to "tree".
24
+ guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
25
+ expanded (bool, optional): Also display children. Defaults to True.
26
+ highlight (bool, optional): Highlight renderable (if str). Defaults to False.
27
+ hide_root (bool, optional): Hide the root node. Defaults to False.
28
+ """
29
+
30
+ ASCII_GUIDES = (" ", "| ", "+-- ", "`-- ")
31
+ TREE_GUIDES = [
32
+ (" ", "│ ", "├── ", "└── "),
33
+ (" ", "┃ ", "┣━━ ", "┗━━ "),
34
+ (" ", "║ ", "╠══ ", "╚══ "),
35
+ ]
36
+
37
+ def __init__(
38
+ self,
39
+ label: RenderableType,
40
+ *,
41
+ style: StyleType = "tree",
42
+ guide_style: StyleType = "tree.line",
43
+ expanded: bool = True,
44
+ highlight: bool = False,
45
+ hide_root: bool = False,
46
+ ) -> None:
47
+ self.label = label
48
+ self.style = style
49
+ self.guide_style = guide_style
50
+ self.children: List[Tree] = []
51
+ self.expanded = expanded
52
+ self.highlight = highlight
53
+ self.hide_root = hide_root
54
+
55
+ def add(
56
+ self,
57
+ label: RenderableType,
58
+ *,
59
+ style: Optional[StyleType] = None,
60
+ guide_style: Optional[StyleType] = None,
61
+ expanded: bool = True,
62
+ highlight: Optional[bool] = False,
63
+ ) -> "Tree":
64
+ """Add a child tree.
65
+
66
+ Args:
67
+ label (RenderableType): The renderable or str for the tree label.
68
+ style (StyleType, optional): Style of this tree. Defaults to "tree".
69
+ guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
70
+ expanded (bool, optional): Also display children. Defaults to True.
71
+ highlight (Optional[bool], optional): Highlight renderable (if str). Defaults to False.
72
+
73
+ Returns:
74
+ Tree: A new child Tree, which may be further modified.
75
+ """
76
+ node = Tree(
77
+ label,
78
+ style=self.style if style is None else style,
79
+ guide_style=self.guide_style if guide_style is None else guide_style,
80
+ expanded=expanded,
81
+ highlight=self.highlight if highlight is None else highlight,
82
+ )
83
+ self.children.append(node)
84
+ return node
85
+
86
+ def __rich_console__(
87
+ self, console: "Console", options: "ConsoleOptions"
88
+ ) -> "RenderResult":
89
+ stack: List[Iterator[Tuple[bool, Tree]]] = []
90
+ pop = stack.pop
91
+ push = stack.append
92
+ new_line = Segment.line()
93
+
94
+ get_style = console.get_style
95
+ null_style = Style.null()
96
+ guide_style = get_style(self.guide_style, default="") or null_style
97
+ SPACE, CONTINUE, FORK, END = range(4)
98
+
99
+ _Segment = Segment
100
+
101
+ def make_guide(index: int, style: Style) -> Segment:
102
+ """Make a Segment for a level of the guide lines."""
103
+ if options.ascii_only:
104
+ line = self.ASCII_GUIDES[index]
105
+ else:
106
+ guide = 1 if style.bold else (2 if style.underline2 else 0)
107
+ line = self.TREE_GUIDES[0 if options.legacy_windows else guide][index]
108
+ return _Segment(line, style)
109
+
110
+ levels: List[Segment] = [make_guide(CONTINUE, guide_style)]
111
+ push(iter(loop_last([self])))
112
+
113
+ guide_style_stack = StyleStack(get_style(self.guide_style))
114
+ style_stack = StyleStack(get_style(self.style))
115
+ remove_guide_styles = Style(bold=False, underline2=False)
116
+
117
+ depth = 0
118
+
119
+ while stack:
120
+ stack_node = pop()
121
+ try:
122
+ last, node = next(stack_node)
123
+ except StopIteration:
124
+ levels.pop()
125
+ if levels:
126
+ guide_style = levels[-1].style or null_style
127
+ levels[-1] = make_guide(FORK, guide_style)
128
+ guide_style_stack.pop()
129
+ style_stack.pop()
130
+ continue
131
+ push(stack_node)
132
+ if last:
133
+ levels[-1] = make_guide(END, levels[-1].style or null_style)
134
+
135
+ guide_style = guide_style_stack.current + get_style(node.guide_style)
136
+ style = style_stack.current + get_style(node.style)
137
+ prefix = levels[(2 if self.hide_root else 1) :]
138
+ renderable_lines = console.render_lines(
139
+ Styled(node.label, style),
140
+ options.update(
141
+ width=options.max_width
142
+ - sum(level.cell_length for level in prefix),
143
+ highlight=self.highlight,
144
+ height=None,
145
+ ),
146
+ pad=options.justify is not None,
147
+ )
148
+
149
+ if not (depth == 0 and self.hide_root):
150
+ for first, line in loop_first(renderable_lines):
151
+ if prefix:
152
+ yield from _Segment.apply_style(
153
+ prefix,
154
+ style.background_style,
155
+ post_style=remove_guide_styles,
156
+ )
157
+ yield from line
158
+ yield new_line
159
+ if first and prefix:
160
+ prefix[-1] = make_guide(
161
+ SPACE if last else CONTINUE, prefix[-1].style or null_style
162
+ )
163
+
164
+ if node.expanded and node.children:
165
+ levels[-1] = make_guide(
166
+ SPACE if last else CONTINUE, levels[-1].style or null_style
167
+ )
168
+ levels.append(
169
+ make_guide(END if len(node.children) == 1 else FORK, guide_style)
170
+ )
171
+ style_stack.push(get_style(node.style))
172
+ guide_style_stack.push(get_style(node.guide_style))
173
+ push(iter(loop_last(node.children)))
174
+ depth += 1
175
+
176
+ def __rich_measure__(
177
+ self, console: "Console", options: "ConsoleOptions"
178
+ ) -> "Measurement":
179
+ stack: List[Iterator[Tree]] = [iter([self])]
180
+ pop = stack.pop
181
+ push = stack.append
182
+ minimum = 0
183
+ maximum = 0
184
+ measure = Measurement.get
185
+ level = 0
186
+ while stack:
187
+ iter_tree = pop()
188
+ try:
189
+ tree = next(iter_tree)
190
+ except StopIteration:
191
+ level -= 1
192
+ continue
193
+ push(iter_tree)
194
+ min_measure, max_measure = measure(console, options, tree.label)
195
+ indent = level * 4
196
+ minimum = max(min_measure + indent, minimum)
197
+ maximum = max(max_measure + indent, maximum)
198
+ if tree.expanded and tree.children:
199
+ push(iter(tree.children))
200
+ level += 1
201
+ return Measurement(minimum, maximum)
202
+
203
+
204
+ if __name__ == "__main__": # pragma: no cover
205
+ from pip._vendor.rich.console import Group
206
+ from pip._vendor.rich.markdown import Markdown
207
+ from pip._vendor.rich.panel import Panel
208
+ from pip._vendor.rich.syntax import Syntax
209
+ from pip._vendor.rich.table import Table
210
+
211
+ table = Table(row_styles=["", "dim"])
212
+
213
+ table.add_column("Released", style="cyan", no_wrap=True)
214
+ table.add_column("Title", style="magenta")
215
+ table.add_column("Box Office", justify="right", style="green")
216
+
217
+ table.add_row("Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$952,110,690")
218
+ table.add_row("May 25, 2018", "Solo: A Star Wars Story", "$393,151,347")
219
+ table.add_row("Dec 15, 2017", "Star Wars Ep. V111: The Last Jedi", "$1,332,539,889")
220
+ table.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,332,439,889")
221
+
222
+ code = """\
223
+ class Segment(NamedTuple):
224
+ text: str = ""
225
+ style: Optional[Style] = None
226
+ is_control: bool = False
227
+ """
228
+ syntax = Syntax(code, "python", theme="monokai", line_numbers=True)
229
+
230
+ markdown = Markdown(
231
+ """\
232
+ ### example.md
233
+ > Hello, World!
234
+ >
235
+ > Markdown _all_ the things
236
+ """
237
+ )
238
+
239
+ root = Tree("🌲 [b green]Rich Tree", highlight=True, hide_root=True)
240
+
241
+ node = root.add(":file_folder: Renderables", guide_style="red")
242
+ simple_node = node.add(":file_folder: [bold yellow]Atomic", guide_style="uu green")
243
+ simple_node.add(Group("📄 Syntax", syntax))
244
+ simple_node.add(Group("📄 Markdown", Panel(markdown, border_style="green")))
245
+
246
+ containers_node = node.add(
247
+ ":file_folder: [bold magenta]Containers", guide_style="bold magenta"
248
+ )
249
+ containers_node.expanded = True
250
+ panel = Panel.fit("Just a panel", border_style="red")
251
+ containers_node.add(Group("📄 Panels", panel))
252
+
253
+ containers_node.add(Group("📄 [b magenta]Table", table))
254
+
255
+ console = Console()
256
+
257
+ console.print(root)
minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/parser_inline.cpython-310.pyc ADDED
Binary file (3.18 kB). View file
 
minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/token.cpython-310.pyc ADDED
Binary file (6.24 kB). View file