plucksquire commited on
Commit
79d8b1d
·
verified ·
1 Parent(s): f5a12f5

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. .venv/Lib/site-packages/pip/_vendor/resolvelib/__init__.py +26 -0
  2. .venv/Lib/site-packages/pip/_vendor/resolvelib/compat/__init__.py +0 -0
  3. .venv/Lib/site-packages/pip/_vendor/resolvelib/compat/collections_abc.py +6 -0
  4. .venv/Lib/site-packages/pip/_vendor/resolvelib/resolvers.py +547 -0
  5. .venv/Lib/site-packages/pip/_vendor/resolvelib/structs.py +170 -0
  6. .venv/Lib/site-packages/pip/_vendor/rich/_cell_widths.py +451 -0
  7. .venv/Lib/site-packages/pip/_vendor/rich/_emoji_codes.py +0 -0
  8. .venv/Lib/site-packages/pip/_vendor/rich/_emoji_replace.py +32 -0
  9. .venv/Lib/site-packages/pip/_vendor/rich/_export_format.py +76 -0
  10. .venv/Lib/site-packages/pip/_vendor/rich/_extension.py +10 -0
  11. .venv/Lib/site-packages/pip/_vendor/rich/_fileno.py +24 -0
  12. .venv/Lib/site-packages/pip/_vendor/rich/_inspect.py +270 -0
  13. .venv/Lib/site-packages/pip/_vendor/rich/_log_render.py +94 -0
  14. .venv/Lib/site-packages/pip/_vendor/rich/_loop.py +43 -0
  15. .venv/Lib/site-packages/pip/_vendor/rich/_null_file.py +69 -0
  16. .venv/Lib/site-packages/pip/_vendor/rich/_palettes.py +309 -0
  17. .venv/Lib/site-packages/pip/_vendor/rich/_pick.py +17 -0
  18. .venv/Lib/site-packages/pip/_vendor/rich/_ratio.py +160 -0
  19. .venv/Lib/site-packages/pip/_vendor/rich/_spinners.py +482 -0
  20. .venv/Lib/site-packages/pip/_vendor/rich/_stack.py +16 -0
  21. .venv/Lib/site-packages/pip/_vendor/rich/abc.py +33 -0
  22. .venv/Lib/site-packages/pip/_vendor/rich/align.py +311 -0
  23. .venv/Lib/site-packages/pip/_vendor/rich/ansi.py +240 -0
  24. .venv/Lib/site-packages/pip/_vendor/rich/bar.py +94 -0
  25. .venv/Lib/site-packages/pip/_vendor/rich/box.py +517 -0
  26. .venv/Lib/site-packages/pip/_vendor/rich/cells.py +154 -0
  27. .venv/Lib/site-packages/pip/_vendor/rich/color.py +622 -0
  28. .venv/Lib/site-packages/pip/_vendor/rich/color_triplet.py +38 -0
  29. .venv/Lib/site-packages/pip/_vendor/rich/columns.py +187 -0
  30. .venv/Lib/site-packages/pip/_vendor/rich/console.py +0 -0
  31. .venv/Lib/site-packages/pip/_vendor/rich/constrain.py +37 -0
  32. .venv/Lib/site-packages/pip/_vendor/rich/containers.py +167 -0
  33. .venv/Lib/site-packages/pip/_vendor/rich/control.py +225 -0
  34. .venv/Lib/site-packages/pip/_vendor/rich/default_styles.py +190 -0
  35. .venv/Lib/site-packages/pip/_vendor/rich/diagnose.py +37 -0
  36. .venv/Lib/site-packages/pip/_vendor/rich/emoji.py +96 -0
  37. .venv/Lib/site-packages/pip/_vendor/rich/errors.py +34 -0
  38. .venv/Lib/site-packages/pip/_vendor/rich/file_proxy.py +57 -0
  39. .venv/Lib/site-packages/pip/_vendor/rich/filesize.py +89 -0
  40. .venv/Lib/site-packages/pip/_vendor/rich/highlighter.py +232 -0
  41. .venv/Lib/site-packages/pip/_vendor/rich/json.py +140 -0
  42. .venv/Lib/site-packages/pip/_vendor/rich/jupyter.py +101 -0
  43. .venv/Lib/site-packages/pip/_vendor/rich/layout.py +443 -0
  44. .venv/Lib/site-packages/pip/_vendor/rich/live.py +375 -0
  45. .venv/Lib/site-packages/pip/_vendor/rich/live_render.py +113 -0
  46. .venv/Lib/site-packages/pip/_vendor/rich/logging.py +289 -0
  47. .venv/Lib/site-packages/pip/_vendor/rich/markup.py +246 -0
  48. .venv/Lib/site-packages/pip/_vendor/rich/measure.py +151 -0
  49. .venv/Lib/site-packages/pip/_vendor/rich/padding.py +141 -0
  50. .venv/Lib/site-packages/pip/_vendor/rich/pager.py +34 -0
.venv/Lib/site-packages/pip/_vendor/resolvelib/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __all__ = [
2
+ "__version__",
3
+ "AbstractProvider",
4
+ "AbstractResolver",
5
+ "BaseReporter",
6
+ "InconsistentCandidate",
7
+ "Resolver",
8
+ "RequirementsConflicted",
9
+ "ResolutionError",
10
+ "ResolutionImpossible",
11
+ "ResolutionTooDeep",
12
+ ]
13
+
14
+ __version__ = "1.0.1"
15
+
16
+
17
+ from .providers import AbstractProvider, AbstractResolver
18
+ from .reporters import BaseReporter
19
+ from .resolvers import (
20
+ InconsistentCandidate,
21
+ RequirementsConflicted,
22
+ ResolutionError,
23
+ ResolutionImpossible,
24
+ ResolutionTooDeep,
25
+ Resolver,
26
+ )
.venv/Lib/site-packages/pip/_vendor/resolvelib/compat/__init__.py ADDED
File without changes
.venv/Lib/site-packages/pip/_vendor/resolvelib/compat/collections_abc.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ __all__ = ["Mapping", "Sequence"]
2
+
3
+ try:
4
+ from collections.abc import Mapping, Sequence
5
+ except ImportError:
6
+ from collections import Mapping, Sequence
.venv/Lib/site-packages/pip/_vendor/resolvelib/resolvers.py ADDED
@@ -0,0 +1,547 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import collections
2
+ import itertools
3
+ import operator
4
+
5
+ from .providers import AbstractResolver
6
+ from .structs import DirectedGraph, IteratorMapping, build_iter_view
7
+
8
+ RequirementInformation = collections.namedtuple(
9
+ "RequirementInformation", ["requirement", "parent"]
10
+ )
11
+
12
+
13
+ class ResolverException(Exception):
14
+ """A base class for all exceptions raised by this module.
15
+
16
+ Exceptions derived by this class should all be handled in this module. Any
17
+ bubbling pass the resolver should be treated as a bug.
18
+ """
19
+
20
+
21
+ class RequirementsConflicted(ResolverException):
22
+ def __init__(self, criterion):
23
+ super(RequirementsConflicted, self).__init__(criterion)
24
+ self.criterion = criterion
25
+
26
+ def __str__(self):
27
+ return "Requirements conflict: {}".format(
28
+ ", ".join(repr(r) for r in self.criterion.iter_requirement()),
29
+ )
30
+
31
+
32
+ class InconsistentCandidate(ResolverException):
33
+ def __init__(self, candidate, criterion):
34
+ super(InconsistentCandidate, self).__init__(candidate, criterion)
35
+ self.candidate = candidate
36
+ self.criterion = criterion
37
+
38
+ def __str__(self):
39
+ return "Provided candidate {!r} does not satisfy {}".format(
40
+ self.candidate,
41
+ ", ".join(repr(r) for r in self.criterion.iter_requirement()),
42
+ )
43
+
44
+
45
+ class Criterion(object):
46
+ """Representation of possible resolution results of a package.
47
+
48
+ This holds three attributes:
49
+
50
+ * `information` is a collection of `RequirementInformation` pairs.
51
+ Each pair is a requirement contributing to this criterion, and the
52
+ candidate that provides the requirement.
53
+ * `incompatibilities` is a collection of all known not-to-work candidates
54
+ to exclude from consideration.
55
+ * `candidates` is a collection containing all possible candidates deducted
56
+ from the union of contributing requirements and known incompatibilities.
57
+ It should never be empty, except when the criterion is an attribute of a
58
+ raised `RequirementsConflicted` (in which case it is always empty).
59
+
60
+ .. note::
61
+ This class is intended to be externally immutable. **Do not** mutate
62
+ any of its attribute containers.
63
+ """
64
+
65
+ def __init__(self, candidates, information, incompatibilities):
66
+ self.candidates = candidates
67
+ self.information = information
68
+ self.incompatibilities = incompatibilities
69
+
70
+ def __repr__(self):
71
+ requirements = ", ".join(
72
+ "({!r}, via={!r})".format(req, parent)
73
+ for req, parent in self.information
74
+ )
75
+ return "Criterion({})".format(requirements)
76
+
77
+ def iter_requirement(self):
78
+ return (i.requirement for i in self.information)
79
+
80
+ def iter_parent(self):
81
+ return (i.parent for i in self.information)
82
+
83
+
84
+ class ResolutionError(ResolverException):
85
+ pass
86
+
87
+
88
+ class ResolutionImpossible(ResolutionError):
89
+ def __init__(self, causes):
90
+ super(ResolutionImpossible, self).__init__(causes)
91
+ # causes is a list of RequirementInformation objects
92
+ self.causes = causes
93
+
94
+
95
+ class ResolutionTooDeep(ResolutionError):
96
+ def __init__(self, round_count):
97
+ super(ResolutionTooDeep, self).__init__(round_count)
98
+ self.round_count = round_count
99
+
100
+
101
+ # Resolution state in a round.
102
+ State = collections.namedtuple("State", "mapping criteria backtrack_causes")
103
+
104
+
105
+ class Resolution(object):
106
+ """Stateful resolution object.
107
+
108
+ This is designed as a one-off object that holds information to kick start
109
+ the resolution process, and holds the results afterwards.
110
+ """
111
+
112
+ def __init__(self, provider, reporter):
113
+ self._p = provider
114
+ self._r = reporter
115
+ self._states = []
116
+
117
+ @property
118
+ def state(self):
119
+ try:
120
+ return self._states[-1]
121
+ except IndexError:
122
+ raise AttributeError("state")
123
+
124
+ def _push_new_state(self):
125
+ """Push a new state into history.
126
+
127
+ This new state will be used to hold resolution results of the next
128
+ coming round.
129
+ """
130
+ base = self._states[-1]
131
+ state = State(
132
+ mapping=base.mapping.copy(),
133
+ criteria=base.criteria.copy(),
134
+ backtrack_causes=base.backtrack_causes[:],
135
+ )
136
+ self._states.append(state)
137
+
138
+ def _add_to_criteria(self, criteria, requirement, parent):
139
+ self._r.adding_requirement(requirement=requirement, parent=parent)
140
+
141
+ identifier = self._p.identify(requirement_or_candidate=requirement)
142
+ criterion = criteria.get(identifier)
143
+ if criterion:
144
+ incompatibilities = list(criterion.incompatibilities)
145
+ else:
146
+ incompatibilities = []
147
+
148
+ matches = self._p.find_matches(
149
+ identifier=identifier,
150
+ requirements=IteratorMapping(
151
+ criteria,
152
+ operator.methodcaller("iter_requirement"),
153
+ {identifier: [requirement]},
154
+ ),
155
+ incompatibilities=IteratorMapping(
156
+ criteria,
157
+ operator.attrgetter("incompatibilities"),
158
+ {identifier: incompatibilities},
159
+ ),
160
+ )
161
+
162
+ if criterion:
163
+ information = list(criterion.information)
164
+ information.append(RequirementInformation(requirement, parent))
165
+ else:
166
+ information = [RequirementInformation(requirement, parent)]
167
+
168
+ criterion = Criterion(
169
+ candidates=build_iter_view(matches),
170
+ information=information,
171
+ incompatibilities=incompatibilities,
172
+ )
173
+ if not criterion.candidates:
174
+ raise RequirementsConflicted(criterion)
175
+ criteria[identifier] = criterion
176
+
177
+ def _remove_information_from_criteria(self, criteria, parents):
178
+ """Remove information from parents of criteria.
179
+
180
+ Concretely, removes all values from each criterion's ``information``
181
+ field that have one of ``parents`` as provider of the requirement.
182
+
183
+ :param criteria: The criteria to update.
184
+ :param parents: Identifiers for which to remove information from all criteria.
185
+ """
186
+ if not parents:
187
+ return
188
+ for key, criterion in criteria.items():
189
+ criteria[key] = Criterion(
190
+ criterion.candidates,
191
+ [
192
+ information
193
+ for information in criterion.information
194
+ if (
195
+ information.parent is None
196
+ or self._p.identify(information.parent) not in parents
197
+ )
198
+ ],
199
+ criterion.incompatibilities,
200
+ )
201
+
202
+ def _get_preference(self, name):
203
+ return self._p.get_preference(
204
+ identifier=name,
205
+ resolutions=self.state.mapping,
206
+ candidates=IteratorMapping(
207
+ self.state.criteria,
208
+ operator.attrgetter("candidates"),
209
+ ),
210
+ information=IteratorMapping(
211
+ self.state.criteria,
212
+ operator.attrgetter("information"),
213
+ ),
214
+ backtrack_causes=self.state.backtrack_causes,
215
+ )
216
+
217
+ def _is_current_pin_satisfying(self, name, criterion):
218
+ try:
219
+ current_pin = self.state.mapping[name]
220
+ except KeyError:
221
+ return False
222
+ return all(
223
+ self._p.is_satisfied_by(requirement=r, candidate=current_pin)
224
+ for r in criterion.iter_requirement()
225
+ )
226
+
227
+ def _get_updated_criteria(self, candidate):
228
+ criteria = self.state.criteria.copy()
229
+ for requirement in self._p.get_dependencies(candidate=candidate):
230
+ self._add_to_criteria(criteria, requirement, parent=candidate)
231
+ return criteria
232
+
233
+ def _attempt_to_pin_criterion(self, name):
234
+ criterion = self.state.criteria[name]
235
+
236
+ causes = []
237
+ for candidate in criterion.candidates:
238
+ try:
239
+ criteria = self._get_updated_criteria(candidate)
240
+ except RequirementsConflicted as e:
241
+ self._r.rejecting_candidate(e.criterion, candidate)
242
+ causes.append(e.criterion)
243
+ continue
244
+
245
+ # Check the newly-pinned candidate actually works. This should
246
+ # always pass under normal circumstances, but in the case of a
247
+ # faulty provider, we will raise an error to notify the implementer
248
+ # to fix find_matches() and/or is_satisfied_by().
249
+ satisfied = all(
250
+ self._p.is_satisfied_by(requirement=r, candidate=candidate)
251
+ for r in criterion.iter_requirement()
252
+ )
253
+ if not satisfied:
254
+ raise InconsistentCandidate(candidate, criterion)
255
+
256
+ self._r.pinning(candidate=candidate)
257
+ self.state.criteria.update(criteria)
258
+
259
+ # Put newly-pinned candidate at the end. This is essential because
260
+ # backtracking looks at this mapping to get the last pin.
261
+ self.state.mapping.pop(name, None)
262
+ self.state.mapping[name] = candidate
263
+
264
+ return []
265
+
266
+ # All candidates tried, nothing works. This criterion is a dead
267
+ # end, signal for backtracking.
268
+ return causes
269
+
270
+ def _backjump(self, causes):
271
+ """Perform backjumping.
272
+
273
+ When we enter here, the stack is like this::
274
+
275
+ [ state Z ]
276
+ [ state Y ]
277
+ [ state X ]
278
+ .... earlier states are irrelevant.
279
+
280
+ 1. No pins worked for Z, so it does not have a pin.
281
+ 2. We want to reset state Y to unpinned, and pin another candidate.
282
+ 3. State X holds what state Y was before the pin, but does not
283
+ have the incompatibility information gathered in state Y.
284
+
285
+ Each iteration of the loop will:
286
+
287
+ 1. Identify Z. The incompatibility is not always caused by the latest
288
+ state. For example, given three requirements A, B and C, with
289
+ dependencies A1, B1 and C1, where A1 and B1 are incompatible: the
290
+ last state might be related to C, so we want to discard the
291
+ previous state.
292
+ 2. Discard Z.
293
+ 3. Discard Y but remember its incompatibility information gathered
294
+ previously, and the failure we're dealing with right now.
295
+ 4. Push a new state Y' based on X, and apply the incompatibility
296
+ information from Y to Y'.
297
+ 5a. If this causes Y' to conflict, we need to backtrack again. Make Y'
298
+ the new Z and go back to step 2.
299
+ 5b. If the incompatibilities apply cleanly, end backtracking.
300
+ """
301
+ incompatible_reqs = itertools.chain(
302
+ (c.parent for c in causes if c.parent is not None),
303
+ (c.requirement for c in causes),
304
+ )
305
+ incompatible_deps = {self._p.identify(r) for r in incompatible_reqs}
306
+ while len(self._states) >= 3:
307
+ # Remove the state that triggered backtracking.
308
+ del self._states[-1]
309
+
310
+ # Ensure to backtrack to a state that caused the incompatibility
311
+ incompatible_state = False
312
+ while not incompatible_state:
313
+ # Retrieve the last candidate pin and known incompatibilities.
314
+ try:
315
+ broken_state = self._states.pop()
316
+ name, candidate = broken_state.mapping.popitem()
317
+ except (IndexError, KeyError):
318
+ raise ResolutionImpossible(causes)
319
+ current_dependencies = {
320
+ self._p.identify(d)
321
+ for d in self._p.get_dependencies(candidate)
322
+ }
323
+ incompatible_state = not current_dependencies.isdisjoint(
324
+ incompatible_deps
325
+ )
326
+
327
+ incompatibilities_from_broken = [
328
+ (k, list(v.incompatibilities))
329
+ for k, v in broken_state.criteria.items()
330
+ ]
331
+
332
+ # Also mark the newly known incompatibility.
333
+ incompatibilities_from_broken.append((name, [candidate]))
334
+
335
+ # Create a new state from the last known-to-work one, and apply
336
+ # the previously gathered incompatibility information.
337
+ def _patch_criteria():
338
+ for k, incompatibilities in incompatibilities_from_broken:
339
+ if not incompatibilities:
340
+ continue
341
+ try:
342
+ criterion = self.state.criteria[k]
343
+ except KeyError:
344
+ continue
345
+ matches = self._p.find_matches(
346
+ identifier=k,
347
+ requirements=IteratorMapping(
348
+ self.state.criteria,
349
+ operator.methodcaller("iter_requirement"),
350
+ ),
351
+ incompatibilities=IteratorMapping(
352
+ self.state.criteria,
353
+ operator.attrgetter("incompatibilities"),
354
+ {k: incompatibilities},
355
+ ),
356
+ )
357
+ candidates = build_iter_view(matches)
358
+ if not candidates:
359
+ return False
360
+ incompatibilities.extend(criterion.incompatibilities)
361
+ self.state.criteria[k] = Criterion(
362
+ candidates=candidates,
363
+ information=list(criterion.information),
364
+ incompatibilities=incompatibilities,
365
+ )
366
+ return True
367
+
368
+ self._push_new_state()
369
+ success = _patch_criteria()
370
+
371
+ # It works! Let's work on this new state.
372
+ if success:
373
+ return True
374
+
375
+ # State does not work after applying known incompatibilities.
376
+ # Try the still previous state.
377
+
378
+ # No way to backtrack anymore.
379
+ return False
380
+
381
+ def resolve(self, requirements, max_rounds):
382
+ if self._states:
383
+ raise RuntimeError("already resolved")
384
+
385
+ self._r.starting()
386
+
387
+ # Initialize the root state.
388
+ self._states = [
389
+ State(
390
+ mapping=collections.OrderedDict(),
391
+ criteria={},
392
+ backtrack_causes=[],
393
+ )
394
+ ]
395
+ for r in requirements:
396
+ try:
397
+ self._add_to_criteria(self.state.criteria, r, parent=None)
398
+ except RequirementsConflicted as e:
399
+ raise ResolutionImpossible(e.criterion.information)
400
+
401
+ # The root state is saved as a sentinel so the first ever pin can have
402
+ # something to backtrack to if it fails. The root state is basically
403
+ # pinning the virtual "root" package in the graph.
404
+ self._push_new_state()
405
+
406
+ for round_index in range(max_rounds):
407
+ self._r.starting_round(index=round_index)
408
+
409
+ unsatisfied_names = [
410
+ key
411
+ for key, criterion in self.state.criteria.items()
412
+ if not self._is_current_pin_satisfying(key, criterion)
413
+ ]
414
+
415
+ # All criteria are accounted for. Nothing more to pin, we are done!
416
+ if not unsatisfied_names:
417
+ self._r.ending(state=self.state)
418
+ return self.state
419
+
420
+ # keep track of satisfied names to calculate diff after pinning
421
+ satisfied_names = set(self.state.criteria.keys()) - set(
422
+ unsatisfied_names
423
+ )
424
+
425
+ # Choose the most preferred unpinned criterion to try.
426
+ name = min(unsatisfied_names, key=self._get_preference)
427
+ failure_causes = self._attempt_to_pin_criterion(name)
428
+
429
+ if failure_causes:
430
+ causes = [i for c in failure_causes for i in c.information]
431
+ # Backjump if pinning fails. The backjump process puts us in
432
+ # an unpinned state, so we can work on it in the next round.
433
+ self._r.resolving_conflicts(causes=causes)
434
+ success = self._backjump(causes)
435
+ self.state.backtrack_causes[:] = causes
436
+
437
+ # Dead ends everywhere. Give up.
438
+ if not success:
439
+ raise ResolutionImpossible(self.state.backtrack_causes)
440
+ else:
441
+ # discard as information sources any invalidated names
442
+ # (unsatisfied names that were previously satisfied)
443
+ newly_unsatisfied_names = {
444
+ key
445
+ for key, criterion in self.state.criteria.items()
446
+ if key in satisfied_names
447
+ and not self._is_current_pin_satisfying(key, criterion)
448
+ }
449
+ self._remove_information_from_criteria(
450
+ self.state.criteria, newly_unsatisfied_names
451
+ )
452
+ # Pinning was successful. Push a new state to do another pin.
453
+ self._push_new_state()
454
+
455
+ self._r.ending_round(index=round_index, state=self.state)
456
+
457
+ raise ResolutionTooDeep(max_rounds)
458
+
459
+
460
+ def _has_route_to_root(criteria, key, all_keys, connected):
461
+ if key in connected:
462
+ return True
463
+ if key not in criteria:
464
+ return False
465
+ for p in criteria[key].iter_parent():
466
+ try:
467
+ pkey = all_keys[id(p)]
468
+ except KeyError:
469
+ continue
470
+ if pkey in connected:
471
+ connected.add(key)
472
+ return True
473
+ if _has_route_to_root(criteria, pkey, all_keys, connected):
474
+ connected.add(key)
475
+ return True
476
+ return False
477
+
478
+
479
+ Result = collections.namedtuple("Result", "mapping graph criteria")
480
+
481
+
482
+ def _build_result(state):
483
+ mapping = state.mapping
484
+ all_keys = {id(v): k for k, v in mapping.items()}
485
+ all_keys[id(None)] = None
486
+
487
+ graph = DirectedGraph()
488
+ graph.add(None) # Sentinel as root dependencies' parent.
489
+
490
+ connected = {None}
491
+ for key, criterion in state.criteria.items():
492
+ if not _has_route_to_root(state.criteria, key, all_keys, connected):
493
+ continue
494
+ if key not in graph:
495
+ graph.add(key)
496
+ for p in criterion.iter_parent():
497
+ try:
498
+ pkey = all_keys[id(p)]
499
+ except KeyError:
500
+ continue
501
+ if pkey not in graph:
502
+ graph.add(pkey)
503
+ graph.connect(pkey, key)
504
+
505
+ return Result(
506
+ mapping={k: v for k, v in mapping.items() if k in connected},
507
+ graph=graph,
508
+ criteria=state.criteria,
509
+ )
510
+
511
+
512
+ class Resolver(AbstractResolver):
513
+ """The thing that performs the actual resolution work."""
514
+
515
+ base_exception = ResolverException
516
+
517
+ def resolve(self, requirements, max_rounds=100):
518
+ """Take a collection of constraints, spit out the resolution result.
519
+
520
+ The return value is a representation to the final resolution result. It
521
+ is a tuple subclass with three public members:
522
+
523
+ * `mapping`: A dict of resolved candidates. Each key is an identifier
524
+ of a requirement (as returned by the provider's `identify` method),
525
+ and the value is the resolved candidate.
526
+ * `graph`: A `DirectedGraph` instance representing the dependency tree.
527
+ The vertices are keys of `mapping`, and each edge represents *why*
528
+ a particular package is included. A special vertex `None` is
529
+ included to represent parents of user-supplied requirements.
530
+ * `criteria`: A dict of "criteria" that hold detailed information on
531
+ how edges in the graph are derived. Each key is an identifier of a
532
+ requirement, and the value is a `Criterion` instance.
533
+
534
+ The following exceptions may be raised if a resolution cannot be found:
535
+
536
+ * `ResolutionImpossible`: A resolution cannot be found for the given
537
+ combination of requirements. The `causes` attribute of the
538
+ exception is a list of (requirement, parent), giving the
539
+ requirements that could not be satisfied.
540
+ * `ResolutionTooDeep`: The dependency tree is too deeply nested and
541
+ the resolver gave up. This is usually caused by a circular
542
+ dependency, but you can try to resolve this by increasing the
543
+ `max_rounds` argument.
544
+ """
545
+ resolution = Resolution(self.provider, self.reporter)
546
+ state = resolution.resolve(requirements, max_rounds=max_rounds)
547
+ return _build_result(state)
.venv/Lib/site-packages/pip/_vendor/resolvelib/structs.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import itertools
2
+
3
+ from .compat import collections_abc
4
+
5
+
6
+ class DirectedGraph(object):
7
+ """A graph structure with directed edges."""
8
+
9
+ def __init__(self):
10
+ self._vertices = set()
11
+ self._forwards = {} # <key> -> Set[<key>]
12
+ self._backwards = {} # <key> -> Set[<key>]
13
+
14
+ def __iter__(self):
15
+ return iter(self._vertices)
16
+
17
+ def __len__(self):
18
+ return len(self._vertices)
19
+
20
+ def __contains__(self, key):
21
+ return key in self._vertices
22
+
23
+ def copy(self):
24
+ """Return a shallow copy of this graph."""
25
+ other = DirectedGraph()
26
+ other._vertices = set(self._vertices)
27
+ other._forwards = {k: set(v) for k, v in self._forwards.items()}
28
+ other._backwards = {k: set(v) for k, v in self._backwards.items()}
29
+ return other
30
+
31
+ def add(self, key):
32
+ """Add a new vertex to the graph."""
33
+ if key in self._vertices:
34
+ raise ValueError("vertex exists")
35
+ self._vertices.add(key)
36
+ self._forwards[key] = set()
37
+ self._backwards[key] = set()
38
+
39
+ def remove(self, key):
40
+ """Remove a vertex from the graph, disconnecting all edges from/to it."""
41
+ self._vertices.remove(key)
42
+ for f in self._forwards.pop(key):
43
+ self._backwards[f].remove(key)
44
+ for t in self._backwards.pop(key):
45
+ self._forwards[t].remove(key)
46
+
47
+ def connected(self, f, t):
48
+ return f in self._backwards[t] and t in self._forwards[f]
49
+
50
+ def connect(self, f, t):
51
+ """Connect two existing vertices.
52
+
53
+ Nothing happens if the vertices are already connected.
54
+ """
55
+ if t not in self._vertices:
56
+ raise KeyError(t)
57
+ self._forwards[f].add(t)
58
+ self._backwards[t].add(f)
59
+
60
+ def iter_edges(self):
61
+ for f, children in self._forwards.items():
62
+ for t in children:
63
+ yield f, t
64
+
65
+ def iter_children(self, key):
66
+ return iter(self._forwards[key])
67
+
68
+ def iter_parents(self, key):
69
+ return iter(self._backwards[key])
70
+
71
+
72
+ class IteratorMapping(collections_abc.Mapping):
73
+ def __init__(self, mapping, accessor, appends=None):
74
+ self._mapping = mapping
75
+ self._accessor = accessor
76
+ self._appends = appends or {}
77
+
78
+ def __repr__(self):
79
+ return "IteratorMapping({!r}, {!r}, {!r})".format(
80
+ self._mapping,
81
+ self._accessor,
82
+ self._appends,
83
+ )
84
+
85
+ def __bool__(self):
86
+ return bool(self._mapping or self._appends)
87
+
88
+ __nonzero__ = __bool__ # XXX: Python 2.
89
+
90
+ def __contains__(self, key):
91
+ return key in self._mapping or key in self._appends
92
+
93
+ def __getitem__(self, k):
94
+ try:
95
+ v = self._mapping[k]
96
+ except KeyError:
97
+ return iter(self._appends[k])
98
+ return itertools.chain(self._accessor(v), self._appends.get(k, ()))
99
+
100
+ def __iter__(self):
101
+ more = (k for k in self._appends if k not in self._mapping)
102
+ return itertools.chain(self._mapping, more)
103
+
104
+ def __len__(self):
105
+ more = sum(1 for k in self._appends if k not in self._mapping)
106
+ return len(self._mapping) + more
107
+
108
+
109
+ class _FactoryIterableView(object):
110
+ """Wrap an iterator factory returned by `find_matches()`.
111
+
112
+ Calling `iter()` on this class would invoke the underlying iterator
113
+ factory, making it a "collection with ordering" that can be iterated
114
+ through multiple times, but lacks random access methods presented in
115
+ built-in Python sequence types.
116
+ """
117
+
118
+ def __init__(self, factory):
119
+ self._factory = factory
120
+ self._iterable = None
121
+
122
+ def __repr__(self):
123
+ return "{}({})".format(type(self).__name__, list(self))
124
+
125
+ def __bool__(self):
126
+ try:
127
+ next(iter(self))
128
+ except StopIteration:
129
+ return False
130
+ return True
131
+
132
+ __nonzero__ = __bool__ # XXX: Python 2.
133
+
134
+ def __iter__(self):
135
+ iterable = (
136
+ self._factory() if self._iterable is None else self._iterable
137
+ )
138
+ self._iterable, current = itertools.tee(iterable)
139
+ return current
140
+
141
+
142
+ class _SequenceIterableView(object):
143
+ """Wrap an iterable returned by find_matches().
144
+
145
+ This is essentially just a proxy to the underlying sequence that provides
146
+ the same interface as `_FactoryIterableView`.
147
+ """
148
+
149
+ def __init__(self, sequence):
150
+ self._sequence = sequence
151
+
152
+ def __repr__(self):
153
+ return "{}({})".format(type(self).__name__, self._sequence)
154
+
155
+ def __bool__(self):
156
+ return bool(self._sequence)
157
+
158
+ __nonzero__ = __bool__ # XXX: Python 2.
159
+
160
+ def __iter__(self):
161
+ return iter(self._sequence)
162
+
163
+
164
+ def build_iter_view(matches):
165
+ """Build an iterable view from the value returned by `find_matches()`."""
166
+ if callable(matches):
167
+ return _FactoryIterableView(matches)
168
+ if not isinstance(matches, collections_abc.Sequence):
169
+ matches = list(matches)
170
+ return _SequenceIterableView(matches)
.venv/Lib/site-packages/pip/_vendor/rich/_cell_widths.py ADDED
@@ -0,0 +1,451 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Auto generated by make_terminal_widths.py
2
+
3
+ CELL_WIDTHS = [
4
+ (0, 0, 0),
5
+ (1, 31, -1),
6
+ (127, 159, -1),
7
+ (768, 879, 0),
8
+ (1155, 1161, 0),
9
+ (1425, 1469, 0),
10
+ (1471, 1471, 0),
11
+ (1473, 1474, 0),
12
+ (1476, 1477, 0),
13
+ (1479, 1479, 0),
14
+ (1552, 1562, 0),
15
+ (1611, 1631, 0),
16
+ (1648, 1648, 0),
17
+ (1750, 1756, 0),
18
+ (1759, 1764, 0),
19
+ (1767, 1768, 0),
20
+ (1770, 1773, 0),
21
+ (1809, 1809, 0),
22
+ (1840, 1866, 0),
23
+ (1958, 1968, 0),
24
+ (2027, 2035, 0),
25
+ (2045, 2045, 0),
26
+ (2070, 2073, 0),
27
+ (2075, 2083, 0),
28
+ (2085, 2087, 0),
29
+ (2089, 2093, 0),
30
+ (2137, 2139, 0),
31
+ (2259, 2273, 0),
32
+ (2275, 2306, 0),
33
+ (2362, 2362, 0),
34
+ (2364, 2364, 0),
35
+ (2369, 2376, 0),
36
+ (2381, 2381, 0),
37
+ (2385, 2391, 0),
38
+ (2402, 2403, 0),
39
+ (2433, 2433, 0),
40
+ (2492, 2492, 0),
41
+ (2497, 2500, 0),
42
+ (2509, 2509, 0),
43
+ (2530, 2531, 0),
44
+ (2558, 2558, 0),
45
+ (2561, 2562, 0),
46
+ (2620, 2620, 0),
47
+ (2625, 2626, 0),
48
+ (2631, 2632, 0),
49
+ (2635, 2637, 0),
50
+ (2641, 2641, 0),
51
+ (2672, 2673, 0),
52
+ (2677, 2677, 0),
53
+ (2689, 2690, 0),
54
+ (2748, 2748, 0),
55
+ (2753, 2757, 0),
56
+ (2759, 2760, 0),
57
+ (2765, 2765, 0),
58
+ (2786, 2787, 0),
59
+ (2810, 2815, 0),
60
+ (2817, 2817, 0),
61
+ (2876, 2876, 0),
62
+ (2879, 2879, 0),
63
+ (2881, 2884, 0),
64
+ (2893, 2893, 0),
65
+ (2901, 2902, 0),
66
+ (2914, 2915, 0),
67
+ (2946, 2946, 0),
68
+ (3008, 3008, 0),
69
+ (3021, 3021, 0),
70
+ (3072, 3072, 0),
71
+ (3076, 3076, 0),
72
+ (3134, 3136, 0),
73
+ (3142, 3144, 0),
74
+ (3146, 3149, 0),
75
+ (3157, 3158, 0),
76
+ (3170, 3171, 0),
77
+ (3201, 3201, 0),
78
+ (3260, 3260, 0),
79
+ (3263, 3263, 0),
80
+ (3270, 3270, 0),
81
+ (3276, 3277, 0),
82
+ (3298, 3299, 0),
83
+ (3328, 3329, 0),
84
+ (3387, 3388, 0),
85
+ (3393, 3396, 0),
86
+ (3405, 3405, 0),
87
+ (3426, 3427, 0),
88
+ (3457, 3457, 0),
89
+ (3530, 3530, 0),
90
+ (3538, 3540, 0),
91
+ (3542, 3542, 0),
92
+ (3633, 3633, 0),
93
+ (3636, 3642, 0),
94
+ (3655, 3662, 0),
95
+ (3761, 3761, 0),
96
+ (3764, 3772, 0),
97
+ (3784, 3789, 0),
98
+ (3864, 3865, 0),
99
+ (3893, 3893, 0),
100
+ (3895, 3895, 0),
101
+ (3897, 3897, 0),
102
+ (3953, 3966, 0),
103
+ (3968, 3972, 0),
104
+ (3974, 3975, 0),
105
+ (3981, 3991, 0),
106
+ (3993, 4028, 0),
107
+ (4038, 4038, 0),
108
+ (4141, 4144, 0),
109
+ (4146, 4151, 0),
110
+ (4153, 4154, 0),
111
+ (4157, 4158, 0),
112
+ (4184, 4185, 0),
113
+ (4190, 4192, 0),
114
+ (4209, 4212, 0),
115
+ (4226, 4226, 0),
116
+ (4229, 4230, 0),
117
+ (4237, 4237, 0),
118
+ (4253, 4253, 0),
119
+ (4352, 4447, 2),
120
+ (4957, 4959, 0),
121
+ (5906, 5908, 0),
122
+ (5938, 5940, 0),
123
+ (5970, 5971, 0),
124
+ (6002, 6003, 0),
125
+ (6068, 6069, 0),
126
+ (6071, 6077, 0),
127
+ (6086, 6086, 0),
128
+ (6089, 6099, 0),
129
+ (6109, 6109, 0),
130
+ (6155, 6157, 0),
131
+ (6277, 6278, 0),
132
+ (6313, 6313, 0),
133
+ (6432, 6434, 0),
134
+ (6439, 6440, 0),
135
+ (6450, 6450, 0),
136
+ (6457, 6459, 0),
137
+ (6679, 6680, 0),
138
+ (6683, 6683, 0),
139
+ (6742, 6742, 0),
140
+ (6744, 6750, 0),
141
+ (6752, 6752, 0),
142
+ (6754, 6754, 0),
143
+ (6757, 6764, 0),
144
+ (6771, 6780, 0),
145
+ (6783, 6783, 0),
146
+ (6832, 6848, 0),
147
+ (6912, 6915, 0),
148
+ (6964, 6964, 0),
149
+ (6966, 6970, 0),
150
+ (6972, 6972, 0),
151
+ (6978, 6978, 0),
152
+ (7019, 7027, 0),
153
+ (7040, 7041, 0),
154
+ (7074, 7077, 0),
155
+ (7080, 7081, 0),
156
+ (7083, 7085, 0),
157
+ (7142, 7142, 0),
158
+ (7144, 7145, 0),
159
+ (7149, 7149, 0),
160
+ (7151, 7153, 0),
161
+ (7212, 7219, 0),
162
+ (7222, 7223, 0),
163
+ (7376, 7378, 0),
164
+ (7380, 7392, 0),
165
+ (7394, 7400, 0),
166
+ (7405, 7405, 0),
167
+ (7412, 7412, 0),
168
+ (7416, 7417, 0),
169
+ (7616, 7673, 0),
170
+ (7675, 7679, 0),
171
+ (8203, 8207, 0),
172
+ (8232, 8238, 0),
173
+ (8288, 8291, 0),
174
+ (8400, 8432, 0),
175
+ (8986, 8987, 2),
176
+ (9001, 9002, 2),
177
+ (9193, 9196, 2),
178
+ (9200, 9200, 2),
179
+ (9203, 9203, 2),
180
+ (9725, 9726, 2),
181
+ (9748, 9749, 2),
182
+ (9800, 9811, 2),
183
+ (9855, 9855, 2),
184
+ (9875, 9875, 2),
185
+ (9889, 9889, 2),
186
+ (9898, 9899, 2),
187
+ (9917, 9918, 2),
188
+ (9924, 9925, 2),
189
+ (9934, 9934, 2),
190
+ (9940, 9940, 2),
191
+ (9962, 9962, 2),
192
+ (9970, 9971, 2),
193
+ (9973, 9973, 2),
194
+ (9978, 9978, 2),
195
+ (9981, 9981, 2),
196
+ (9989, 9989, 2),
197
+ (9994, 9995, 2),
198
+ (10024, 10024, 2),
199
+ (10060, 10060, 2),
200
+ (10062, 10062, 2),
201
+ (10067, 10069, 2),
202
+ (10071, 10071, 2),
203
+ (10133, 10135, 2),
204
+ (10160, 10160, 2),
205
+ (10175, 10175, 2),
206
+ (11035, 11036, 2),
207
+ (11088, 11088, 2),
208
+ (11093, 11093, 2),
209
+ (11503, 11505, 0),
210
+ (11647, 11647, 0),
211
+ (11744, 11775, 0),
212
+ (11904, 11929, 2),
213
+ (11931, 12019, 2),
214
+ (12032, 12245, 2),
215
+ (12272, 12283, 2),
216
+ (12288, 12329, 2),
217
+ (12330, 12333, 0),
218
+ (12334, 12350, 2),
219
+ (12353, 12438, 2),
220
+ (12441, 12442, 0),
221
+ (12443, 12543, 2),
222
+ (12549, 12591, 2),
223
+ (12593, 12686, 2),
224
+ (12688, 12771, 2),
225
+ (12784, 12830, 2),
226
+ (12832, 12871, 2),
227
+ (12880, 19903, 2),
228
+ (19968, 42124, 2),
229
+ (42128, 42182, 2),
230
+ (42607, 42610, 0),
231
+ (42612, 42621, 0),
232
+ (42654, 42655, 0),
233
+ (42736, 42737, 0),
234
+ (43010, 43010, 0),
235
+ (43014, 43014, 0),
236
+ (43019, 43019, 0),
237
+ (43045, 43046, 0),
238
+ (43052, 43052, 0),
239
+ (43204, 43205, 0),
240
+ (43232, 43249, 0),
241
+ (43263, 43263, 0),
242
+ (43302, 43309, 0),
243
+ (43335, 43345, 0),
244
+ (43360, 43388, 2),
245
+ (43392, 43394, 0),
246
+ (43443, 43443, 0),
247
+ (43446, 43449, 0),
248
+ (43452, 43453, 0),
249
+ (43493, 43493, 0),
250
+ (43561, 43566, 0),
251
+ (43569, 43570, 0),
252
+ (43573, 43574, 0),
253
+ (43587, 43587, 0),
254
+ (43596, 43596, 0),
255
+ (43644, 43644, 0),
256
+ (43696, 43696, 0),
257
+ (43698, 43700, 0),
258
+ (43703, 43704, 0),
259
+ (43710, 43711, 0),
260
+ (43713, 43713, 0),
261
+ (43756, 43757, 0),
262
+ (43766, 43766, 0),
263
+ (44005, 44005, 0),
264
+ (44008, 44008, 0),
265
+ (44013, 44013, 0),
266
+ (44032, 55203, 2),
267
+ (63744, 64255, 2),
268
+ (64286, 64286, 0),
269
+ (65024, 65039, 0),
270
+ (65040, 65049, 2),
271
+ (65056, 65071, 0),
272
+ (65072, 65106, 2),
273
+ (65108, 65126, 2),
274
+ (65128, 65131, 2),
275
+ (65281, 65376, 2),
276
+ (65504, 65510, 2),
277
+ (66045, 66045, 0),
278
+ (66272, 66272, 0),
279
+ (66422, 66426, 0),
280
+ (68097, 68099, 0),
281
+ (68101, 68102, 0),
282
+ (68108, 68111, 0),
283
+ (68152, 68154, 0),
284
+ (68159, 68159, 0),
285
+ (68325, 68326, 0),
286
+ (68900, 68903, 0),
287
+ (69291, 69292, 0),
288
+ (69446, 69456, 0),
289
+ (69633, 69633, 0),
290
+ (69688, 69702, 0),
291
+ (69759, 69761, 0),
292
+ (69811, 69814, 0),
293
+ (69817, 69818, 0),
294
+ (69888, 69890, 0),
295
+ (69927, 69931, 0),
296
+ (69933, 69940, 0),
297
+ (70003, 70003, 0),
298
+ (70016, 70017, 0),
299
+ (70070, 70078, 0),
300
+ (70089, 70092, 0),
301
+ (70095, 70095, 0),
302
+ (70191, 70193, 0),
303
+ (70196, 70196, 0),
304
+ (70198, 70199, 0),
305
+ (70206, 70206, 0),
306
+ (70367, 70367, 0),
307
+ (70371, 70378, 0),
308
+ (70400, 70401, 0),
309
+ (70459, 70460, 0),
310
+ (70464, 70464, 0),
311
+ (70502, 70508, 0),
312
+ (70512, 70516, 0),
313
+ (70712, 70719, 0),
314
+ (70722, 70724, 0),
315
+ (70726, 70726, 0),
316
+ (70750, 70750, 0),
317
+ (70835, 70840, 0),
318
+ (70842, 70842, 0),
319
+ (70847, 70848, 0),
320
+ (70850, 70851, 0),
321
+ (71090, 71093, 0),
322
+ (71100, 71101, 0),
323
+ (71103, 71104, 0),
324
+ (71132, 71133, 0),
325
+ (71219, 71226, 0),
326
+ (71229, 71229, 0),
327
+ (71231, 71232, 0),
328
+ (71339, 71339, 0),
329
+ (71341, 71341, 0),
330
+ (71344, 71349, 0),
331
+ (71351, 71351, 0),
332
+ (71453, 71455, 0),
333
+ (71458, 71461, 0),
334
+ (71463, 71467, 0),
335
+ (71727, 71735, 0),
336
+ (71737, 71738, 0),
337
+ (71995, 71996, 0),
338
+ (71998, 71998, 0),
339
+ (72003, 72003, 0),
340
+ (72148, 72151, 0),
341
+ (72154, 72155, 0),
342
+ (72160, 72160, 0),
343
+ (72193, 72202, 0),
344
+ (72243, 72248, 0),
345
+ (72251, 72254, 0),
346
+ (72263, 72263, 0),
347
+ (72273, 72278, 0),
348
+ (72281, 72283, 0),
349
+ (72330, 72342, 0),
350
+ (72344, 72345, 0),
351
+ (72752, 72758, 0),
352
+ (72760, 72765, 0),
353
+ (72767, 72767, 0),
354
+ (72850, 72871, 0),
355
+ (72874, 72880, 0),
356
+ (72882, 72883, 0),
357
+ (72885, 72886, 0),
358
+ (73009, 73014, 0),
359
+ (73018, 73018, 0),
360
+ (73020, 73021, 0),
361
+ (73023, 73029, 0),
362
+ (73031, 73031, 0),
363
+ (73104, 73105, 0),
364
+ (73109, 73109, 0),
365
+ (73111, 73111, 0),
366
+ (73459, 73460, 0),
367
+ (92912, 92916, 0),
368
+ (92976, 92982, 0),
369
+ (94031, 94031, 0),
370
+ (94095, 94098, 0),
371
+ (94176, 94179, 2),
372
+ (94180, 94180, 0),
373
+ (94192, 94193, 2),
374
+ (94208, 100343, 2),
375
+ (100352, 101589, 2),
376
+ (101632, 101640, 2),
377
+ (110592, 110878, 2),
378
+ (110928, 110930, 2),
379
+ (110948, 110951, 2),
380
+ (110960, 111355, 2),
381
+ (113821, 113822, 0),
382
+ (119143, 119145, 0),
383
+ (119163, 119170, 0),
384
+ (119173, 119179, 0),
385
+ (119210, 119213, 0),
386
+ (119362, 119364, 0),
387
+ (121344, 121398, 0),
388
+ (121403, 121452, 0),
389
+ (121461, 121461, 0),
390
+ (121476, 121476, 0),
391
+ (121499, 121503, 0),
392
+ (121505, 121519, 0),
393
+ (122880, 122886, 0),
394
+ (122888, 122904, 0),
395
+ (122907, 122913, 0),
396
+ (122915, 122916, 0),
397
+ (122918, 122922, 0),
398
+ (123184, 123190, 0),
399
+ (123628, 123631, 0),
400
+ (125136, 125142, 0),
401
+ (125252, 125258, 0),
402
+ (126980, 126980, 2),
403
+ (127183, 127183, 2),
404
+ (127374, 127374, 2),
405
+ (127377, 127386, 2),
406
+ (127488, 127490, 2),
407
+ (127504, 127547, 2),
408
+ (127552, 127560, 2),
409
+ (127568, 127569, 2),
410
+ (127584, 127589, 2),
411
+ (127744, 127776, 2),
412
+ (127789, 127797, 2),
413
+ (127799, 127868, 2),
414
+ (127870, 127891, 2),
415
+ (127904, 127946, 2),
416
+ (127951, 127955, 2),
417
+ (127968, 127984, 2),
418
+ (127988, 127988, 2),
419
+ (127992, 128062, 2),
420
+ (128064, 128064, 2),
421
+ (128066, 128252, 2),
422
+ (128255, 128317, 2),
423
+ (128331, 128334, 2),
424
+ (128336, 128359, 2),
425
+ (128378, 128378, 2),
426
+ (128405, 128406, 2),
427
+ (128420, 128420, 2),
428
+ (128507, 128591, 2),
429
+ (128640, 128709, 2),
430
+ (128716, 128716, 2),
431
+ (128720, 128722, 2),
432
+ (128725, 128727, 2),
433
+ (128747, 128748, 2),
434
+ (128756, 128764, 2),
435
+ (128992, 129003, 2),
436
+ (129292, 129338, 2),
437
+ (129340, 129349, 2),
438
+ (129351, 129400, 2),
439
+ (129402, 129483, 2),
440
+ (129485, 129535, 2),
441
+ (129648, 129652, 2),
442
+ (129656, 129658, 2),
443
+ (129664, 129670, 2),
444
+ (129680, 129704, 2),
445
+ (129712, 129718, 2),
446
+ (129728, 129730, 2),
447
+ (129744, 129750, 2),
448
+ (131072, 196605, 2),
449
+ (196608, 262141, 2),
450
+ (917760, 917999, 0),
451
+ ]
.venv/Lib/site-packages/pip/_vendor/rich/_emoji_codes.py ADDED
The diff for this file is too large to render. See raw diff
 
.venv/Lib/site-packages/pip/_vendor/rich/_emoji_replace.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Callable, Match, Optional
2
+ import re
3
+
4
+ from ._emoji_codes import EMOJI
5
+
6
+
7
+ _ReStringMatch = Match[str] # regex match object
8
+ _ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub
9
+ _EmojiSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re
10
+
11
+
12
+ def _emoji_replace(
13
+ text: str,
14
+ default_variant: Optional[str] = None,
15
+ _emoji_sub: _EmojiSubMethod = re.compile(r"(:(\S*?)(?:(?:\-)(emoji|text))?:)").sub,
16
+ ) -> str:
17
+ """Replace emoji code in text."""
18
+ get_emoji = EMOJI.__getitem__
19
+ variants = {"text": "\uFE0E", "emoji": "\uFE0F"}
20
+ get_variant = variants.get
21
+ default_variant_code = variants.get(default_variant, "") if default_variant else ""
22
+
23
+ def do_replace(match: Match[str]) -> str:
24
+ emoji_code, emoji_name, variant = match.groups()
25
+ try:
26
+ return get_emoji(emoji_name.lower()) + get_variant(
27
+ variant, default_variant_code
28
+ )
29
+ except KeyError:
30
+ return emoji_code
31
+
32
+ return _emoji_sub(do_replace, text)
.venv/Lib/site-packages/pip/_vendor/rich/_export_format.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CONSOLE_HTML_FORMAT = """\
2
+ <!DOCTYPE html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <style>
6
+ {stylesheet}
7
+ body {{
8
+ color: {foreground};
9
+ background-color: {background};
10
+ }}
11
+ </style>
12
+ </head>
13
+ <html>
14
+ <body>
15
+ <pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code>{code}</code></pre>
16
+ </body>
17
+ </html>
18
+ """
19
+
20
+ CONSOLE_SVG_FORMAT = """\
21
+ <svg class="rich-terminal" viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg">
22
+ <!-- Generated with Rich https://www.textualize.io -->
23
+ <style>
24
+
25
+ @font-face {{
26
+ font-family: "Fira Code";
27
+ src: local("FiraCode-Regular"),
28
+ url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
29
+ url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
30
+ font-style: normal;
31
+ font-weight: 400;
32
+ }}
33
+ @font-face {{
34
+ font-family: "Fira Code";
35
+ src: local("FiraCode-Bold"),
36
+ url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
37
+ url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
38
+ font-style: bold;
39
+ font-weight: 700;
40
+ }}
41
+
42
+ .{unique_id}-matrix {{
43
+ font-family: Fira Code, monospace;
44
+ font-size: {char_height}px;
45
+ line-height: {line_height}px;
46
+ font-variant-east-asian: full-width;
47
+ }}
48
+
49
+ .{unique_id}-title {{
50
+ font-size: 18px;
51
+ font-weight: bold;
52
+ font-family: arial;
53
+ }}
54
+
55
+ {styles}
56
+ </style>
57
+
58
+ <defs>
59
+ <clipPath id="{unique_id}-clip-terminal">
60
+ <rect x="0" y="0" width="{terminal_width}" height="{terminal_height}" />
61
+ </clipPath>
62
+ {lines}
63
+ </defs>
64
+
65
+ {chrome}
66
+ <g transform="translate({terminal_x}, {terminal_y})" clip-path="url(#{unique_id}-clip-terminal)">
67
+ {backgrounds}
68
+ <g class="{unique_id}-matrix">
69
+ {matrix}
70
+ </g>
71
+ </g>
72
+ </svg>
73
+ """
74
+
75
+ _SVG_FONT_FAMILY = "Rich Fira Code"
76
+ _SVG_CLASSES_PREFIX = "rich-svg"
.venv/Lib/site-packages/pip/_vendor/rich/_extension.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any
2
+
3
+
4
+ def load_ipython_extension(ip: Any) -> None: # pragma: no cover
5
+ # prevent circular import
6
+ from pip._vendor.rich.pretty import install
7
+ from pip._vendor.rich.traceback import install as tr_install
8
+
9
+ install()
10
+ tr_install()
.venv/Lib/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
.venv/Lib/site-packages/pip/_vendor/rich/_inspect.py ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import absolute_import
2
+
3
+ import inspect
4
+ from inspect import cleandoc, getdoc, getfile, isclass, ismodule, signature
5
+ from typing import Any, Collection, Iterable, Optional, Tuple, Type, Union
6
+
7
+ from .console import Group, RenderableType
8
+ from .control import escape_control_codes
9
+ from .highlighter import ReprHighlighter
10
+ from .jupyter import JupyterMixin
11
+ from .panel import Panel
12
+ from .pretty import Pretty
13
+ from .table import Table
14
+ from .text import Text, TextType
15
+
16
+
17
+ def _first_paragraph(doc: str) -> str:
18
+ """Get the first paragraph from a docstring."""
19
+ paragraph, _, _ = doc.partition("\n\n")
20
+ return paragraph
21
+
22
+
23
+ class Inspect(JupyterMixin):
24
+ """A renderable to inspect any Python Object.
25
+
26
+ Args:
27
+ obj (Any): An object to inspect.
28
+ title (str, optional): Title to display over inspect result, or None use type. Defaults to None.
29
+ help (bool, optional): Show full help text rather than just first paragraph. Defaults to False.
30
+ methods (bool, optional): Enable inspection of callables. Defaults to False.
31
+ docs (bool, optional): Also render doc strings. Defaults to True.
32
+ private (bool, optional): Show private attributes (beginning with underscore). Defaults to False.
33
+ dunder (bool, optional): Show attributes starting with double underscore. Defaults to False.
34
+ sort (bool, optional): Sort attributes alphabetically. Defaults to True.
35
+ all (bool, optional): Show all attributes. Defaults to False.
36
+ value (bool, optional): Pretty print value of object. Defaults to True.
37
+ """
38
+
39
+ def __init__(
40
+ self,
41
+ obj: Any,
42
+ *,
43
+ title: Optional[TextType] = None,
44
+ help: bool = False,
45
+ methods: bool = False,
46
+ docs: bool = True,
47
+ private: bool = False,
48
+ dunder: bool = False,
49
+ sort: bool = True,
50
+ all: bool = True,
51
+ value: bool = True,
52
+ ) -> None:
53
+ self.highlighter = ReprHighlighter()
54
+ self.obj = obj
55
+ self.title = title or self._make_title(obj)
56
+ if all:
57
+ methods = private = dunder = True
58
+ self.help = help
59
+ self.methods = methods
60
+ self.docs = docs or help
61
+ self.private = private or dunder
62
+ self.dunder = dunder
63
+ self.sort = sort
64
+ self.value = value
65
+
66
+ def _make_title(self, obj: Any) -> Text:
67
+ """Make a default title."""
68
+ title_str = (
69
+ str(obj)
70
+ if (isclass(obj) or callable(obj) or ismodule(obj))
71
+ else str(type(obj))
72
+ )
73
+ title_text = self.highlighter(title_str)
74
+ return title_text
75
+
76
+ def __rich__(self) -> Panel:
77
+ return Panel.fit(
78
+ Group(*self._render()),
79
+ title=self.title,
80
+ border_style="scope.border",
81
+ padding=(0, 1),
82
+ )
83
+
84
+ def _get_signature(self, name: str, obj: Any) -> Optional[Text]:
85
+ """Get a signature for a callable."""
86
+ try:
87
+ _signature = str(signature(obj)) + ":"
88
+ except ValueError:
89
+ _signature = "(...)"
90
+ except TypeError:
91
+ return None
92
+
93
+ source_filename: Optional[str] = None
94
+ try:
95
+ source_filename = getfile(obj)
96
+ except (OSError, TypeError):
97
+ # OSError is raised if obj has no source file, e.g. when defined in REPL.
98
+ pass
99
+
100
+ callable_name = Text(name, style="inspect.callable")
101
+ if source_filename:
102
+ callable_name.stylize(f"link file://{source_filename}")
103
+ signature_text = self.highlighter(_signature)
104
+
105
+ qualname = name or getattr(obj, "__qualname__", name)
106
+
107
+ # If obj is a module, there may be classes (which are callable) to display
108
+ if inspect.isclass(obj):
109
+ prefix = "class"
110
+ elif inspect.iscoroutinefunction(obj):
111
+ prefix = "async def"
112
+ else:
113
+ prefix = "def"
114
+
115
+ qual_signature = Text.assemble(
116
+ (f"{prefix} ", f"inspect.{prefix.replace(' ', '_')}"),
117
+ (qualname, "inspect.callable"),
118
+ signature_text,
119
+ )
120
+
121
+ return qual_signature
122
+
123
+ def _render(self) -> Iterable[RenderableType]:
124
+ """Render object."""
125
+
126
+ def sort_items(item: Tuple[str, Any]) -> Tuple[bool, str]:
127
+ key, (_error, value) = item
128
+ return (callable(value), key.strip("_").lower())
129
+
130
+ def safe_getattr(attr_name: str) -> Tuple[Any, Any]:
131
+ """Get attribute or any exception."""
132
+ try:
133
+ return (None, getattr(obj, attr_name))
134
+ except Exception as error:
135
+ return (error, None)
136
+
137
+ obj = self.obj
138
+ keys = dir(obj)
139
+ total_items = len(keys)
140
+ if not self.dunder:
141
+ keys = [key for key in keys if not key.startswith("__")]
142
+ if not self.private:
143
+ keys = [key for key in keys if not key.startswith("_")]
144
+ not_shown_count = total_items - len(keys)
145
+ items = [(key, safe_getattr(key)) for key in keys]
146
+ if self.sort:
147
+ items.sort(key=sort_items)
148
+
149
+ items_table = Table.grid(padding=(0, 1), expand=False)
150
+ items_table.add_column(justify="right")
151
+ add_row = items_table.add_row
152
+ highlighter = self.highlighter
153
+
154
+ if callable(obj):
155
+ signature = self._get_signature("", obj)
156
+ if signature is not None:
157
+ yield signature
158
+ yield ""
159
+
160
+ if self.docs:
161
+ _doc = self._get_formatted_doc(obj)
162
+ if _doc is not None:
163
+ doc_text = Text(_doc, style="inspect.help")
164
+ doc_text = highlighter(doc_text)
165
+ yield doc_text
166
+ yield ""
167
+
168
+ if self.value and not (isclass(obj) or callable(obj) or ismodule(obj)):
169
+ yield Panel(
170
+ Pretty(obj, indent_guides=True, max_length=10, max_string=60),
171
+ border_style="inspect.value.border",
172
+ )
173
+ yield ""
174
+
175
+ for key, (error, value) in items:
176
+ key_text = Text.assemble(
177
+ (
178
+ key,
179
+ "inspect.attr.dunder" if key.startswith("__") else "inspect.attr",
180
+ ),
181
+ (" =", "inspect.equals"),
182
+ )
183
+ if error is not None:
184
+ warning = key_text.copy()
185
+ warning.stylize("inspect.error")
186
+ add_row(warning, highlighter(repr(error)))
187
+ continue
188
+
189
+ if callable(value):
190
+ if not self.methods:
191
+ continue
192
+
193
+ _signature_text = self._get_signature(key, value)
194
+ if _signature_text is None:
195
+ add_row(key_text, Pretty(value, highlighter=highlighter))
196
+ else:
197
+ if self.docs:
198
+ docs = self._get_formatted_doc(value)
199
+ if docs is not None:
200
+ _signature_text.append("\n" if "\n" in docs else " ")
201
+ doc = highlighter(docs)
202
+ doc.stylize("inspect.doc")
203
+ _signature_text.append(doc)
204
+
205
+ add_row(key_text, _signature_text)
206
+ else:
207
+ add_row(key_text, Pretty(value, highlighter=highlighter))
208
+ if items_table.row_count:
209
+ yield items_table
210
+ elif not_shown_count:
211
+ yield Text.from_markup(
212
+ f"[b cyan]{not_shown_count}[/][i] attribute(s) not shown.[/i] "
213
+ f"Run [b][magenta]inspect[/]([not b]inspect[/])[/b] for options."
214
+ )
215
+
216
+ def _get_formatted_doc(self, object_: Any) -> Optional[str]:
217
+ """
218
+ Extract the docstring of an object, process it and returns it.
219
+ The processing consists in cleaning up the doctring's indentation,
220
+ taking only its 1st paragraph if `self.help` is not True,
221
+ and escape its control codes.
222
+
223
+ Args:
224
+ object_ (Any): the object to get the docstring from.
225
+
226
+ Returns:
227
+ Optional[str]: the processed docstring, or None if no docstring was found.
228
+ """
229
+ docs = getdoc(object_)
230
+ if docs is None:
231
+ return None
232
+ docs = cleandoc(docs).strip()
233
+ if not self.help:
234
+ docs = _first_paragraph(docs)
235
+ return escape_control_codes(docs)
236
+
237
+
238
+ def get_object_types_mro(obj: Union[object, Type[Any]]) -> Tuple[type, ...]:
239
+ """Returns the MRO of an object's class, or of the object itself if it's a class."""
240
+ if not hasattr(obj, "__mro__"):
241
+ # N.B. we cannot use `if type(obj) is type` here because it doesn't work with
242
+ # some types of classes, such as the ones that use abc.ABCMeta.
243
+ obj = type(obj)
244
+ return getattr(obj, "__mro__", ())
245
+
246
+
247
+ def get_object_types_mro_as_strings(obj: object) -> Collection[str]:
248
+ """
249
+ Returns the MRO of an object's class as full qualified names, or of the object itself if it's a class.
250
+
251
+ Examples:
252
+ `object_types_mro_as_strings(JSONDecoder)` will return `['json.decoder.JSONDecoder', 'builtins.object']`
253
+ """
254
+ return [
255
+ f'{getattr(type_, "__module__", "")}.{getattr(type_, "__qualname__", "")}'
256
+ for type_ in get_object_types_mro(obj)
257
+ ]
258
+
259
+
260
+ def is_object_one_of_types(
261
+ obj: object, fully_qualified_types_names: Collection[str]
262
+ ) -> bool:
263
+ """
264
+ Returns `True` if the given object's class (or the object itself, if it's a class) has one of the
265
+ fully qualified names in its MRO.
266
+ """
267
+ for type_name in get_object_types_mro_as_strings(obj):
268
+ if type_name in fully_qualified_types_names:
269
+ return True
270
+ return False
.venv/Lib/site-packages/pip/_vendor/rich/_log_render.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ from typing import Iterable, List, Optional, TYPE_CHECKING, Union, Callable
3
+
4
+
5
+ from .text import Text, TextType
6
+
7
+ if TYPE_CHECKING:
8
+ from .console import Console, ConsoleRenderable, RenderableType
9
+ from .table import Table
10
+
11
+ FormatTimeCallable = Callable[[datetime], Text]
12
+
13
+
14
+ class LogRender:
15
+ def __init__(
16
+ self,
17
+ show_time: bool = True,
18
+ show_level: bool = False,
19
+ show_path: bool = True,
20
+ time_format: Union[str, FormatTimeCallable] = "[%x %X]",
21
+ omit_repeated_times: bool = True,
22
+ level_width: Optional[int] = 8,
23
+ ) -> None:
24
+ self.show_time = show_time
25
+ self.show_level = show_level
26
+ self.show_path = show_path
27
+ self.time_format = time_format
28
+ self.omit_repeated_times = omit_repeated_times
29
+ self.level_width = level_width
30
+ self._last_time: Optional[Text] = None
31
+
32
+ def __call__(
33
+ self,
34
+ console: "Console",
35
+ renderables: Iterable["ConsoleRenderable"],
36
+ log_time: Optional[datetime] = None,
37
+ time_format: Optional[Union[str, FormatTimeCallable]] = None,
38
+ level: TextType = "",
39
+ path: Optional[str] = None,
40
+ line_no: Optional[int] = None,
41
+ link_path: Optional[str] = None,
42
+ ) -> "Table":
43
+ from .containers import Renderables
44
+ from .table import Table
45
+
46
+ output = Table.grid(padding=(0, 1))
47
+ output.expand = True
48
+ if self.show_time:
49
+ output.add_column(style="log.time")
50
+ if self.show_level:
51
+ output.add_column(style="log.level", width=self.level_width)
52
+ output.add_column(ratio=1, style="log.message", overflow="fold")
53
+ if self.show_path and path:
54
+ output.add_column(style="log.path")
55
+ row: List["RenderableType"] = []
56
+ if self.show_time:
57
+ log_time = log_time or console.get_datetime()
58
+ time_format = time_format or self.time_format
59
+ if callable(time_format):
60
+ log_time_display = time_format(log_time)
61
+ else:
62
+ log_time_display = Text(log_time.strftime(time_format))
63
+ if log_time_display == self._last_time and self.omit_repeated_times:
64
+ row.append(Text(" " * len(log_time_display)))
65
+ else:
66
+ row.append(log_time_display)
67
+ self._last_time = log_time_display
68
+ if self.show_level:
69
+ row.append(level)
70
+
71
+ row.append(Renderables(renderables))
72
+ if self.show_path and path:
73
+ path_text = Text()
74
+ path_text.append(
75
+ path, style=f"link file://{link_path}" if link_path else ""
76
+ )
77
+ if line_no:
78
+ path_text.append(":")
79
+ path_text.append(
80
+ f"{line_no}",
81
+ style=f"link file://{link_path}#{line_no}" if link_path else "",
82
+ )
83
+ row.append(path_text)
84
+
85
+ output.add_row(*row)
86
+ return output
87
+
88
+
89
+ if __name__ == "__main__": # pragma: no cover
90
+ from pip._vendor.rich.console import Console
91
+
92
+ c = Console()
93
+ c.print("[on blue]Hello", justify="right")
94
+ c.log("[on blue]hello", justify="right")
.venv/Lib/site-packages/pip/_vendor/rich/_loop.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Iterable, Tuple, TypeVar
2
+
3
+ T = TypeVar("T")
4
+
5
+
6
+ def loop_first(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
7
+ """Iterate and generate a tuple with a flag for first value."""
8
+ iter_values = iter(values)
9
+ try:
10
+ value = next(iter_values)
11
+ except StopIteration:
12
+ return
13
+ yield True, value
14
+ for value in iter_values:
15
+ yield False, value
16
+
17
+
18
+ def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
19
+ """Iterate and generate a tuple with a flag for last value."""
20
+ iter_values = iter(values)
21
+ try:
22
+ previous_value = next(iter_values)
23
+ except StopIteration:
24
+ return
25
+ for value in iter_values:
26
+ yield False, previous_value
27
+ previous_value = value
28
+ yield True, previous_value
29
+
30
+
31
+ def loop_first_last(values: Iterable[T]) -> Iterable[Tuple[bool, bool, T]]:
32
+ """Iterate and generate a tuple with a flag for first and last value."""
33
+ iter_values = iter(values)
34
+ try:
35
+ previous_value = next(iter_values)
36
+ except StopIteration:
37
+ return
38
+ first = True
39
+ for value in iter_values:
40
+ yield first, False, previous_value
41
+ first = False
42
+ previous_value = value
43
+ yield first, True, previous_value
.venv/Lib/site-packages/pip/_vendor/rich/_null_file.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from types import TracebackType
2
+ from typing import IO, Iterable, Iterator, List, Optional, Type
3
+
4
+
5
+ class NullFile(IO[str]):
6
+ def close(self) -> None:
7
+ pass
8
+
9
+ def isatty(self) -> bool:
10
+ return False
11
+
12
+ def read(self, __n: int = 1) -> str:
13
+ return ""
14
+
15
+ def readable(self) -> bool:
16
+ return False
17
+
18
+ def readline(self, __limit: int = 1) -> str:
19
+ return ""
20
+
21
+ def readlines(self, __hint: int = 1) -> List[str]:
22
+ return []
23
+
24
+ def seek(self, __offset: int, __whence: int = 1) -> int:
25
+ return 0
26
+
27
+ def seekable(self) -> bool:
28
+ return False
29
+
30
+ def tell(self) -> int:
31
+ return 0
32
+
33
+ def truncate(self, __size: Optional[int] = 1) -> int:
34
+ return 0
35
+
36
+ def writable(self) -> bool:
37
+ return False
38
+
39
+ def writelines(self, __lines: Iterable[str]) -> None:
40
+ pass
41
+
42
+ def __next__(self) -> str:
43
+ return ""
44
+
45
+ def __iter__(self) -> Iterator[str]:
46
+ return iter([""])
47
+
48
+ def __enter__(self) -> IO[str]:
49
+ pass
50
+
51
+ def __exit__(
52
+ self,
53
+ __t: Optional[Type[BaseException]],
54
+ __value: Optional[BaseException],
55
+ __traceback: Optional[TracebackType],
56
+ ) -> None:
57
+ pass
58
+
59
+ def write(self, text: str) -> int:
60
+ return 0
61
+
62
+ def flush(self) -> None:
63
+ pass
64
+
65
+ def fileno(self) -> int:
66
+ return -1
67
+
68
+
69
+ NULL_FILE = NullFile()
.venv/Lib/site-packages/pip/_vendor/rich/_palettes.py ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .palette import Palette
2
+
3
+
4
+ # Taken from https://en.wikipedia.org/wiki/ANSI_escape_code (Windows 10 column)
5
+ WINDOWS_PALETTE = Palette(
6
+ [
7
+ (12, 12, 12),
8
+ (197, 15, 31),
9
+ (19, 161, 14),
10
+ (193, 156, 0),
11
+ (0, 55, 218),
12
+ (136, 23, 152),
13
+ (58, 150, 221),
14
+ (204, 204, 204),
15
+ (118, 118, 118),
16
+ (231, 72, 86),
17
+ (22, 198, 12),
18
+ (249, 241, 165),
19
+ (59, 120, 255),
20
+ (180, 0, 158),
21
+ (97, 214, 214),
22
+ (242, 242, 242),
23
+ ]
24
+ )
25
+
26
+ # # The standard ansi colors (including bright variants)
27
+ STANDARD_PALETTE = Palette(
28
+ [
29
+ (0, 0, 0),
30
+ (170, 0, 0),
31
+ (0, 170, 0),
32
+ (170, 85, 0),
33
+ (0, 0, 170),
34
+ (170, 0, 170),
35
+ (0, 170, 170),
36
+ (170, 170, 170),
37
+ (85, 85, 85),
38
+ (255, 85, 85),
39
+ (85, 255, 85),
40
+ (255, 255, 85),
41
+ (85, 85, 255),
42
+ (255, 85, 255),
43
+ (85, 255, 255),
44
+ (255, 255, 255),
45
+ ]
46
+ )
47
+
48
+
49
+ # The 256 color palette
50
+ EIGHT_BIT_PALETTE = Palette(
51
+ [
52
+ (0, 0, 0),
53
+ (128, 0, 0),
54
+ (0, 128, 0),
55
+ (128, 128, 0),
56
+ (0, 0, 128),
57
+ (128, 0, 128),
58
+ (0, 128, 128),
59
+ (192, 192, 192),
60
+ (128, 128, 128),
61
+ (255, 0, 0),
62
+ (0, 255, 0),
63
+ (255, 255, 0),
64
+ (0, 0, 255),
65
+ (255, 0, 255),
66
+ (0, 255, 255),
67
+ (255, 255, 255),
68
+ (0, 0, 0),
69
+ (0, 0, 95),
70
+ (0, 0, 135),
71
+ (0, 0, 175),
72
+ (0, 0, 215),
73
+ (0, 0, 255),
74
+ (0, 95, 0),
75
+ (0, 95, 95),
76
+ (0, 95, 135),
77
+ (0, 95, 175),
78
+ (0, 95, 215),
79
+ (0, 95, 255),
80
+ (0, 135, 0),
81
+ (0, 135, 95),
82
+ (0, 135, 135),
83
+ (0, 135, 175),
84
+ (0, 135, 215),
85
+ (0, 135, 255),
86
+ (0, 175, 0),
87
+ (0, 175, 95),
88
+ (0, 175, 135),
89
+ (0, 175, 175),
90
+ (0, 175, 215),
91
+ (0, 175, 255),
92
+ (0, 215, 0),
93
+ (0, 215, 95),
94
+ (0, 215, 135),
95
+ (0, 215, 175),
96
+ (0, 215, 215),
97
+ (0, 215, 255),
98
+ (0, 255, 0),
99
+ (0, 255, 95),
100
+ (0, 255, 135),
101
+ (0, 255, 175),
102
+ (0, 255, 215),
103
+ (0, 255, 255),
104
+ (95, 0, 0),
105
+ (95, 0, 95),
106
+ (95, 0, 135),
107
+ (95, 0, 175),
108
+ (95, 0, 215),
109
+ (95, 0, 255),
110
+ (95, 95, 0),
111
+ (95, 95, 95),
112
+ (95, 95, 135),
113
+ (95, 95, 175),
114
+ (95, 95, 215),
115
+ (95, 95, 255),
116
+ (95, 135, 0),
117
+ (95, 135, 95),
118
+ (95, 135, 135),
119
+ (95, 135, 175),
120
+ (95, 135, 215),
121
+ (95, 135, 255),
122
+ (95, 175, 0),
123
+ (95, 175, 95),
124
+ (95, 175, 135),
125
+ (95, 175, 175),
126
+ (95, 175, 215),
127
+ (95, 175, 255),
128
+ (95, 215, 0),
129
+ (95, 215, 95),
130
+ (95, 215, 135),
131
+ (95, 215, 175),
132
+ (95, 215, 215),
133
+ (95, 215, 255),
134
+ (95, 255, 0),
135
+ (95, 255, 95),
136
+ (95, 255, 135),
137
+ (95, 255, 175),
138
+ (95, 255, 215),
139
+ (95, 255, 255),
140
+ (135, 0, 0),
141
+ (135, 0, 95),
142
+ (135, 0, 135),
143
+ (135, 0, 175),
144
+ (135, 0, 215),
145
+ (135, 0, 255),
146
+ (135, 95, 0),
147
+ (135, 95, 95),
148
+ (135, 95, 135),
149
+ (135, 95, 175),
150
+ (135, 95, 215),
151
+ (135, 95, 255),
152
+ (135, 135, 0),
153
+ (135, 135, 95),
154
+ (135, 135, 135),
155
+ (135, 135, 175),
156
+ (135, 135, 215),
157
+ (135, 135, 255),
158
+ (135, 175, 0),
159
+ (135, 175, 95),
160
+ (135, 175, 135),
161
+ (135, 175, 175),
162
+ (135, 175, 215),
163
+ (135, 175, 255),
164
+ (135, 215, 0),
165
+ (135, 215, 95),
166
+ (135, 215, 135),
167
+ (135, 215, 175),
168
+ (135, 215, 215),
169
+ (135, 215, 255),
170
+ (135, 255, 0),
171
+ (135, 255, 95),
172
+ (135, 255, 135),
173
+ (135, 255, 175),
174
+ (135, 255, 215),
175
+ (135, 255, 255),
176
+ (175, 0, 0),
177
+ (175, 0, 95),
178
+ (175, 0, 135),
179
+ (175, 0, 175),
180
+ (175, 0, 215),
181
+ (175, 0, 255),
182
+ (175, 95, 0),
183
+ (175, 95, 95),
184
+ (175, 95, 135),
185
+ (175, 95, 175),
186
+ (175, 95, 215),
187
+ (175, 95, 255),
188
+ (175, 135, 0),
189
+ (175, 135, 95),
190
+ (175, 135, 135),
191
+ (175, 135, 175),
192
+ (175, 135, 215),
193
+ (175, 135, 255),
194
+ (175, 175, 0),
195
+ (175, 175, 95),
196
+ (175, 175, 135),
197
+ (175, 175, 175),
198
+ (175, 175, 215),
199
+ (175, 175, 255),
200
+ (175, 215, 0),
201
+ (175, 215, 95),
202
+ (175, 215, 135),
203
+ (175, 215, 175),
204
+ (175, 215, 215),
205
+ (175, 215, 255),
206
+ (175, 255, 0),
207
+ (175, 255, 95),
208
+ (175, 255, 135),
209
+ (175, 255, 175),
210
+ (175, 255, 215),
211
+ (175, 255, 255),
212
+ (215, 0, 0),
213
+ (215, 0, 95),
214
+ (215, 0, 135),
215
+ (215, 0, 175),
216
+ (215, 0, 215),
217
+ (215, 0, 255),
218
+ (215, 95, 0),
219
+ (215, 95, 95),
220
+ (215, 95, 135),
221
+ (215, 95, 175),
222
+ (215, 95, 215),
223
+ (215, 95, 255),
224
+ (215, 135, 0),
225
+ (215, 135, 95),
226
+ (215, 135, 135),
227
+ (215, 135, 175),
228
+ (215, 135, 215),
229
+ (215, 135, 255),
230
+ (215, 175, 0),
231
+ (215, 175, 95),
232
+ (215, 175, 135),
233
+ (215, 175, 175),
234
+ (215, 175, 215),
235
+ (215, 175, 255),
236
+ (215, 215, 0),
237
+ (215, 215, 95),
238
+ (215, 215, 135),
239
+ (215, 215, 175),
240
+ (215, 215, 215),
241
+ (215, 215, 255),
242
+ (215, 255, 0),
243
+ (215, 255, 95),
244
+ (215, 255, 135),
245
+ (215, 255, 175),
246
+ (215, 255, 215),
247
+ (215, 255, 255),
248
+ (255, 0, 0),
249
+ (255, 0, 95),
250
+ (255, 0, 135),
251
+ (255, 0, 175),
252
+ (255, 0, 215),
253
+ (255, 0, 255),
254
+ (255, 95, 0),
255
+ (255, 95, 95),
256
+ (255, 95, 135),
257
+ (255, 95, 175),
258
+ (255, 95, 215),
259
+ (255, 95, 255),
260
+ (255, 135, 0),
261
+ (255, 135, 95),
262
+ (255, 135, 135),
263
+ (255, 135, 175),
264
+ (255, 135, 215),
265
+ (255, 135, 255),
266
+ (255, 175, 0),
267
+ (255, 175, 95),
268
+ (255, 175, 135),
269
+ (255, 175, 175),
270
+ (255, 175, 215),
271
+ (255, 175, 255),
272
+ (255, 215, 0),
273
+ (255, 215, 95),
274
+ (255, 215, 135),
275
+ (255, 215, 175),
276
+ (255, 215, 215),
277
+ (255, 215, 255),
278
+ (255, 255, 0),
279
+ (255, 255, 95),
280
+ (255, 255, 135),
281
+ (255, 255, 175),
282
+ (255, 255, 215),
283
+ (255, 255, 255),
284
+ (8, 8, 8),
285
+ (18, 18, 18),
286
+ (28, 28, 28),
287
+ (38, 38, 38),
288
+ (48, 48, 48),
289
+ (58, 58, 58),
290
+ (68, 68, 68),
291
+ (78, 78, 78),
292
+ (88, 88, 88),
293
+ (98, 98, 98),
294
+ (108, 108, 108),
295
+ (118, 118, 118),
296
+ (128, 128, 128),
297
+ (138, 138, 138),
298
+ (148, 148, 148),
299
+ (158, 158, 158),
300
+ (168, 168, 168),
301
+ (178, 178, 178),
302
+ (188, 188, 188),
303
+ (198, 198, 198),
304
+ (208, 208, 208),
305
+ (218, 218, 218),
306
+ (228, 228, 228),
307
+ (238, 238, 238),
308
+ ]
309
+ )
.venv/Lib/site-packages/pip/_vendor/rich/_pick.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional
2
+
3
+
4
+ def pick_bool(*values: Optional[bool]) -> bool:
5
+ """Pick the first non-none bool or return the last value.
6
+
7
+ Args:
8
+ *values (bool): Any number of boolean or None values.
9
+
10
+ Returns:
11
+ bool: First non-none boolean.
12
+ """
13
+ assert values, "1 or more values required"
14
+ for value in values:
15
+ if value is not None:
16
+ return value
17
+ return bool(value)
.venv/Lib/site-packages/pip/_vendor/rich/_ratio.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from fractions import Fraction
3
+ from math import ceil
4
+ from typing import cast, List, Optional, Sequence
5
+
6
+ if sys.version_info >= (3, 8):
7
+ from typing import Protocol
8
+ else:
9
+ from pip._vendor.typing_extensions import Protocol # pragma: no cover
10
+
11
+
12
+ class Edge(Protocol):
13
+ """Any object that defines an edge (such as Layout)."""
14
+
15
+ size: Optional[int] = None
16
+ ratio: int = 1
17
+ minimum_size: int = 1
18
+
19
+
20
+ def ratio_resolve(total: int, edges: Sequence[Edge]) -> List[int]:
21
+ """Divide total space to satisfy size, ratio, and minimum_size, constraints.
22
+
23
+ The returned list of integers should add up to total in most cases, unless it is
24
+ impossible to satisfy all the constraints. For instance, if there are two edges
25
+ with a minimum size of 20 each and `total` is 30 then the returned list will be
26
+ greater than total. In practice, this would mean that a Layout object would
27
+ clip the rows that would overflow the screen height.
28
+
29
+ Args:
30
+ total (int): Total number of characters.
31
+ edges (List[Edge]): Edges within total space.
32
+
33
+ Returns:
34
+ List[int]: Number of characters for each edge.
35
+ """
36
+ # Size of edge or None for yet to be determined
37
+ sizes = [(edge.size or None) for edge in edges]
38
+
39
+ _Fraction = Fraction
40
+
41
+ # While any edges haven't been calculated
42
+ while None in sizes:
43
+ # Get flexible edges and index to map these back on to sizes list
44
+ flexible_edges = [
45
+ (index, edge)
46
+ for index, (size, edge) in enumerate(zip(sizes, edges))
47
+ if size is None
48
+ ]
49
+ # Remaining space in total
50
+ remaining = total - sum(size or 0 for size in sizes)
51
+ if remaining <= 0:
52
+ # No room for flexible edges
53
+ return [
54
+ ((edge.minimum_size or 1) if size is None else size)
55
+ for size, edge in zip(sizes, edges)
56
+ ]
57
+ # Calculate number of characters in a ratio portion
58
+ portion = _Fraction(
59
+ remaining, sum((edge.ratio or 1) for _, edge in flexible_edges)
60
+ )
61
+
62
+ # If any edges will be less than their minimum, replace size with the minimum
63
+ for index, edge in flexible_edges:
64
+ if portion * edge.ratio <= edge.minimum_size:
65
+ sizes[index] = edge.minimum_size
66
+ # New fixed size will invalidate calculations, so we need to repeat the process
67
+ break
68
+ else:
69
+ # Distribute flexible space and compensate for rounding error
70
+ # Since edge sizes can only be integers we need to add the remainder
71
+ # to the following line
72
+ remainder = _Fraction(0)
73
+ for index, edge in flexible_edges:
74
+ size, remainder = divmod(portion * edge.ratio + remainder, 1)
75
+ sizes[index] = size
76
+ break
77
+ # Sizes now contains integers only
78
+ return cast(List[int], sizes)
79
+
80
+
81
+ def ratio_reduce(
82
+ total: int, ratios: List[int], maximums: List[int], values: List[int]
83
+ ) -> List[int]:
84
+ """Divide an integer total in to parts based on ratios.
85
+
86
+ Args:
87
+ total (int): The total to divide.
88
+ ratios (List[int]): A list of integer ratios.
89
+ maximums (List[int]): List of maximums values for each slot.
90
+ values (List[int]): List of values
91
+
92
+ Returns:
93
+ List[int]: A list of integers guaranteed to sum to total.
94
+ """
95
+ ratios = [ratio if _max else 0 for ratio, _max in zip(ratios, maximums)]
96
+ total_ratio = sum(ratios)
97
+ if not total_ratio:
98
+ return values[:]
99
+ total_remaining = total
100
+ result: List[int] = []
101
+ append = result.append
102
+ for ratio, maximum, value in zip(ratios, maximums, values):
103
+ if ratio and total_ratio > 0:
104
+ distributed = min(maximum, round(ratio * total_remaining / total_ratio))
105
+ append(value - distributed)
106
+ total_remaining -= distributed
107
+ total_ratio -= ratio
108
+ else:
109
+ append(value)
110
+ return result
111
+
112
+
113
+ def ratio_distribute(
114
+ total: int, ratios: List[int], minimums: Optional[List[int]] = None
115
+ ) -> List[int]:
116
+ """Distribute an integer total in to parts based on ratios.
117
+
118
+ Args:
119
+ total (int): The total to divide.
120
+ ratios (List[int]): A list of integer ratios.
121
+ minimums (List[int]): List of minimum values for each slot.
122
+
123
+ Returns:
124
+ List[int]: A list of integers guaranteed to sum to total.
125
+ """
126
+ if minimums:
127
+ ratios = [ratio if _min else 0 for ratio, _min in zip(ratios, minimums)]
128
+ total_ratio = sum(ratios)
129
+ assert total_ratio > 0, "Sum of ratios must be > 0"
130
+
131
+ total_remaining = total
132
+ distributed_total: List[int] = []
133
+ append = distributed_total.append
134
+ if minimums is None:
135
+ _minimums = [0] * len(ratios)
136
+ else:
137
+ _minimums = minimums
138
+ for ratio, minimum in zip(ratios, _minimums):
139
+ if total_ratio > 0:
140
+ distributed = max(minimum, ceil(ratio * total_remaining / total_ratio))
141
+ else:
142
+ distributed = total_remaining
143
+ append(distributed)
144
+ total_ratio -= ratio
145
+ total_remaining -= distributed
146
+ return distributed_total
147
+
148
+
149
+ if __name__ == "__main__":
150
+ from dataclasses import dataclass
151
+
152
+ @dataclass
153
+ class E:
154
+
155
+ size: Optional[int] = None
156
+ ratio: int = 1
157
+ minimum_size: int = 1
158
+
159
+ resolved = ratio_resolve(110, [E(None, 1, 1), E(None, 1, 1), E(None, 1, 1)])
160
+ print(sum(resolved))
.venv/Lib/site-packages/pip/_vendor/rich/_spinners.py ADDED
@@ -0,0 +1,482 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Spinners are from:
3
+ * cli-spinners:
4
+ MIT License
5
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
20
+ """
21
+
22
+ SPINNERS = {
23
+ "dots": {
24
+ "interval": 80,
25
+ "frames": "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏",
26
+ },
27
+ "dots2": {"interval": 80, "frames": "⣾⣽⣻⢿⡿⣟⣯⣷"},
28
+ "dots3": {
29
+ "interval": 80,
30
+ "frames": "⠋⠙⠚⠞⠖⠦⠴⠲⠳⠓",
31
+ },
32
+ "dots4": {
33
+ "interval": 80,
34
+ "frames": "⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆",
35
+ },
36
+ "dots5": {
37
+ "interval": 80,
38
+ "frames": "⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋",
39
+ },
40
+ "dots6": {
41
+ "interval": 80,
42
+ "frames": "⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁",
43
+ },
44
+ "dots7": {
45
+ "interval": 80,
46
+ "frames": "⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈",
47
+ },
48
+ "dots8": {
49
+ "interval": 80,
50
+ "frames": "⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈",
51
+ },
52
+ "dots9": {"interval": 80, "frames": "⢹⢺⢼⣸⣇⡧⡗⡏"},
53
+ "dots10": {"interval": 80, "frames": "⢄⢂⢁⡁⡈⡐⡠"},
54
+ "dots11": {"interval": 100, "frames": "⠁⠂⠄⡀⢀⠠⠐⠈"},
55
+ "dots12": {
56
+ "interval": 80,
57
+ "frames": [
58
+ "⢀⠀",
59
+ "⡀⠀",
60
+ "⠄⠀",
61
+ "⢂⠀",
62
+ "⡂⠀",
63
+ "⠅⠀",
64
+ "⢃⠀",
65
+ "⡃⠀",
66
+ "⠍⠀",
67
+ "⢋⠀",
68
+ "⡋⠀",
69
+ "⠍⠁",
70
+ "⢋⠁",
71
+ "⡋⠁",
72
+ "⠍⠉",
73
+ "⠋⠉",
74
+ "⠋⠉",
75
+ "⠉⠙",
76
+ "⠉⠙",
77
+ "⠉⠩",
78
+ "⠈⢙",
79
+ "⠈⡙",
80
+ "⢈⠩",
81
+ "⡀⢙",
82
+ "⠄⡙",
83
+ "⢂⠩",
84
+ "⡂⢘",
85
+ "⠅⡘",
86
+ "⢃⠨",
87
+ "⡃⢐",
88
+ "⠍⡐",
89
+ "⢋⠠",
90
+ "⡋⢀",
91
+ "⠍⡁",
92
+ "⢋⠁",
93
+ "⡋⠁",
94
+ "⠍⠉",
95
+ "⠋⠉",
96
+ "⠋⠉",
97
+ "⠉⠙",
98
+ "⠉⠙",
99
+ "⠉⠩",
100
+ "⠈⢙",
101
+ "⠈⡙",
102
+ "⠈⠩",
103
+ "⠀⢙",
104
+ "⠀⡙",
105
+ "⠀⠩",
106
+ "⠀⢘",
107
+ "⠀⡘",
108
+ "⠀⠨",
109
+ "⠀⢐",
110
+ "⠀⡐",
111
+ "⠀⠠",
112
+ "⠀⢀",
113
+ "⠀⡀",
114
+ ],
115
+ },
116
+ "dots8Bit": {
117
+ "interval": 80,
118
+ "frames": "⠀⠁⠂⠃⠄⠅⠆⠇⡀⡁⡂⡃⡄⡅⡆⡇⠈⠉⠊⠋⠌⠍⠎⠏⡈⡉⡊⡋⡌⡍⡎⡏⠐⠑⠒⠓⠔⠕⠖⠗⡐⡑⡒⡓⡔⡕⡖⡗⠘⠙⠚⠛⠜⠝⠞⠟⡘⡙"
119
+ "⡚⡛⡜⡝⡞⡟⠠⠡⠢⠣⠤⠥⠦⠧⡠⡡⡢⡣⡤⡥⡦⡧⠨⠩⠪⠫⠬⠭⠮⠯⡨⡩⡪⡫⡬⡭⡮⡯⠰⠱⠲⠳⠴⠵⠶⠷⡰⡱⡲⡳⡴⡵⡶⡷⠸⠹⠺⠻"
120
+ "⠼⠽⠾⠿⡸⡹⡺⡻⡼⡽⡾⡿⢀⢁⢂⢃⢄⢅⢆⢇⣀⣁⣂⣃⣄⣅⣆⣇⢈⢉⢊⢋⢌⢍⢎⢏⣈⣉⣊⣋⣌⣍⣎⣏⢐⢑⢒⢓⢔⢕⢖⢗⣐⣑⣒⣓⣔⣕"
121
+ "⣖⣗⢘⢙⢚⢛⢜⢝⢞⢟⣘⣙⣚⣛⣜⣝⣞⣟⢠⢡⢢⢣⢤⢥⢦⢧⣠⣡⣢⣣⣤⣥⣦⣧⢨⢩⢪⢫⢬⢭⢮⢯⣨⣩⣪⣫⣬⣭⣮⣯⢰⢱⢲⢳⢴⢵⢶⢷"
122
+ "⣰⣱⣲⣳⣴⣵⣶⣷⢸⢹⢺⢻⢼⢽⢾⢿⣸⣹⣺⣻⣼⣽⣾⣿",
123
+ },
124
+ "line": {"interval": 130, "frames": ["-", "\\", "|", "/"]},
125
+ "line2": {"interval": 100, "frames": "⠂-–—–-"},
126
+ "pipe": {"interval": 100, "frames": "┤┘┴└├┌┬┐"},
127
+ "simpleDots": {"interval": 400, "frames": [". ", ".. ", "...", " "]},
128
+ "simpleDotsScrolling": {
129
+ "interval": 200,
130
+ "frames": [". ", ".. ", "...", " ..", " .", " "],
131
+ },
132
+ "star": {"interval": 70, "frames": "✶✸✹✺✹✷"},
133
+ "star2": {"interval": 80, "frames": "+x*"},
134
+ "flip": {
135
+ "interval": 70,
136
+ "frames": "___-``'´-___",
137
+ },
138
+ "hamburger": {"interval": 100, "frames": "☱☲☴"},
139
+ "growVertical": {
140
+ "interval": 120,
141
+ "frames": "▁▃▄▅▆▇▆▅▄▃",
142
+ },
143
+ "growHorizontal": {
144
+ "interval": 120,
145
+ "frames": "▏▎▍▌▋▊▉▊▋▌▍▎",
146
+ },
147
+ "balloon": {"interval": 140, "frames": " .oO@* "},
148
+ "balloon2": {"interval": 120, "frames": ".oO°Oo."},
149
+ "noise": {"interval": 100, "frames": "▓▒░"},
150
+ "bounce": {"interval": 120, "frames": "⠁⠂⠄⠂"},
151
+ "boxBounce": {"interval": 120, "frames": "▖▘▝▗"},
152
+ "boxBounce2": {"interval": 100, "frames": "▌▀▐▄"},
153
+ "triangle": {"interval": 50, "frames": "◢◣◤◥"},
154
+ "arc": {"interval": 100, "frames": "◜◠◝◞◡◟"},
155
+ "circle": {"interval": 120, "frames": "◡⊙◠"},
156
+ "squareCorners": {"interval": 180, "frames": "◰◳◲◱"},
157
+ "circleQuarters": {"interval": 120, "frames": "◴◷◶◵"},
158
+ "circleHalves": {"interval": 50, "frames": "◐◓◑◒"},
159
+ "squish": {"interval": 100, "frames": "╫╪"},
160
+ "toggle": {"interval": 250, "frames": "⊶⊷"},
161
+ "toggle2": {"interval": 80, "frames": "▫▪"},
162
+ "toggle3": {"interval": 120, "frames": "□■"},
163
+ "toggle4": {"interval": 100, "frames": "■□▪▫"},
164
+ "toggle5": {"interval": 100, "frames": "▮▯"},
165
+ "toggle6": {"interval": 300, "frames": "ဝ၀"},
166
+ "toggle7": {"interval": 80, "frames": "⦾⦿"},
167
+ "toggle8": {"interval": 100, "frames": "◍◌"},
168
+ "toggle9": {"interval": 100, "frames": "◉◎"},
169
+ "toggle10": {"interval": 100, "frames": "㊂㊀㊁"},
170
+ "toggle11": {"interval": 50, "frames": "⧇⧆"},
171
+ "toggle12": {"interval": 120, "frames": "☗☖"},
172
+ "toggle13": {"interval": 80, "frames": "=*-"},
173
+ "arrow": {"interval": 100, "frames": "←↖↑↗→↘↓↙"},
174
+ "arrow2": {
175
+ "interval": 80,
176
+ "frames": ["⬆️ ", "↗️ ", "➡️ ", "↘️ ", "⬇️ ", "↙️ ", "⬅️ ", "↖️ "],
177
+ },
178
+ "arrow3": {
179
+ "interval": 120,
180
+ "frames": ["▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"],
181
+ },
182
+ "bouncingBar": {
183
+ "interval": 80,
184
+ "frames": [
185
+ "[ ]",
186
+ "[= ]",
187
+ "[== ]",
188
+ "[=== ]",
189
+ "[ ===]",
190
+ "[ ==]",
191
+ "[ =]",
192
+ "[ ]",
193
+ "[ =]",
194
+ "[ ==]",
195
+ "[ ===]",
196
+ "[====]",
197
+ "[=== ]",
198
+ "[== ]",
199
+ "[= ]",
200
+ ],
201
+ },
202
+ "bouncingBall": {
203
+ "interval": 80,
204
+ "frames": [
205
+ "( ● )",
206
+ "( ● )",
207
+ "( ● )",
208
+ "( ● )",
209
+ "( ●)",
210
+ "( ● )",
211
+ "( ● )",
212
+ "( ● )",
213
+ "( ● )",
214
+ "(● )",
215
+ ],
216
+ },
217
+ "smiley": {"interval": 200, "frames": ["😄 ", "😝 "]},
218
+ "monkey": {"interval": 300, "frames": ["🙈 ", "🙈 ", "🙉 ", "🙊 "]},
219
+ "hearts": {"interval": 100, "frames": ["💛 ", "💙 ", "💜 ", "💚 ", "❤️ "]},
220
+ "clock": {
221
+ "interval": 100,
222
+ "frames": [
223
+ "🕛 ",
224
+ "🕐 ",
225
+ "🕑 ",
226
+ "🕒 ",
227
+ "🕓 ",
228
+ "🕔 ",
229
+ "🕕 ",
230
+ "🕖 ",
231
+ "🕗 ",
232
+ "🕘 ",
233
+ "🕙 ",
234
+ "🕚 ",
235
+ ],
236
+ },
237
+ "earth": {"interval": 180, "frames": ["🌍 ", "🌎 ", "🌏 "]},
238
+ "material": {
239
+ "interval": 17,
240
+ "frames": [
241
+ "█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
242
+ "██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
243
+ "███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
244
+ "████▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
245
+ "██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
246
+ "██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
247
+ "███████▁▁▁▁▁▁▁▁▁▁▁▁▁",
248
+ "████████▁▁▁▁▁▁▁▁▁▁▁▁",
249
+ "█████████▁▁▁▁▁▁▁▁▁▁▁",
250
+ "█████████▁▁▁▁▁▁▁▁▁▁▁",
251
+ "██████████▁▁▁▁▁▁▁▁▁▁",
252
+ "███████████▁▁▁▁▁▁▁▁▁",
253
+ "█████████████▁▁▁▁▁▁▁",
254
+ "██████████████▁▁▁▁▁▁",
255
+ "██████████████▁▁▁▁▁▁",
256
+ "▁██████████████▁▁▁▁▁",
257
+ "▁██████████████▁▁▁▁▁",
258
+ "▁██████████████▁▁▁▁▁",
259
+ "▁▁██████████████▁▁▁▁",
260
+ "▁▁▁██████████████▁▁▁",
261
+ "▁▁▁▁█████████████▁▁▁",
262
+ "▁▁▁▁██████████████▁▁",
263
+ "▁▁▁▁██████████████▁▁",
264
+ "▁▁▁▁▁██████████████▁",
265
+ "▁▁▁▁▁██████████████▁",
266
+ "▁▁▁▁▁██████████████▁",
267
+ "▁▁▁▁▁▁██████████████",
268
+ "▁▁▁▁▁▁██████████████",
269
+ "▁▁▁▁▁▁▁█████████████",
270
+ "▁▁▁▁▁▁▁█████████████",
271
+ "▁▁▁▁▁▁▁▁████████████",
272
+ "▁▁▁▁▁▁▁▁████████████",
273
+ "▁▁▁▁▁▁▁▁▁███████████",
274
+ "▁▁▁▁▁▁▁▁▁███████████",
275
+ "▁▁▁▁▁▁▁▁▁▁██████████",
276
+ "▁▁▁▁▁▁▁▁▁▁██████████",
277
+ "▁▁▁▁▁▁▁▁▁▁▁▁████████",
278
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
279
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁██████",
280
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
281
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
282
+ "█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
283
+ "██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
284
+ "██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
285
+ "███▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
286
+ "████▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
287
+ "█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
288
+ "█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
289
+ "██████▁▁▁▁▁▁▁▁▁▁▁▁▁█",
290
+ "████████▁▁▁▁▁▁▁▁▁▁▁▁",
291
+ "█████████▁▁▁▁▁▁▁▁▁▁▁",
292
+ "█████████▁▁▁▁▁▁▁▁▁▁▁",
293
+ "█████████▁▁▁▁▁▁▁▁▁▁▁",
294
+ "█████████▁▁▁▁▁▁▁▁▁▁▁",
295
+ "███████████▁▁▁▁▁▁▁▁▁",
296
+ "████████████▁▁▁▁▁▁▁▁",
297
+ "████████████▁▁▁▁▁▁▁▁",
298
+ "██████████████▁▁▁▁▁▁",
299
+ "██████████████▁▁▁▁▁▁",
300
+ "▁██████████████▁▁▁▁▁",
301
+ "▁██████████████▁▁▁▁▁",
302
+ "▁▁▁█████████████▁▁▁▁",
303
+ "▁▁▁▁▁████████████▁▁▁",
304
+ "▁▁▁▁▁████████████▁▁▁",
305
+ "▁▁▁▁▁▁███████████▁▁▁",
306
+ "▁▁▁▁▁▁▁▁█████████▁▁▁",
307
+ "▁▁▁▁▁▁▁▁█████████▁▁▁",
308
+ "▁▁▁▁▁▁▁▁▁█████████▁▁",
309
+ "▁▁▁▁▁▁▁▁▁█████████▁▁",
310
+ "▁▁▁▁▁▁▁▁▁▁█████████▁",
311
+ "▁▁▁▁▁▁▁▁▁▁▁████████▁",
312
+ "▁▁▁▁▁▁▁▁▁▁▁████████▁",
313
+ "▁▁▁▁▁▁▁▁▁▁▁▁███████▁",
314
+ "▁▁▁▁▁▁▁▁▁▁▁▁███████▁",
315
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
316
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
317
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
318
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
319
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
320
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
321
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
322
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
323
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
324
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
325
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
326
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
327
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
328
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
329
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
330
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
331
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
332
+ "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
333
+ ],
334
+ },
335
+ "moon": {
336
+ "interval": 80,
337
+ "frames": ["🌑 ", "🌒 ", "🌓 ", "🌔 ", "🌕 ", "🌖 ", "🌗 ", "🌘 "],
338
+ },
339
+ "runner": {"interval": 140, "frames": ["🚶 ", "🏃 "]},
340
+ "pong": {
341
+ "interval": 80,
342
+ "frames": [
343
+ "▐⠂ ▌",
344
+ "▐⠈ ▌",
345
+ "▐ ⠂ ▌",
346
+ "▐ ⠠ ▌",
347
+ "▐ ⡀ ▌",
348
+ "▐ ⠠ ▌",
349
+ "▐ ⠂ ▌",
350
+ "▐ ⠈ ▌",
351
+ "▐ ⠂ ▌",
352
+ "▐ ⠠ ▌",
353
+ "▐ ⡀ ▌",
354
+ "▐ ⠠ ▌",
355
+ "▐ ⠂ ▌",
356
+ "▐ ⠈ ▌",
357
+ "▐ ⠂▌",
358
+ "▐ ⠠▌",
359
+ "▐ ⡀▌",
360
+ "▐ ⠠ ▌",
361
+ "▐ ⠂ ▌",
362
+ "▐ ⠈ ▌",
363
+ "▐ ⠂ ▌",
364
+ "▐ ⠠ ▌",
365
+ "▐ ⡀ ▌",
366
+ "▐ ⠠ ▌",
367
+ "▐ ⠂ ▌",
368
+ "▐ ⠈ ▌",
369
+ "▐ ⠂ ▌",
370
+ "▐ ⠠ ▌",
371
+ "▐ ⡀ ▌",
372
+ "▐⠠ ▌",
373
+ ],
374
+ },
375
+ "shark": {
376
+ "interval": 120,
377
+ "frames": [
378
+ "▐|\\____________▌",
379
+ "▐_|\\___________▌",
380
+ "▐__|\\__________▌",
381
+ "▐___|\\_________▌",
382
+ "▐____|\\________▌",
383
+ "▐_____|\\_______▌",
384
+ "▐______|\\______▌",
385
+ "▐_______|\\_____▌",
386
+ "▐________|\\____▌",
387
+ "▐_________|\\___▌",
388
+ "▐__________|\\__▌",
389
+ "▐___________|\\_▌",
390
+ "▐____________|\\▌",
391
+ "▐____________/|▌",
392
+ "▐___________/|_▌",
393
+ "▐__________/|__▌",
394
+ "▐_________/|___▌",
395
+ "▐________/|____▌",
396
+ "▐_______/|_____▌",
397
+ "▐______/|______▌",
398
+ "▐_____/|_______▌",
399
+ "▐____/|________▌",
400
+ "▐___/|_________▌",
401
+ "▐__/|__________▌",
402
+ "▐_/|___________▌",
403
+ "▐/|____________▌",
404
+ ],
405
+ },
406
+ "dqpb": {"interval": 100, "frames": "dqpb"},
407
+ "weather": {
408
+ "interval": 100,
409
+ "frames": [
410
+ "☀️ ",
411
+ "☀️ ",
412
+ "☀️ ",
413
+ "🌤 ",
414
+ "⛅️ ",
415
+ "🌥 ",
416
+ "☁️ ",
417
+ "🌧 ",
418
+ "🌨 ",
419
+ "🌧 ",
420
+ "🌨 ",
421
+ "🌧 ",
422
+ "🌨 ",
423
+ "⛈ ",
424
+ "🌨 ",
425
+ "🌧 ",
426
+ "🌨 ",
427
+ "☁️ ",
428
+ "🌥 ",
429
+ "⛅️ ",
430
+ "🌤 ",
431
+ "☀️ ",
432
+ "☀️ ",
433
+ ],
434
+ },
435
+ "christmas": {"interval": 400, "frames": "🌲🎄"},
436
+ "grenade": {
437
+ "interval": 80,
438
+ "frames": [
439
+ "، ",
440
+ "′ ",
441
+ " ´ ",
442
+ " ‾ ",
443
+ " ⸌",
444
+ " ⸊",
445
+ " |",
446
+ " ⁎",
447
+ " ⁕",
448
+ " ෴ ",
449
+ " ⁓",
450
+ " ",
451
+ " ",
452
+ " ",
453
+ ],
454
+ },
455
+ "point": {"interval": 125, "frames": ["∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"]},
456
+ "layer": {"interval": 150, "frames": "-=≡"},
457
+ "betaWave": {
458
+ "interval": 80,
459
+ "frames": [
460
+ "ρββββββ",
461
+ "βρβββββ",
462
+ "ββρββββ",
463
+ "βββρβββ",
464
+ "ββββρββ",
465
+ "βββββρβ",
466
+ "ββββββρ",
467
+ ],
468
+ },
469
+ "aesthetic": {
470
+ "interval": 80,
471
+ "frames": [
472
+ "▰▱▱▱▱▱▱",
473
+ "▰▰▱▱▱▱▱",
474
+ "▰▰▰▱▱▱▱",
475
+ "▰▰▰▰▱▱▱",
476
+ "▰▰▰▰▰▱▱",
477
+ "▰▰▰▰▰▰▱",
478
+ "▰▰▰▰▰▰▰",
479
+ "▰▱▱▱▱▱▱",
480
+ ],
481
+ },
482
+ }
.venv/Lib/site-packages/pip/_vendor/rich/_stack.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List, TypeVar
2
+
3
+ T = TypeVar("T")
4
+
5
+
6
+ class Stack(List[T]):
7
+ """A small shim over builtin list."""
8
+
9
+ @property
10
+ def top(self) -> T:
11
+ """Get top of stack."""
12
+ return self[-1]
13
+
14
+ def push(self, item: T) -> None:
15
+ """Push an item on to the stack (append in stack nomenclature)."""
16
+ self.append(item)
.venv/Lib/site-packages/pip/_vendor/rich/abc.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import ABC
2
+
3
+
4
+ class RichRenderable(ABC):
5
+ """An abstract base class for Rich renderables.
6
+
7
+ Note that there is no need to extend this class, the intended use is to check if an
8
+ object supports the Rich renderable protocol. For example::
9
+
10
+ if isinstance(my_object, RichRenderable):
11
+ console.print(my_object)
12
+
13
+ """
14
+
15
+ @classmethod
16
+ def __subclasshook__(cls, other: type) -> bool:
17
+ """Check if this class supports the rich render protocol."""
18
+ return hasattr(other, "__rich_console__") or hasattr(other, "__rich__")
19
+
20
+
21
+ if __name__ == "__main__": # pragma: no cover
22
+ from pip._vendor.rich.text import Text
23
+
24
+ t = Text()
25
+ print(isinstance(Text, RichRenderable))
26
+ print(isinstance(t, RichRenderable))
27
+
28
+ class Foo:
29
+ pass
30
+
31
+ f = Foo()
32
+ print(isinstance(f, RichRenderable))
33
+ print(isinstance("", RichRenderable))
.venv/Lib/site-packages/pip/_vendor/rich/align.py ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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[VerticalAlginMethod], 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
+ """
244
+
245
+ def __init__(
246
+ self,
247
+ renderable: "RenderableType",
248
+ style: Optional[StyleType] = None,
249
+ ) -> None:
250
+ self.renderable = renderable
251
+ self.style = style
252
+
253
+ def __repr__(self) -> str:
254
+ return f"VerticalCenter({self.renderable!r})"
255
+
256
+ def __rich_console__(
257
+ self, console: "Console", options: "ConsoleOptions"
258
+ ) -> "RenderResult":
259
+ style = console.get_style(self.style) if self.style is not None else None
260
+ lines = console.render_lines(
261
+ self.renderable, options.update(height=None), pad=False
262
+ )
263
+ width, _height = Segment.get_shape(lines)
264
+ new_line = Segment.line()
265
+ height = options.height or options.size.height
266
+ top_space = (height - len(lines)) // 2
267
+ bottom_space = height - top_space - len(lines)
268
+ blank_line = Segment(f"{' ' * width}", style)
269
+
270
+ def blank_lines(count: int) -> Iterable[Segment]:
271
+ for _ in range(count):
272
+ yield blank_line
273
+ yield new_line
274
+
275
+ if top_space > 0:
276
+ yield from blank_lines(top_space)
277
+ for line in lines:
278
+ yield from line
279
+ yield new_line
280
+ if bottom_space > 0:
281
+ yield from blank_lines(bottom_space)
282
+
283
+ def __rich_measure__(
284
+ self, console: "Console", options: "ConsoleOptions"
285
+ ) -> Measurement:
286
+ measurement = Measurement.get(console, options, self.renderable)
287
+ return measurement
288
+
289
+
290
+ if __name__ == "__main__": # pragma: no cover
291
+ from pip._vendor.rich.console import Console, Group
292
+ from pip._vendor.rich.highlighter import ReprHighlighter
293
+ from pip._vendor.rich.panel import Panel
294
+
295
+ highlighter = ReprHighlighter()
296
+ console = Console()
297
+
298
+ panel = Panel(
299
+ Group(
300
+ Align.left(highlighter("align='left'")),
301
+ Align.center(highlighter("align='center'")),
302
+ Align.right(highlighter("align='right'")),
303
+ ),
304
+ width=60,
305
+ style="on dark_blue",
306
+ title="Align",
307
+ )
308
+
309
+ console.print(
310
+ Align.center(panel, vertical="middle", style="on red", height=console.height)
311
+ )
.venv/Lib/site-packages/pip/_vendor/rich/ansi.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import sys
3
+ from contextlib import suppress
4
+ from typing import Iterable, NamedTuple, Optional
5
+
6
+ from .color import Color
7
+ from .style import Style
8
+ from .text import Text
9
+
10
+ re_ansi = re.compile(
11
+ r"""
12
+ (?:\x1b\](.*?)\x1b\\)|
13
+ (?:\x1b([(@-Z\\-_]|\[[0-?]*[ -/]*[@-~]))
14
+ """,
15
+ re.VERBOSE,
16
+ )
17
+
18
+
19
+ class _AnsiToken(NamedTuple):
20
+ """Result of ansi tokenized string."""
21
+
22
+ plain: str = ""
23
+ sgr: Optional[str] = ""
24
+ osc: Optional[str] = ""
25
+
26
+
27
+ def _ansi_tokenize(ansi_text: str) -> Iterable[_AnsiToken]:
28
+ """Tokenize a string in to plain text and ANSI codes.
29
+
30
+ Args:
31
+ ansi_text (str): A String containing ANSI codes.
32
+
33
+ Yields:
34
+ AnsiToken: A named tuple of (plain, sgr, osc)
35
+ """
36
+
37
+ position = 0
38
+ sgr: Optional[str]
39
+ osc: Optional[str]
40
+ for match in re_ansi.finditer(ansi_text):
41
+ start, end = match.span(0)
42
+ osc, sgr = match.groups()
43
+ if start > position:
44
+ yield _AnsiToken(ansi_text[position:start])
45
+ if sgr:
46
+ if sgr == "(":
47
+ position = end + 1
48
+ continue
49
+ if sgr.endswith("m"):
50
+ yield _AnsiToken("", sgr[1:-1], osc)
51
+ else:
52
+ yield _AnsiToken("", sgr, osc)
53
+ position = end
54
+ if position < len(ansi_text):
55
+ yield _AnsiToken(ansi_text[position:])
56
+
57
+
58
+ SGR_STYLE_MAP = {
59
+ 1: "bold",
60
+ 2: "dim",
61
+ 3: "italic",
62
+ 4: "underline",
63
+ 5: "blink",
64
+ 6: "blink2",
65
+ 7: "reverse",
66
+ 8: "conceal",
67
+ 9: "strike",
68
+ 21: "underline2",
69
+ 22: "not dim not bold",
70
+ 23: "not italic",
71
+ 24: "not underline",
72
+ 25: "not blink",
73
+ 26: "not blink2",
74
+ 27: "not reverse",
75
+ 28: "not conceal",
76
+ 29: "not strike",
77
+ 30: "color(0)",
78
+ 31: "color(1)",
79
+ 32: "color(2)",
80
+ 33: "color(3)",
81
+ 34: "color(4)",
82
+ 35: "color(5)",
83
+ 36: "color(6)",
84
+ 37: "color(7)",
85
+ 39: "default",
86
+ 40: "on color(0)",
87
+ 41: "on color(1)",
88
+ 42: "on color(2)",
89
+ 43: "on color(3)",
90
+ 44: "on color(4)",
91
+ 45: "on color(5)",
92
+ 46: "on color(6)",
93
+ 47: "on color(7)",
94
+ 49: "on default",
95
+ 51: "frame",
96
+ 52: "encircle",
97
+ 53: "overline",
98
+ 54: "not frame not encircle",
99
+ 55: "not overline",
100
+ 90: "color(8)",
101
+ 91: "color(9)",
102
+ 92: "color(10)",
103
+ 93: "color(11)",
104
+ 94: "color(12)",
105
+ 95: "color(13)",
106
+ 96: "color(14)",
107
+ 97: "color(15)",
108
+ 100: "on color(8)",
109
+ 101: "on color(9)",
110
+ 102: "on color(10)",
111
+ 103: "on color(11)",
112
+ 104: "on color(12)",
113
+ 105: "on color(13)",
114
+ 106: "on color(14)",
115
+ 107: "on color(15)",
116
+ }
117
+
118
+
119
+ class AnsiDecoder:
120
+ """Translate ANSI code in to styled Text."""
121
+
122
+ def __init__(self) -> None:
123
+ self.style = Style.null()
124
+
125
+ def decode(self, terminal_text: str) -> Iterable[Text]:
126
+ """Decode ANSI codes in an iterable of lines.
127
+
128
+ Args:
129
+ lines (Iterable[str]): An iterable of lines of terminal output.
130
+
131
+ Yields:
132
+ Text: Marked up Text.
133
+ """
134
+ for line in terminal_text.splitlines():
135
+ yield self.decode_line(line)
136
+
137
+ def decode_line(self, line: str) -> Text:
138
+ """Decode a line containing ansi codes.
139
+
140
+ Args:
141
+ line (str): A line of terminal output.
142
+
143
+ Returns:
144
+ Text: A Text instance marked up according to ansi codes.
145
+ """
146
+ from_ansi = Color.from_ansi
147
+ from_rgb = Color.from_rgb
148
+ _Style = Style
149
+ text = Text()
150
+ append = text.append
151
+ line = line.rsplit("\r", 1)[-1]
152
+ for plain_text, sgr, osc in _ansi_tokenize(line):
153
+ if plain_text:
154
+ append(plain_text, self.style or None)
155
+ elif osc is not None:
156
+ if osc.startswith("8;"):
157
+ _params, semicolon, link = osc[2:].partition(";")
158
+ if semicolon:
159
+ self.style = self.style.update_link(link or None)
160
+ elif sgr is not None:
161
+ # Translate in to semi-colon separated codes
162
+ # Ignore invalid codes, because we want to be lenient
163
+ codes = [
164
+ min(255, int(_code) if _code else 0)
165
+ for _code in sgr.split(";")
166
+ if _code.isdigit() or _code == ""
167
+ ]
168
+ iter_codes = iter(codes)
169
+ for code in iter_codes:
170
+ if code == 0:
171
+ # reset
172
+ self.style = _Style.null()
173
+ elif code in SGR_STYLE_MAP:
174
+ # styles
175
+ self.style += _Style.parse(SGR_STYLE_MAP[code])
176
+ elif code == 38:
177
+ #  Foreground
178
+ with suppress(StopIteration):
179
+ color_type = next(iter_codes)
180
+ if color_type == 5:
181
+ self.style += _Style.from_color(
182
+ from_ansi(next(iter_codes))
183
+ )
184
+ elif color_type == 2:
185
+ self.style += _Style.from_color(
186
+ from_rgb(
187
+ next(iter_codes),
188
+ next(iter_codes),
189
+ next(iter_codes),
190
+ )
191
+ )
192
+ elif code == 48:
193
+ # Background
194
+ with suppress(StopIteration):
195
+ color_type = next(iter_codes)
196
+ if color_type == 5:
197
+ self.style += _Style.from_color(
198
+ None, from_ansi(next(iter_codes))
199
+ )
200
+ elif color_type == 2:
201
+ self.style += _Style.from_color(
202
+ None,
203
+ from_rgb(
204
+ next(iter_codes),
205
+ next(iter_codes),
206
+ next(iter_codes),
207
+ ),
208
+ )
209
+
210
+ return text
211
+
212
+
213
+ if sys.platform != "win32" and __name__ == "__main__": # pragma: no cover
214
+ import io
215
+ import os
216
+ import pty
217
+ import sys
218
+
219
+ decoder = AnsiDecoder()
220
+
221
+ stdout = io.BytesIO()
222
+
223
+ def read(fd: int) -> bytes:
224
+ data = os.read(fd, 1024)
225
+ stdout.write(data)
226
+ return data
227
+
228
+ pty.spawn(sys.argv[1:], read)
229
+
230
+ from .console import Console
231
+
232
+ console = Console(record=True)
233
+
234
+ stdout_result = stdout.getvalue().decode("utf-8")
235
+ print(stdout_result)
236
+
237
+ for line in decoder.decode(stdout_result):
238
+ console.print(line)
239
+
240
+ console.save_html("stdout.html")
.venv/Lib/site-packages/pip/_vendor/rich/bar.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
52
+ width = min(
53
+ self.width if self.width is not None else options.max_width,
54
+ options.max_width,
55
+ )
56
+
57
+ if self.begin >= self.end:
58
+ yield Segment(" " * width, self.style)
59
+ yield Segment.line()
60
+ return
61
+
62
+ prefix_complete_eights = int(width * 8 * self.begin / self.size)
63
+ prefix_bar_count = prefix_complete_eights // 8
64
+ prefix_eights_count = prefix_complete_eights % 8
65
+
66
+ body_complete_eights = int(width * 8 * self.end / self.size)
67
+ body_bar_count = body_complete_eights // 8
68
+ body_eights_count = body_complete_eights % 8
69
+
70
+ # When start and end fall into the same cell, we ideally should render
71
+ # a symbol that's "center-aligned", but there is no good symbol in Unicode.
72
+ # In this case, we fall back to right-aligned block symbol for simplicity.
73
+
74
+ prefix = " " * prefix_bar_count
75
+ if prefix_eights_count:
76
+ prefix += BEGIN_BLOCK_ELEMENTS[prefix_eights_count]
77
+
78
+ body = FULL_BLOCK * body_bar_count
79
+ if body_eights_count:
80
+ body += END_BLOCK_ELEMENTS[body_eights_count]
81
+
82
+ suffix = " " * (width - len(body))
83
+
84
+ yield Segment(prefix + body[len(prefix) :] + suffix, self.style)
85
+ yield Segment.line()
86
+
87
+ def __rich_measure__(
88
+ self, console: Console, options: ConsoleOptions
89
+ ) -> Measurement:
90
+ return (
91
+ Measurement(self.width, self.width)
92
+ if self.width is not None
93
+ else Measurement(4, options.max_width)
94
+ )
.venv/Lib/site-packages/pip/_vendor/rich/box.py ADDED
@@ -0,0 +1,517 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ASCII: Box = Box(
192
+ """\
193
+ +--+
194
+ | ||
195
+ |-+|
196
+ | ||
197
+ |-+|
198
+ |-+|
199
+ | ||
200
+ +--+
201
+ """,
202
+ ascii=True,
203
+ )
204
+
205
+ ASCII2: Box = Box(
206
+ """\
207
+ +-++
208
+ | ||
209
+ +-++
210
+ | ||
211
+ +-++
212
+ +-++
213
+ | ||
214
+ +-++
215
+ """,
216
+ ascii=True,
217
+ )
218
+
219
+ ASCII_DOUBLE_HEAD: Box = Box(
220
+ """\
221
+ +-++
222
+ | ||
223
+ +=++
224
+ | ||
225
+ +-++
226
+ +-++
227
+ | ||
228
+ +-++
229
+ """,
230
+ ascii=True,
231
+ )
232
+
233
+ SQUARE: Box = Box(
234
+ """\
235
+ ┌─┬┐
236
+ │ ││
237
+ ├─┼┤
238
+ │ ││
239
+ ├─┼┤
240
+ ├─┼┤
241
+ │ ││
242
+ └─┴┘
243
+ """
244
+ )
245
+
246
+ SQUARE_DOUBLE_HEAD: Box = Box(
247
+ """\
248
+ ┌─┬┐
249
+ │ ││
250
+ ╞═╪╡
251
+ │ ││
252
+ ├─┼┤
253
+ ├─┼┤
254
+ │ ││
255
+ └─┴┘
256
+ """
257
+ )
258
+
259
+ MINIMAL: Box = Box(
260
+ """\
261
+
262
+
263
+ ╶─┼╴
264
+
265
+ ╶─┼╴
266
+ ╶─┼╴
267
+
268
+
269
+ """
270
+ )
271
+
272
+
273
+ MINIMAL_HEAVY_HEAD: Box = Box(
274
+ """\
275
+
276
+
277
+ ╺━┿╸
278
+
279
+ ╶─┼╴
280
+ ╶─┼╴
281
+
282
+
283
+ """
284
+ )
285
+
286
+ MINIMAL_DOUBLE_HEAD: Box = Box(
287
+ """\
288
+
289
+
290
+ ═╪
291
+
292
+ ─┼
293
+ ─┼
294
+
295
+
296
+ """
297
+ )
298
+
299
+
300
+ SIMPLE: Box = Box(
301
+ """\
302
+
303
+
304
+ ──
305
+
306
+
307
+ ──
308
+
309
+
310
+ """
311
+ )
312
+
313
+ SIMPLE_HEAD: Box = Box(
314
+ """\
315
+
316
+
317
+ ──
318
+
319
+
320
+
321
+
322
+
323
+ """
324
+ )
325
+
326
+
327
+ SIMPLE_HEAVY: Box = Box(
328
+ """\
329
+
330
+
331
+ ━━
332
+
333
+
334
+ ━━
335
+
336
+
337
+ """
338
+ )
339
+
340
+
341
+ HORIZONTALS: Box = Box(
342
+ """\
343
+ ──
344
+
345
+ ──
346
+
347
+ ──
348
+ ──
349
+
350
+ ──
351
+ """
352
+ )
353
+
354
+ ROUNDED: Box = Box(
355
+ """\
356
+ ╭─┬╮
357
+ │ ││
358
+ ├─┼┤
359
+ │ ││
360
+ ├─┼┤
361
+ ├─┼┤
362
+ │ ││
363
+ ╰─┴╯
364
+ """
365
+ )
366
+
367
+ HEAVY: Box = Box(
368
+ """\
369
+ ┏━┳┓
370
+ ┃ ┃┃
371
+ ┣━╋┫
372
+ ┃ ┃┃
373
+ ┣━╋┫
374
+ ┣━╋┫
375
+ ┃ ┃┃
376
+ ┗━┻┛
377
+ """
378
+ )
379
+
380
+ HEAVY_EDGE: Box = Box(
381
+ """\
382
+ ┏━┯┓
383
+ ┃ │┃
384
+ ┠─┼┨
385
+ ┃ │┃
386
+ ┠─┼┨
387
+ ┠─┼┨
388
+ ┃ │┃
389
+ ┗━┷┛
390
+ """
391
+ )
392
+
393
+ HEAVY_HEAD: Box = Box(
394
+ """\
395
+ ┏━┳┓
396
+ ┃ ┃┃
397
+ ┡━╇┩
398
+ │ ││
399
+ ├─┼┤
400
+ ├─┼┤
401
+ │ ││
402
+ └─┴┘
403
+ """
404
+ )
405
+
406
+ DOUBLE: Box = Box(
407
+ """\
408
+ ╔═╦╗
409
+ ║ ║║
410
+ ╠═╬╣
411
+ ║ ║║
412
+ ╠═╬╣
413
+ ╠═╬╣
414
+ ║ ║║
415
+ ╚═╩╝
416
+ """
417
+ )
418
+
419
+ DOUBLE_EDGE: Box = Box(
420
+ """\
421
+ ╔═╤╗
422
+ ║ │║
423
+ ╟─┼╢
424
+ ║ │║
425
+ ╟─┼╢
426
+ ╟─┼╢
427
+ ║ │║
428
+ ╚═╧╝
429
+ """
430
+ )
431
+
432
+ MARKDOWN: Box = Box(
433
+ """\
434
+
435
+ | ||
436
+ |-||
437
+ | ||
438
+ |-||
439
+ |-||
440
+ | ||
441
+
442
+ """,
443
+ ascii=True,
444
+ )
445
+
446
+ # Map Boxes that don't render with raster fonts on to equivalent that do
447
+ LEGACY_WINDOWS_SUBSTITUTIONS = {
448
+ ROUNDED: SQUARE,
449
+ MINIMAL_HEAVY_HEAD: MINIMAL,
450
+ SIMPLE_HEAVY: SIMPLE,
451
+ HEAVY: SQUARE,
452
+ HEAVY_EDGE: SQUARE,
453
+ HEAVY_HEAD: SQUARE,
454
+ }
455
+
456
+ # Map headed boxes to their headerless equivalents
457
+ PLAIN_HEADED_SUBSTITUTIONS = {
458
+ HEAVY_HEAD: SQUARE,
459
+ SQUARE_DOUBLE_HEAD: SQUARE,
460
+ MINIMAL_DOUBLE_HEAD: MINIMAL,
461
+ MINIMAL_HEAVY_HEAD: MINIMAL,
462
+ ASCII_DOUBLE_HEAD: ASCII2,
463
+ }
464
+
465
+
466
+ if __name__ == "__main__": # pragma: no cover
467
+
468
+ from pip._vendor.rich.columns import Columns
469
+ from pip._vendor.rich.panel import Panel
470
+
471
+ from . import box as box
472
+ from .console import Console
473
+ from .table import Table
474
+ from .text import Text
475
+
476
+ console = Console(record=True)
477
+
478
+ BOXES = [
479
+ "ASCII",
480
+ "ASCII2",
481
+ "ASCII_DOUBLE_HEAD",
482
+ "SQUARE",
483
+ "SQUARE_DOUBLE_HEAD",
484
+ "MINIMAL",
485
+ "MINIMAL_HEAVY_HEAD",
486
+ "MINIMAL_DOUBLE_HEAD",
487
+ "SIMPLE",
488
+ "SIMPLE_HEAD",
489
+ "SIMPLE_HEAVY",
490
+ "HORIZONTALS",
491
+ "ROUNDED",
492
+ "HEAVY",
493
+ "HEAVY_EDGE",
494
+ "HEAVY_HEAD",
495
+ "DOUBLE",
496
+ "DOUBLE_EDGE",
497
+ "MARKDOWN",
498
+ ]
499
+
500
+ console.print(Panel("[bold green]Box Constants", style="green"), justify="center")
501
+ console.print()
502
+
503
+ columns = Columns(expand=True, padding=2)
504
+ for box_name in sorted(BOXES):
505
+ table = Table(
506
+ show_footer=True, style="dim", border_style="not dim", expand=True
507
+ )
508
+ table.add_column("Header 1", "Footer 1")
509
+ table.add_column("Header 2", "Footer 2")
510
+ table.add_row("Cell", "Cell")
511
+ table.add_row("Cell", "Cell")
512
+ table.box = getattr(box, box_name)
513
+ table.title = Text(f"box.{box_name}", style="magenta")
514
+ columns.add_renderable(table)
515
+ console.print(columns)
516
+
517
+ # console.save_svg("box.svg")
.venv/Lib/site-packages/pip/_vendor/rich/cells.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from functools import lru_cache
3
+ from typing import Callable, List
4
+
5
+ from ._cell_widths import CELL_WIDTHS
6
+
7
+ # Regex to match sequence of the most common character ranges
8
+ _is_single_cell_widths = re.compile("^[\u0020-\u006f\u00a0\u02ff\u0370-\u0482]*$").match
9
+
10
+
11
+ @lru_cache(4096)
12
+ def cached_cell_len(text: str) -> int:
13
+ """Get the number of cells required to display text.
14
+
15
+ This method always caches, which may use up a lot of memory. It is recommended to use
16
+ `cell_len` over this method.
17
+
18
+ Args:
19
+ text (str): Text to display.
20
+
21
+ Returns:
22
+ int: Get the number of cells required to display text.
23
+ """
24
+ _get_size = get_character_cell_size
25
+ total_size = sum(_get_size(character) for character in text)
26
+ return total_size
27
+
28
+
29
+ def cell_len(text: str, _cell_len: Callable[[str], int] = cached_cell_len) -> int:
30
+ """Get the number of cells required to display text.
31
+
32
+ Args:
33
+ text (str): Text to display.
34
+
35
+ Returns:
36
+ int: Get the number of cells required to display text.
37
+ """
38
+ if len(text) < 512:
39
+ return _cell_len(text)
40
+ _get_size = get_character_cell_size
41
+ total_size = sum(_get_size(character) for character in text)
42
+ return total_size
43
+
44
+
45
+ @lru_cache(maxsize=4096)
46
+ def get_character_cell_size(character: str) -> int:
47
+ """Get the cell size of a character.
48
+
49
+ Args:
50
+ character (str): A single character.
51
+
52
+ Returns:
53
+ int: Number of cells (0, 1 or 2) occupied by that character.
54
+ """
55
+ return _get_codepoint_cell_size(ord(character))
56
+
57
+
58
+ @lru_cache(maxsize=4096)
59
+ def _get_codepoint_cell_size(codepoint: int) -> int:
60
+ """Get the cell size of a character.
61
+
62
+ Args:
63
+ codepoint (int): Codepoint of a character.
64
+
65
+ Returns:
66
+ int: Number of cells (0, 1 or 2) occupied by that character.
67
+ """
68
+
69
+ _table = CELL_WIDTHS
70
+ lower_bound = 0
71
+ upper_bound = len(_table) - 1
72
+ index = (lower_bound + upper_bound) // 2
73
+ while True:
74
+ start, end, width = _table[index]
75
+ if codepoint < start:
76
+ upper_bound = index - 1
77
+ elif codepoint > end:
78
+ lower_bound = index + 1
79
+ else:
80
+ return 0 if width == -1 else width
81
+ if upper_bound < lower_bound:
82
+ break
83
+ index = (lower_bound + upper_bound) // 2
84
+ return 1
85
+
86
+
87
+ def set_cell_size(text: str, total: int) -> str:
88
+ """Set the length of a string to fit within given number of cells."""
89
+
90
+ if _is_single_cell_widths(text):
91
+ size = len(text)
92
+ if size < total:
93
+ return text + " " * (total - size)
94
+ return text[:total]
95
+
96
+ if total <= 0:
97
+ return ""
98
+ cell_size = cell_len(text)
99
+ if cell_size == total:
100
+ return text
101
+ if cell_size < total:
102
+ return text + " " * (total - cell_size)
103
+
104
+ start = 0
105
+ end = len(text)
106
+
107
+ # Binary search until we find the right size
108
+ while True:
109
+ pos = (start + end) // 2
110
+ before = text[: pos + 1]
111
+ before_len = cell_len(before)
112
+ if before_len == total + 1 and cell_len(before[-1]) == 2:
113
+ return before[:-1] + " "
114
+ if before_len == total:
115
+ return before
116
+ if before_len > total:
117
+ end = pos
118
+ else:
119
+ start = pos
120
+
121
+
122
+ # TODO: This is inefficient
123
+ # TODO: This might not work with CWJ type characters
124
+ def chop_cells(text: str, max_size: int, position: int = 0) -> List[str]:
125
+ """Break text in to equal (cell) length strings, returning the characters in reverse
126
+ order"""
127
+ _get_character_cell_size = get_character_cell_size
128
+ characters = [
129
+ (character, _get_character_cell_size(character)) for character in text
130
+ ]
131
+ total_size = position
132
+ lines: List[List[str]] = [[]]
133
+ append = lines[-1].append
134
+
135
+ for character, size in reversed(characters):
136
+ if total_size + size > max_size:
137
+ lines.append([character])
138
+ append = lines[-1].append
139
+ total_size = size
140
+ else:
141
+ total_size += size
142
+ append(character)
143
+
144
+ return ["".join(line) for line in lines]
145
+
146
+
147
+ if __name__ == "__main__": # pragma: no cover
148
+
149
+ print(get_character_cell_size("😽"))
150
+ for line in chop_cells("""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", 8):
151
+ print(line)
152
+ for n in range(80, 1, -1):
153
+ print(set_cell_size("""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", n) + "|")
154
+ print("x" * n)
.venv/Lib/site-packages/pip/_vendor/rich/color.py ADDED
@@ -0,0 +1,622 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import platform
2
+ import re
3
+ from colorsys import rgb_to_hls
4
+ from enum import IntEnum
5
+ from functools import lru_cache
6
+ from typing import TYPE_CHECKING, NamedTuple, Optional, Tuple
7
+
8
+ from ._palettes import EIGHT_BIT_PALETTE, STANDARD_PALETTE, WINDOWS_PALETTE
9
+ from .color_triplet import ColorTriplet
10
+ from .repr import Result, rich_repr
11
+ from .terminal_theme import DEFAULT_TERMINAL_THEME
12
+
13
+ if TYPE_CHECKING: # pragma: no cover
14
+ from .terminal_theme import TerminalTheme
15
+ from .text import Text
16
+
17
+
18
+ WINDOWS = platform.system() == "Windows"
19
+
20
+
21
+ class ColorSystem(IntEnum):
22
+ """One of the 3 color system supported by terminals."""
23
+
24
+ STANDARD = 1
25
+ EIGHT_BIT = 2
26
+ TRUECOLOR = 3
27
+ WINDOWS = 4
28
+
29
+ def __repr__(self) -> str:
30
+ return f"ColorSystem.{self.name}"
31
+
32
+ def __str__(self) -> str:
33
+ return repr(self)
34
+
35
+
36
+ class ColorType(IntEnum):
37
+ """Type of color stored in Color class."""
38
+
39
+ DEFAULT = 0
40
+ STANDARD = 1
41
+ EIGHT_BIT = 2
42
+ TRUECOLOR = 3
43
+ WINDOWS = 4
44
+
45
+ def __repr__(self) -> str:
46
+ return f"ColorType.{self.name}"
47
+
48
+
49
+ ANSI_COLOR_NAMES = {
50
+ "black": 0,
51
+ "red": 1,
52
+ "green": 2,
53
+ "yellow": 3,
54
+ "blue": 4,
55
+ "magenta": 5,
56
+ "cyan": 6,
57
+ "white": 7,
58
+ "bright_black": 8,
59
+ "bright_red": 9,
60
+ "bright_green": 10,
61
+ "bright_yellow": 11,
62
+ "bright_blue": 12,
63
+ "bright_magenta": 13,
64
+ "bright_cyan": 14,
65
+ "bright_white": 15,
66
+ "grey0": 16,
67
+ "gray0": 16,
68
+ "navy_blue": 17,
69
+ "dark_blue": 18,
70
+ "blue3": 20,
71
+ "blue1": 21,
72
+ "dark_green": 22,
73
+ "deep_sky_blue4": 25,
74
+ "dodger_blue3": 26,
75
+ "dodger_blue2": 27,
76
+ "green4": 28,
77
+ "spring_green4": 29,
78
+ "turquoise4": 30,
79
+ "deep_sky_blue3": 32,
80
+ "dodger_blue1": 33,
81
+ "green3": 40,
82
+ "spring_green3": 41,
83
+ "dark_cyan": 36,
84
+ "light_sea_green": 37,
85
+ "deep_sky_blue2": 38,
86
+ "deep_sky_blue1": 39,
87
+ "spring_green2": 47,
88
+ "cyan3": 43,
89
+ "dark_turquoise": 44,
90
+ "turquoise2": 45,
91
+ "green1": 46,
92
+ "spring_green1": 48,
93
+ "medium_spring_green": 49,
94
+ "cyan2": 50,
95
+ "cyan1": 51,
96
+ "dark_red": 88,
97
+ "deep_pink4": 125,
98
+ "purple4": 55,
99
+ "purple3": 56,
100
+ "blue_violet": 57,
101
+ "orange4": 94,
102
+ "grey37": 59,
103
+ "gray37": 59,
104
+ "medium_purple4": 60,
105
+ "slate_blue3": 62,
106
+ "royal_blue1": 63,
107
+ "chartreuse4": 64,
108
+ "dark_sea_green4": 71,
109
+ "pale_turquoise4": 66,
110
+ "steel_blue": 67,
111
+ "steel_blue3": 68,
112
+ "cornflower_blue": 69,
113
+ "chartreuse3": 76,
114
+ "cadet_blue": 73,
115
+ "sky_blue3": 74,
116
+ "steel_blue1": 81,
117
+ "pale_green3": 114,
118
+ "sea_green3": 78,
119
+ "aquamarine3": 79,
120
+ "medium_turquoise": 80,
121
+ "chartreuse2": 112,
122
+ "sea_green2": 83,
123
+ "sea_green1": 85,
124
+ "aquamarine1": 122,
125
+ "dark_slate_gray2": 87,
126
+ "dark_magenta": 91,
127
+ "dark_violet": 128,
128
+ "purple": 129,
129
+ "light_pink4": 95,
130
+ "plum4": 96,
131
+ "medium_purple3": 98,
132
+ "slate_blue1": 99,
133
+ "yellow4": 106,
134
+ "wheat4": 101,
135
+ "grey53": 102,
136
+ "gray53": 102,
137
+ "light_slate_grey": 103,
138
+ "light_slate_gray": 103,
139
+ "medium_purple": 104,
140
+ "light_slate_blue": 105,
141
+ "dark_olive_green3": 149,
142
+ "dark_sea_green": 108,
143
+ "light_sky_blue3": 110,
144
+ "sky_blue2": 111,
145
+ "dark_sea_green3": 150,
146
+ "dark_slate_gray3": 116,
147
+ "sky_blue1": 117,
148
+ "chartreuse1": 118,
149
+ "light_green": 120,
150
+ "pale_green1": 156,
151
+ "dark_slate_gray1": 123,
152
+ "red3": 160,
153
+ "medium_violet_red": 126,
154
+ "magenta3": 164,
155
+ "dark_orange3": 166,
156
+ "indian_red": 167,
157
+ "hot_pink3": 168,
158
+ "medium_orchid3": 133,
159
+ "medium_orchid": 134,
160
+ "medium_purple2": 140,
161
+ "dark_goldenrod": 136,
162
+ "light_salmon3": 173,
163
+ "rosy_brown": 138,
164
+ "grey63": 139,
165
+ "gray63": 139,
166
+ "medium_purple1": 141,
167
+ "gold3": 178,
168
+ "dark_khaki": 143,
169
+ "navajo_white3": 144,
170
+ "grey69": 145,
171
+ "gray69": 145,
172
+ "light_steel_blue3": 146,
173
+ "light_steel_blue": 147,
174
+ "yellow3": 184,
175
+ "dark_sea_green2": 157,
176
+ "light_cyan3": 152,
177
+ "light_sky_blue1": 153,
178
+ "green_yellow": 154,
179
+ "dark_olive_green2": 155,
180
+ "dark_sea_green1": 193,
181
+ "pale_turquoise1": 159,
182
+ "deep_pink3": 162,
183
+ "magenta2": 200,
184
+ "hot_pink2": 169,
185
+ "orchid": 170,
186
+ "medium_orchid1": 207,
187
+ "orange3": 172,
188
+ "light_pink3": 174,
189
+ "pink3": 175,
190
+ "plum3": 176,
191
+ "violet": 177,
192
+ "light_goldenrod3": 179,
193
+ "tan": 180,
194
+ "misty_rose3": 181,
195
+ "thistle3": 182,
196
+ "plum2": 183,
197
+ "khaki3": 185,
198
+ "light_goldenrod2": 222,
199
+ "light_yellow3": 187,
200
+ "grey84": 188,
201
+ "gray84": 188,
202
+ "light_steel_blue1": 189,
203
+ "yellow2": 190,
204
+ "dark_olive_green1": 192,
205
+ "honeydew2": 194,
206
+ "light_cyan1": 195,
207
+ "red1": 196,
208
+ "deep_pink2": 197,
209
+ "deep_pink1": 199,
210
+ "magenta1": 201,
211
+ "orange_red1": 202,
212
+ "indian_red1": 204,
213
+ "hot_pink": 206,
214
+ "dark_orange": 208,
215
+ "salmon1": 209,
216
+ "light_coral": 210,
217
+ "pale_violet_red1": 211,
218
+ "orchid2": 212,
219
+ "orchid1": 213,
220
+ "orange1": 214,
221
+ "sandy_brown": 215,
222
+ "light_salmon1": 216,
223
+ "light_pink1": 217,
224
+ "pink1": 218,
225
+ "plum1": 219,
226
+ "gold1": 220,
227
+ "navajo_white1": 223,
228
+ "misty_rose1": 224,
229
+ "thistle1": 225,
230
+ "yellow1": 226,
231
+ "light_goldenrod1": 227,
232
+ "khaki1": 228,
233
+ "wheat1": 229,
234
+ "cornsilk1": 230,
235
+ "grey100": 231,
236
+ "gray100": 231,
237
+ "grey3": 232,
238
+ "gray3": 232,
239
+ "grey7": 233,
240
+ "gray7": 233,
241
+ "grey11": 234,
242
+ "gray11": 234,
243
+ "grey15": 235,
244
+ "gray15": 235,
245
+ "grey19": 236,
246
+ "gray19": 236,
247
+ "grey23": 237,
248
+ "gray23": 237,
249
+ "grey27": 238,
250
+ "gray27": 238,
251
+ "grey30": 239,
252
+ "gray30": 239,
253
+ "grey35": 240,
254
+ "gray35": 240,
255
+ "grey39": 241,
256
+ "gray39": 241,
257
+ "grey42": 242,
258
+ "gray42": 242,
259
+ "grey46": 243,
260
+ "gray46": 243,
261
+ "grey50": 244,
262
+ "gray50": 244,
263
+ "grey54": 245,
264
+ "gray54": 245,
265
+ "grey58": 246,
266
+ "gray58": 246,
267
+ "grey62": 247,
268
+ "gray62": 247,
269
+ "grey66": 248,
270
+ "gray66": 248,
271
+ "grey70": 249,
272
+ "gray70": 249,
273
+ "grey74": 250,
274
+ "gray74": 250,
275
+ "grey78": 251,
276
+ "gray78": 251,
277
+ "grey82": 252,
278
+ "gray82": 252,
279
+ "grey85": 253,
280
+ "gray85": 253,
281
+ "grey89": 254,
282
+ "gray89": 254,
283
+ "grey93": 255,
284
+ "gray93": 255,
285
+ }
286
+
287
+
288
+ class ColorParseError(Exception):
289
+ """The color could not be parsed."""
290
+
291
+
292
+ RE_COLOR = re.compile(
293
+ r"""^
294
+ \#([0-9a-f]{6})$|
295
+ color\(([0-9]{1,3})\)$|
296
+ rgb\(([\d\s,]+)\)$
297
+ """,
298
+ re.VERBOSE,
299
+ )
300
+
301
+
302
+ @rich_repr
303
+ class Color(NamedTuple):
304
+ """Terminal color definition."""
305
+
306
+ name: str
307
+ """The name of the color (typically the input to Color.parse)."""
308
+ type: ColorType
309
+ """The type of the color."""
310
+ number: Optional[int] = None
311
+ """The color number, if a standard color, or None."""
312
+ triplet: Optional[ColorTriplet] = None
313
+ """A triplet of color components, if an RGB color."""
314
+
315
+ def __rich__(self) -> "Text":
316
+ """Displays the actual color if Rich printed."""
317
+ from .style import Style
318
+ from .text import Text
319
+
320
+ return Text.assemble(
321
+ f"<color {self.name!r} ({self.type.name.lower()})",
322
+ ("⬤", Style(color=self)),
323
+ " >",
324
+ )
325
+
326
+ def __rich_repr__(self) -> Result:
327
+ yield self.name
328
+ yield self.type
329
+ yield "number", self.number, None
330
+ yield "triplet", self.triplet, None
331
+
332
+ @property
333
+ def system(self) -> ColorSystem:
334
+ """Get the native color system for this color."""
335
+ if self.type == ColorType.DEFAULT:
336
+ return ColorSystem.STANDARD
337
+ return ColorSystem(int(self.type))
338
+
339
+ @property
340
+ def is_system_defined(self) -> bool:
341
+ """Check if the color is ultimately defined by the system."""
342
+ return self.system not in (ColorSystem.EIGHT_BIT, ColorSystem.TRUECOLOR)
343
+
344
+ @property
345
+ def is_default(self) -> bool:
346
+ """Check if the color is a default color."""
347
+ return self.type == ColorType.DEFAULT
348
+
349
+ def get_truecolor(
350
+ self, theme: Optional["TerminalTheme"] = None, foreground: bool = True
351
+ ) -> ColorTriplet:
352
+ """Get an equivalent color triplet for this color.
353
+
354
+ Args:
355
+ theme (TerminalTheme, optional): Optional terminal theme, or None to use default. Defaults to None.
356
+ foreground (bool, optional): True for a foreground color, or False for background. Defaults to True.
357
+
358
+ Returns:
359
+ ColorTriplet: A color triplet containing RGB components.
360
+ """
361
+
362
+ if theme is None:
363
+ theme = DEFAULT_TERMINAL_THEME
364
+ if self.type == ColorType.TRUECOLOR:
365
+ assert self.triplet is not None
366
+ return self.triplet
367
+ elif self.type == ColorType.EIGHT_BIT:
368
+ assert self.number is not None
369
+ return EIGHT_BIT_PALETTE[self.number]
370
+ elif self.type == ColorType.STANDARD:
371
+ assert self.number is not None
372
+ return theme.ansi_colors[self.number]
373
+ elif self.type == ColorType.WINDOWS:
374
+ assert self.number is not None
375
+ return WINDOWS_PALETTE[self.number]
376
+ else: # self.type == ColorType.DEFAULT:
377
+ assert self.number is None
378
+ return theme.foreground_color if foreground else theme.background_color
379
+
380
+ @classmethod
381
+ def from_ansi(cls, number: int) -> "Color":
382
+ """Create a Color number from it's 8-bit ansi number.
383
+
384
+ Args:
385
+ number (int): A number between 0-255 inclusive.
386
+
387
+ Returns:
388
+ Color: A new Color instance.
389
+ """
390
+ return cls(
391
+ name=f"color({number})",
392
+ type=(ColorType.STANDARD if number < 16 else ColorType.EIGHT_BIT),
393
+ number=number,
394
+ )
395
+
396
+ @classmethod
397
+ def from_triplet(cls, triplet: "ColorTriplet") -> "Color":
398
+ """Create a truecolor RGB color from a triplet of values.
399
+
400
+ Args:
401
+ triplet (ColorTriplet): A color triplet containing red, green and blue components.
402
+
403
+ Returns:
404
+ Color: A new color object.
405
+ """
406
+ return cls(name=triplet.hex, type=ColorType.TRUECOLOR, triplet=triplet)
407
+
408
+ @classmethod
409
+ def from_rgb(cls, red: float, green: float, blue: float) -> "Color":
410
+ """Create a truecolor from three color components in the range(0->255).
411
+
412
+ Args:
413
+ red (float): Red component in range 0-255.
414
+ green (float): Green component in range 0-255.
415
+ blue (float): Blue component in range 0-255.
416
+
417
+ Returns:
418
+ Color: A new color object.
419
+ """
420
+ return cls.from_triplet(ColorTriplet(int(red), int(green), int(blue)))
421
+
422
+ @classmethod
423
+ def default(cls) -> "Color":
424
+ """Get a Color instance representing the default color.
425
+
426
+ Returns:
427
+ Color: Default color.
428
+ """
429
+ return cls(name="default", type=ColorType.DEFAULT)
430
+
431
+ @classmethod
432
+ @lru_cache(maxsize=1024)
433
+ def parse(cls, color: str) -> "Color":
434
+ """Parse a color definition."""
435
+ original_color = color
436
+ color = color.lower().strip()
437
+
438
+ if color == "default":
439
+ return cls(color, type=ColorType.DEFAULT)
440
+
441
+ color_number = ANSI_COLOR_NAMES.get(color)
442
+ if color_number is not None:
443
+ return cls(
444
+ color,
445
+ type=(ColorType.STANDARD if color_number < 16 else ColorType.EIGHT_BIT),
446
+ number=color_number,
447
+ )
448
+
449
+ color_match = RE_COLOR.match(color)
450
+ if color_match is None:
451
+ raise ColorParseError(f"{original_color!r} is not a valid color")
452
+
453
+ color_24, color_8, color_rgb = color_match.groups()
454
+ if color_24:
455
+ triplet = ColorTriplet(
456
+ int(color_24[0:2], 16), int(color_24[2:4], 16), int(color_24[4:6], 16)
457
+ )
458
+ return cls(color, ColorType.TRUECOLOR, triplet=triplet)
459
+
460
+ elif color_8:
461
+ number = int(color_8)
462
+ if number > 255:
463
+ raise ColorParseError(f"color number must be <= 255 in {color!r}")
464
+ return cls(
465
+ color,
466
+ type=(ColorType.STANDARD if number < 16 else ColorType.EIGHT_BIT),
467
+ number=number,
468
+ )
469
+
470
+ else: # color_rgb:
471
+ components = color_rgb.split(",")
472
+ if len(components) != 3:
473
+ raise ColorParseError(
474
+ f"expected three components in {original_color!r}"
475
+ )
476
+ red, green, blue = components
477
+ triplet = ColorTriplet(int(red), int(green), int(blue))
478
+ if not all(component <= 255 for component in triplet):
479
+ raise ColorParseError(
480
+ f"color components must be <= 255 in {original_color!r}"
481
+ )
482
+ return cls(color, ColorType.TRUECOLOR, triplet=triplet)
483
+
484
+ @lru_cache(maxsize=1024)
485
+ def get_ansi_codes(self, foreground: bool = True) -> Tuple[str, ...]:
486
+ """Get the ANSI escape codes for this color."""
487
+ _type = self.type
488
+ if _type == ColorType.DEFAULT:
489
+ return ("39" if foreground else "49",)
490
+
491
+ elif _type == ColorType.WINDOWS:
492
+ number = self.number
493
+ assert number is not None
494
+ fore, back = (30, 40) if number < 8 else (82, 92)
495
+ return (str(fore + number if foreground else back + number),)
496
+
497
+ elif _type == ColorType.STANDARD:
498
+ number = self.number
499
+ assert number is not None
500
+ fore, back = (30, 40) if number < 8 else (82, 92)
501
+ return (str(fore + number if foreground else back + number),)
502
+
503
+ elif _type == ColorType.EIGHT_BIT:
504
+ assert self.number is not None
505
+ return ("38" if foreground else "48", "5", str(self.number))
506
+
507
+ else: # self.standard == ColorStandard.TRUECOLOR:
508
+ assert self.triplet is not None
509
+ red, green, blue = self.triplet
510
+ return ("38" if foreground else "48", "2", str(red), str(green), str(blue))
511
+
512
+ @lru_cache(maxsize=1024)
513
+ def downgrade(self, system: ColorSystem) -> "Color":
514
+ """Downgrade a color system to a system with fewer colors."""
515
+
516
+ if self.type in (ColorType.DEFAULT, system):
517
+ return self
518
+ # Convert to 8-bit color from truecolor color
519
+ if system == ColorSystem.EIGHT_BIT and self.system == ColorSystem.TRUECOLOR:
520
+ assert self.triplet is not None
521
+ _h, l, s = rgb_to_hls(*self.triplet.normalized)
522
+ # If saturation is under 15% assume it is grayscale
523
+ if s < 0.15:
524
+ gray = round(l * 25.0)
525
+ if gray == 0:
526
+ color_number = 16
527
+ elif gray == 25:
528
+ color_number = 231
529
+ else:
530
+ color_number = 231 + gray
531
+ return Color(self.name, ColorType.EIGHT_BIT, number=color_number)
532
+
533
+ red, green, blue = self.triplet
534
+ six_red = red / 95 if red < 95 else 1 + (red - 95) / 40
535
+ six_green = green / 95 if green < 95 else 1 + (green - 95) / 40
536
+ six_blue = blue / 95 if blue < 95 else 1 + (blue - 95) / 40
537
+
538
+ color_number = (
539
+ 16 + 36 * round(six_red) + 6 * round(six_green) + round(six_blue)
540
+ )
541
+ return Color(self.name, ColorType.EIGHT_BIT, number=color_number)
542
+
543
+ # Convert to standard from truecolor or 8-bit
544
+ elif system == ColorSystem.STANDARD:
545
+ if self.system == ColorSystem.TRUECOLOR:
546
+ assert self.triplet is not None
547
+ triplet = self.triplet
548
+ else: # self.system == ColorSystem.EIGHT_BIT
549
+ assert self.number is not None
550
+ triplet = ColorTriplet(*EIGHT_BIT_PALETTE[self.number])
551
+
552
+ color_number = STANDARD_PALETTE.match(triplet)
553
+ return Color(self.name, ColorType.STANDARD, number=color_number)
554
+
555
+ elif system == ColorSystem.WINDOWS:
556
+ if self.system == ColorSystem.TRUECOLOR:
557
+ assert self.triplet is not None
558
+ triplet = self.triplet
559
+ else: # self.system == ColorSystem.EIGHT_BIT
560
+ assert self.number is not None
561
+ if self.number < 16:
562
+ return Color(self.name, ColorType.WINDOWS, number=self.number)
563
+ triplet = ColorTriplet(*EIGHT_BIT_PALETTE[self.number])
564
+
565
+ color_number = WINDOWS_PALETTE.match(triplet)
566
+ return Color(self.name, ColorType.WINDOWS, number=color_number)
567
+
568
+ return self
569
+
570
+
571
+ def parse_rgb_hex(hex_color: str) -> ColorTriplet:
572
+ """Parse six hex characters in to RGB triplet."""
573
+ assert len(hex_color) == 6, "must be 6 characters"
574
+ color = ColorTriplet(
575
+ int(hex_color[0:2], 16), int(hex_color[2:4], 16), int(hex_color[4:6], 16)
576
+ )
577
+ return color
578
+
579
+
580
+ def blend_rgb(
581
+ color1: ColorTriplet, color2: ColorTriplet, cross_fade: float = 0.5
582
+ ) -> ColorTriplet:
583
+ """Blend one RGB color in to another."""
584
+ r1, g1, b1 = color1
585
+ r2, g2, b2 = color2
586
+ new_color = ColorTriplet(
587
+ int(r1 + (r2 - r1) * cross_fade),
588
+ int(g1 + (g2 - g1) * cross_fade),
589
+ int(b1 + (b2 - b1) * cross_fade),
590
+ )
591
+ return new_color
592
+
593
+
594
+ if __name__ == "__main__": # pragma: no cover
595
+
596
+ from .console import Console
597
+ from .table import Table
598
+ from .text import Text
599
+
600
+ console = Console()
601
+
602
+ table = Table(show_footer=False, show_edge=True)
603
+ table.add_column("Color", width=10, overflow="ellipsis")
604
+ table.add_column("Number", justify="right", style="yellow")
605
+ table.add_column("Name", style="green")
606
+ table.add_column("Hex", style="blue")
607
+ table.add_column("RGB", style="magenta")
608
+
609
+ colors = sorted((v, k) for k, v in ANSI_COLOR_NAMES.items())
610
+ for color_number, name in colors:
611
+ if "grey" in name:
612
+ continue
613
+ color_cell = Text(" " * 10, style=f"on {name}")
614
+ if color_number < 16:
615
+ table.add_row(color_cell, f"{color_number}", Text(f'"{name}"'))
616
+ else:
617
+ color = EIGHT_BIT_PALETTE[color_number] # type: ignore[has-type]
618
+ table.add_row(
619
+ color_cell, str(color_number), Text(f'"{name}"'), color.hex, color.rgb
620
+ )
621
+
622
+ console.print(table)
.venv/Lib/site-packages/pip/_vendor/rich/color_triplet.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import NamedTuple, Tuple
2
+
3
+
4
+ class ColorTriplet(NamedTuple):
5
+ """The red, green, and blue components of a color."""
6
+
7
+ red: int
8
+ """Red component in 0 to 255 range."""
9
+ green: int
10
+ """Green component in 0 to 255 range."""
11
+ blue: int
12
+ """Blue component in 0 to 255 range."""
13
+
14
+ @property
15
+ def hex(self) -> str:
16
+ """get the color triplet in CSS style."""
17
+ red, green, blue = self
18
+ return f"#{red:02x}{green:02x}{blue:02x}"
19
+
20
+ @property
21
+ def rgb(self) -> str:
22
+ """The color in RGB format.
23
+
24
+ Returns:
25
+ str: An rgb color, e.g. ``"rgb(100,23,255)"``.
26
+ """
27
+ red, green, blue = self
28
+ return f"rgb({red},{green},{blue})"
29
+
30
+ @property
31
+ def normalized(self) -> Tuple[float, float, float]:
32
+ """Convert components into floats between 0 and 1.
33
+
34
+ Returns:
35
+ Tuple[float, float, float]: A tuple of three normalized colour components.
36
+ """
37
+ red, green, blue = self
38
+ return red / 255.0, green / 255.0, blue / 255.0
.venv/Lib/site-packages/pip/_vendor/rich/columns.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections import defaultdict
2
+ from itertools import chain
3
+ from operator import itemgetter
4
+ from typing import Dict, Iterable, List, Optional, Tuple
5
+
6
+ from .align import Align, AlignMethod
7
+ from .console import Console, ConsoleOptions, RenderableType, RenderResult
8
+ from .constrain import Constrain
9
+ from .measure import Measurement
10
+ from .padding import Padding, PaddingDimensions
11
+ from .table import Table
12
+ from .text import TextType
13
+ from .jupyter import JupyterMixin
14
+
15
+
16
+ class Columns(JupyterMixin):
17
+ """Display renderables in neat columns.
18
+
19
+ Args:
20
+ renderables (Iterable[RenderableType]): Any number of Rich renderables (including str).
21
+ width (int, optional): The desired width of the columns, or None to auto detect. Defaults to None.
22
+ padding (PaddingDimensions, optional): Optional padding around cells. Defaults to (0, 1).
23
+ expand (bool, optional): Expand columns to full width. Defaults to False.
24
+ equal (bool, optional): Arrange in to equal sized columns. Defaults to False.
25
+ column_first (bool, optional): Align items from top to bottom (rather than left to right). Defaults to False.
26
+ right_to_left (bool, optional): Start column from right hand side. Defaults to False.
27
+ align (str, optional): Align value ("left", "right", or "center") or None for default. Defaults to None.
28
+ title (TextType, optional): Optional title for Columns.
29
+ """
30
+
31
+ def __init__(
32
+ self,
33
+ renderables: Optional[Iterable[RenderableType]] = None,
34
+ padding: PaddingDimensions = (0, 1),
35
+ *,
36
+ width: Optional[int] = None,
37
+ expand: bool = False,
38
+ equal: bool = False,
39
+ column_first: bool = False,
40
+ right_to_left: bool = False,
41
+ align: Optional[AlignMethod] = None,
42
+ title: Optional[TextType] = None,
43
+ ) -> None:
44
+ self.renderables = list(renderables or [])
45
+ self.width = width
46
+ self.padding = padding
47
+ self.expand = expand
48
+ self.equal = equal
49
+ self.column_first = column_first
50
+ self.right_to_left = right_to_left
51
+ self.align: Optional[AlignMethod] = align
52
+ self.title = title
53
+
54
+ def add_renderable(self, renderable: RenderableType) -> None:
55
+ """Add a renderable to the columns.
56
+
57
+ Args:
58
+ renderable (RenderableType): Any renderable object.
59
+ """
60
+ self.renderables.append(renderable)
61
+
62
+ def __rich_console__(
63
+ self, console: Console, options: ConsoleOptions
64
+ ) -> RenderResult:
65
+ render_str = console.render_str
66
+ renderables = [
67
+ render_str(renderable) if isinstance(renderable, str) else renderable
68
+ for renderable in self.renderables
69
+ ]
70
+ if not renderables:
71
+ return
72
+ _top, right, _bottom, left = Padding.unpack(self.padding)
73
+ width_padding = max(left, right)
74
+ max_width = options.max_width
75
+ widths: Dict[int, int] = defaultdict(int)
76
+ column_count = len(renderables)
77
+
78
+ get_measurement = Measurement.get
79
+ renderable_widths = [
80
+ get_measurement(console, options, renderable).maximum
81
+ for renderable in renderables
82
+ ]
83
+ if self.equal:
84
+ renderable_widths = [max(renderable_widths)] * len(renderable_widths)
85
+
86
+ def iter_renderables(
87
+ column_count: int,
88
+ ) -> Iterable[Tuple[int, Optional[RenderableType]]]:
89
+ item_count = len(renderables)
90
+ if self.column_first:
91
+ width_renderables = list(zip(renderable_widths, renderables))
92
+
93
+ column_lengths: List[int] = [item_count // column_count] * column_count
94
+ for col_no in range(item_count % column_count):
95
+ column_lengths[col_no] += 1
96
+
97
+ row_count = (item_count + column_count - 1) // column_count
98
+ cells = [[-1] * column_count for _ in range(row_count)]
99
+ row = col = 0
100
+ for index in range(item_count):
101
+ cells[row][col] = index
102
+ column_lengths[col] -= 1
103
+ if column_lengths[col]:
104
+ row += 1
105
+ else:
106
+ col += 1
107
+ row = 0
108
+ for index in chain.from_iterable(cells):
109
+ if index == -1:
110
+ break
111
+ yield width_renderables[index]
112
+ else:
113
+ yield from zip(renderable_widths, renderables)
114
+ # Pad odd elements with spaces
115
+ if item_count % column_count:
116
+ for _ in range(column_count - (item_count % column_count)):
117
+ yield 0, None
118
+
119
+ table = Table.grid(padding=self.padding, collapse_padding=True, pad_edge=False)
120
+ table.expand = self.expand
121
+ table.title = self.title
122
+
123
+ if self.width is not None:
124
+ column_count = (max_width) // (self.width + width_padding)
125
+ for _ in range(column_count):
126
+ table.add_column(width=self.width)
127
+ else:
128
+ while column_count > 1:
129
+ widths.clear()
130
+ column_no = 0
131
+ for renderable_width, _ in iter_renderables(column_count):
132
+ widths[column_no] = max(widths[column_no], renderable_width)
133
+ total_width = sum(widths.values()) + width_padding * (
134
+ len(widths) - 1
135
+ )
136
+ if total_width > max_width:
137
+ column_count = len(widths) - 1
138
+ break
139
+ else:
140
+ column_no = (column_no + 1) % column_count
141
+ else:
142
+ break
143
+
144
+ get_renderable = itemgetter(1)
145
+ _renderables = [
146
+ get_renderable(_renderable)
147
+ for _renderable in iter_renderables(column_count)
148
+ ]
149
+ if self.equal:
150
+ _renderables = [
151
+ None
152
+ if renderable is None
153
+ else Constrain(renderable, renderable_widths[0])
154
+ for renderable in _renderables
155
+ ]
156
+ if self.align:
157
+ align = self.align
158
+ _Align = Align
159
+ _renderables = [
160
+ None if renderable is None else _Align(renderable, align)
161
+ for renderable in _renderables
162
+ ]
163
+
164
+ right_to_left = self.right_to_left
165
+ add_row = table.add_row
166
+ for start in range(0, len(_renderables), column_count):
167
+ row = _renderables[start : start + column_count]
168
+ if right_to_left:
169
+ row = row[::-1]
170
+ add_row(*row)
171
+ yield table
172
+
173
+
174
+ if __name__ == "__main__": # pragma: no cover
175
+ import os
176
+
177
+ console = Console()
178
+
179
+ files = [f"{i} {s}" for i, s in enumerate(sorted(os.listdir()))]
180
+ columns = Columns(files, padding=(0, 1), expand=False, equal=False)
181
+ console.print(columns)
182
+ console.rule()
183
+ columns.column_first = True
184
+ console.print(columns)
185
+ columns.right_to_left = True
186
+ console.rule()
187
+ console.print(columns)
.venv/Lib/site-packages/pip/_vendor/rich/console.py ADDED
The diff for this file is too large to render. See raw diff
 
.venv/Lib/site-packages/pip/_vendor/rich/constrain.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, TYPE_CHECKING
2
+
3
+ from .jupyter import JupyterMixin
4
+ from .measure import Measurement
5
+
6
+ if TYPE_CHECKING:
7
+ from .console import Console, ConsoleOptions, RenderableType, RenderResult
8
+
9
+
10
+ class Constrain(JupyterMixin):
11
+ """Constrain the width of a renderable to a given number of characters.
12
+
13
+ Args:
14
+ renderable (RenderableType): A renderable object.
15
+ width (int, optional): The maximum width (in characters) to render. Defaults to 80.
16
+ """
17
+
18
+ def __init__(self, renderable: "RenderableType", width: Optional[int] = 80) -> None:
19
+ self.renderable = renderable
20
+ self.width = width
21
+
22
+ def __rich_console__(
23
+ self, console: "Console", options: "ConsoleOptions"
24
+ ) -> "RenderResult":
25
+ if self.width is None:
26
+ yield self.renderable
27
+ else:
28
+ child_options = options.update_width(min(self.width, options.max_width))
29
+ yield from console.render(self.renderable, child_options)
30
+
31
+ def __rich_measure__(
32
+ self, console: "Console", options: "ConsoleOptions"
33
+ ) -> "Measurement":
34
+ if self.width is not None:
35
+ options = options.update_width(self.width)
36
+ measurement = Measurement.get(console, options, self.renderable)
37
+ return measurement
.venv/Lib/site-packages/pip/_vendor/rich/containers.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from itertools import zip_longest
2
+ from typing import (
3
+ Iterator,
4
+ Iterable,
5
+ List,
6
+ Optional,
7
+ Union,
8
+ overload,
9
+ TypeVar,
10
+ TYPE_CHECKING,
11
+ )
12
+
13
+ if TYPE_CHECKING:
14
+ from .console import (
15
+ Console,
16
+ ConsoleOptions,
17
+ JustifyMethod,
18
+ OverflowMethod,
19
+ RenderResult,
20
+ RenderableType,
21
+ )
22
+ from .text import Text
23
+
24
+ from .cells import cell_len
25
+ from .measure import Measurement
26
+
27
+ T = TypeVar("T")
28
+
29
+
30
+ class Renderables:
31
+ """A list subclass which renders its contents to the console."""
32
+
33
+ def __init__(
34
+ self, renderables: Optional[Iterable["RenderableType"]] = None
35
+ ) -> None:
36
+ self._renderables: List["RenderableType"] = (
37
+ list(renderables) if renderables is not None else []
38
+ )
39
+
40
+ def __rich_console__(
41
+ self, console: "Console", options: "ConsoleOptions"
42
+ ) -> "RenderResult":
43
+ """Console render method to insert line-breaks."""
44
+ yield from self._renderables
45
+
46
+ def __rich_measure__(
47
+ self, console: "Console", options: "ConsoleOptions"
48
+ ) -> "Measurement":
49
+ dimensions = [
50
+ Measurement.get(console, options, renderable)
51
+ for renderable in self._renderables
52
+ ]
53
+ if not dimensions:
54
+ return Measurement(1, 1)
55
+ _min = max(dimension.minimum for dimension in dimensions)
56
+ _max = max(dimension.maximum for dimension in dimensions)
57
+ return Measurement(_min, _max)
58
+
59
+ def append(self, renderable: "RenderableType") -> None:
60
+ self._renderables.append(renderable)
61
+
62
+ def __iter__(self) -> Iterable["RenderableType"]:
63
+ return iter(self._renderables)
64
+
65
+
66
+ class Lines:
67
+ """A list subclass which can render to the console."""
68
+
69
+ def __init__(self, lines: Iterable["Text"] = ()) -> None:
70
+ self._lines: List["Text"] = list(lines)
71
+
72
+ def __repr__(self) -> str:
73
+ return f"Lines({self._lines!r})"
74
+
75
+ def __iter__(self) -> Iterator["Text"]:
76
+ return iter(self._lines)
77
+
78
+ @overload
79
+ def __getitem__(self, index: int) -> "Text":
80
+ ...
81
+
82
+ @overload
83
+ def __getitem__(self, index: slice) -> List["Text"]:
84
+ ...
85
+
86
+ def __getitem__(self, index: Union[slice, int]) -> Union["Text", List["Text"]]:
87
+ return self._lines[index]
88
+
89
+ def __setitem__(self, index: int, value: "Text") -> "Lines":
90
+ self._lines[index] = value
91
+ return self
92
+
93
+ def __len__(self) -> int:
94
+ return self._lines.__len__()
95
+
96
+ def __rich_console__(
97
+ self, console: "Console", options: "ConsoleOptions"
98
+ ) -> "RenderResult":
99
+ """Console render method to insert line-breaks."""
100
+ yield from self._lines
101
+
102
+ def append(self, line: "Text") -> None:
103
+ self._lines.append(line)
104
+
105
+ def extend(self, lines: Iterable["Text"]) -> None:
106
+ self._lines.extend(lines)
107
+
108
+ def pop(self, index: int = -1) -> "Text":
109
+ return self._lines.pop(index)
110
+
111
+ def justify(
112
+ self,
113
+ console: "Console",
114
+ width: int,
115
+ justify: "JustifyMethod" = "left",
116
+ overflow: "OverflowMethod" = "fold",
117
+ ) -> None:
118
+ """Justify and overflow text to a given width.
119
+
120
+ Args:
121
+ console (Console): Console instance.
122
+ width (int): Number of characters per line.
123
+ justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
124
+ overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
125
+
126
+ """
127
+ from .text import Text
128
+
129
+ if justify == "left":
130
+ for line in self._lines:
131
+ line.truncate(width, overflow=overflow, pad=True)
132
+ elif justify == "center":
133
+ for line in self._lines:
134
+ line.rstrip()
135
+ line.truncate(width, overflow=overflow)
136
+ line.pad_left((width - cell_len(line.plain)) // 2)
137
+ line.pad_right(width - cell_len(line.plain))
138
+ elif justify == "right":
139
+ for line in self._lines:
140
+ line.rstrip()
141
+ line.truncate(width, overflow=overflow)
142
+ line.pad_left(width - cell_len(line.plain))
143
+ elif justify == "full":
144
+ for line_index, line in enumerate(self._lines):
145
+ if line_index == len(self._lines) - 1:
146
+ break
147
+ words = line.split(" ")
148
+ words_size = sum(cell_len(word.plain) for word in words)
149
+ num_spaces = len(words) - 1
150
+ spaces = [1 for _ in range(num_spaces)]
151
+ index = 0
152
+ if spaces:
153
+ while words_size + num_spaces < width:
154
+ spaces[len(spaces) - index - 1] += 1
155
+ num_spaces += 1
156
+ index = (index + 1) % len(spaces)
157
+ tokens: List[Text] = []
158
+ for index, (word, next_word) in enumerate(
159
+ zip_longest(words, words[1:])
160
+ ):
161
+ tokens.append(word)
162
+ if index < len(spaces):
163
+ style = word.get_style_at_offset(console, -1)
164
+ next_style = next_word.get_style_at_offset(console, 0)
165
+ space_style = style if style == next_style else line.style
166
+ tokens.append(Text(" " * spaces[index], style=space_style))
167
+ self[line_index] = Text("").join(tokens)
.venv/Lib/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)
.venv/Lib/site-packages/pip/_vendor/rich/default_styles.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+
3
+ from .style import Style
4
+
5
+ DEFAULT_STYLES: Dict[str, Style] = {
6
+ "none": Style.null(),
7
+ "reset": Style(
8
+ color="default",
9
+ bgcolor="default",
10
+ dim=False,
11
+ bold=False,
12
+ italic=False,
13
+ underline=False,
14
+ blink=False,
15
+ blink2=False,
16
+ reverse=False,
17
+ conceal=False,
18
+ strike=False,
19
+ ),
20
+ "dim": Style(dim=True),
21
+ "bright": Style(dim=False),
22
+ "bold": Style(bold=True),
23
+ "strong": Style(bold=True),
24
+ "code": Style(reverse=True, bold=True),
25
+ "italic": Style(italic=True),
26
+ "emphasize": Style(italic=True),
27
+ "underline": Style(underline=True),
28
+ "blink": Style(blink=True),
29
+ "blink2": Style(blink2=True),
30
+ "reverse": Style(reverse=True),
31
+ "strike": Style(strike=True),
32
+ "black": Style(color="black"),
33
+ "red": Style(color="red"),
34
+ "green": Style(color="green"),
35
+ "yellow": Style(color="yellow"),
36
+ "magenta": Style(color="magenta"),
37
+ "cyan": Style(color="cyan"),
38
+ "white": Style(color="white"),
39
+ "inspect.attr": Style(color="yellow", italic=True),
40
+ "inspect.attr.dunder": Style(color="yellow", italic=True, dim=True),
41
+ "inspect.callable": Style(bold=True, color="red"),
42
+ "inspect.async_def": Style(italic=True, color="bright_cyan"),
43
+ "inspect.def": Style(italic=True, color="bright_cyan"),
44
+ "inspect.class": Style(italic=True, color="bright_cyan"),
45
+ "inspect.error": Style(bold=True, color="red"),
46
+ "inspect.equals": Style(),
47
+ "inspect.help": Style(color="cyan"),
48
+ "inspect.doc": Style(dim=True),
49
+ "inspect.value.border": Style(color="green"),
50
+ "live.ellipsis": Style(bold=True, color="red"),
51
+ "layout.tree.row": Style(dim=False, color="red"),
52
+ "layout.tree.column": Style(dim=False, color="blue"),
53
+ "logging.keyword": Style(bold=True, color="yellow"),
54
+ "logging.level.notset": Style(dim=True),
55
+ "logging.level.debug": Style(color="green"),
56
+ "logging.level.info": Style(color="blue"),
57
+ "logging.level.warning": Style(color="red"),
58
+ "logging.level.error": Style(color="red", bold=True),
59
+ "logging.level.critical": Style(color="red", bold=True, reverse=True),
60
+ "log.level": Style.null(),
61
+ "log.time": Style(color="cyan", dim=True),
62
+ "log.message": Style.null(),
63
+ "log.path": Style(dim=True),
64
+ "repr.ellipsis": Style(color="yellow"),
65
+ "repr.indent": Style(color="green", dim=True),
66
+ "repr.error": Style(color="red", bold=True),
67
+ "repr.str": Style(color="green", italic=False, bold=False),
68
+ "repr.brace": Style(bold=True),
69
+ "repr.comma": Style(bold=True),
70
+ "repr.ipv4": Style(bold=True, color="bright_green"),
71
+ "repr.ipv6": Style(bold=True, color="bright_green"),
72
+ "repr.eui48": Style(bold=True, color="bright_green"),
73
+ "repr.eui64": Style(bold=True, color="bright_green"),
74
+ "repr.tag_start": Style(bold=True),
75
+ "repr.tag_name": Style(color="bright_magenta", bold=True),
76
+ "repr.tag_contents": Style(color="default"),
77
+ "repr.tag_end": Style(bold=True),
78
+ "repr.attrib_name": Style(color="yellow", italic=False),
79
+ "repr.attrib_equal": Style(bold=True),
80
+ "repr.attrib_value": Style(color="magenta", italic=False),
81
+ "repr.number": Style(color="cyan", bold=True, italic=False),
82
+ "repr.number_complex": Style(color="cyan", bold=True, italic=False), # same
83
+ "repr.bool_true": Style(color="bright_green", italic=True),
84
+ "repr.bool_false": Style(color="bright_red", italic=True),
85
+ "repr.none": Style(color="magenta", italic=True),
86
+ "repr.url": Style(underline=True, color="bright_blue", italic=False, bold=False),
87
+ "repr.uuid": Style(color="bright_yellow", bold=False),
88
+ "repr.call": Style(color="magenta", bold=True),
89
+ "repr.path": Style(color="magenta"),
90
+ "repr.filename": Style(color="bright_magenta"),
91
+ "rule.line": Style(color="bright_green"),
92
+ "rule.text": Style.null(),
93
+ "json.brace": Style(bold=True),
94
+ "json.bool_true": Style(color="bright_green", italic=True),
95
+ "json.bool_false": Style(color="bright_red", italic=True),
96
+ "json.null": Style(color="magenta", italic=True),
97
+ "json.number": Style(color="cyan", bold=True, italic=False),
98
+ "json.str": Style(color="green", italic=False, bold=False),
99
+ "json.key": Style(color="blue", bold=True),
100
+ "prompt": Style.null(),
101
+ "prompt.choices": Style(color="magenta", bold=True),
102
+ "prompt.default": Style(color="cyan", bold=True),
103
+ "prompt.invalid": Style(color="red"),
104
+ "prompt.invalid.choice": Style(color="red"),
105
+ "pretty": Style.null(),
106
+ "scope.border": Style(color="blue"),
107
+ "scope.key": Style(color="yellow", italic=True),
108
+ "scope.key.special": Style(color="yellow", italic=True, dim=True),
109
+ "scope.equals": Style(color="red"),
110
+ "table.header": Style(bold=True),
111
+ "table.footer": Style(bold=True),
112
+ "table.cell": Style.null(),
113
+ "table.title": Style(italic=True),
114
+ "table.caption": Style(italic=True, dim=True),
115
+ "traceback.error": Style(color="red", italic=True),
116
+ "traceback.border.syntax_error": Style(color="bright_red"),
117
+ "traceback.border": Style(color="red"),
118
+ "traceback.text": Style.null(),
119
+ "traceback.title": Style(color="red", bold=True),
120
+ "traceback.exc_type": Style(color="bright_red", bold=True),
121
+ "traceback.exc_value": Style.null(),
122
+ "traceback.offset": Style(color="bright_red", bold=True),
123
+ "bar.back": Style(color="grey23"),
124
+ "bar.complete": Style(color="rgb(249,38,114)"),
125
+ "bar.finished": Style(color="rgb(114,156,31)"),
126
+ "bar.pulse": Style(color="rgb(249,38,114)"),
127
+ "progress.description": Style.null(),
128
+ "progress.filesize": Style(color="green"),
129
+ "progress.filesize.total": Style(color="green"),
130
+ "progress.download": Style(color="green"),
131
+ "progress.elapsed": Style(color="yellow"),
132
+ "progress.percentage": Style(color="magenta"),
133
+ "progress.remaining": Style(color="cyan"),
134
+ "progress.data.speed": Style(color="red"),
135
+ "progress.spinner": Style(color="green"),
136
+ "status.spinner": Style(color="green"),
137
+ "tree": Style(),
138
+ "tree.line": Style(),
139
+ "markdown.paragraph": Style(),
140
+ "markdown.text": Style(),
141
+ "markdown.em": Style(italic=True),
142
+ "markdown.emph": Style(italic=True), # For commonmark backwards compatibility
143
+ "markdown.strong": Style(bold=True),
144
+ "markdown.code": Style(bold=True, color="cyan", bgcolor="black"),
145
+ "markdown.code_block": Style(color="cyan", bgcolor="black"),
146
+ "markdown.block_quote": Style(color="magenta"),
147
+ "markdown.list": Style(color="cyan"),
148
+ "markdown.item": Style(),
149
+ "markdown.item.bullet": Style(color="yellow", bold=True),
150
+ "markdown.item.number": Style(color="yellow", bold=True),
151
+ "markdown.hr": Style(color="yellow"),
152
+ "markdown.h1.border": Style(),
153
+ "markdown.h1": Style(bold=True),
154
+ "markdown.h2": Style(bold=True, underline=True),
155
+ "markdown.h3": Style(bold=True),
156
+ "markdown.h4": Style(bold=True, dim=True),
157
+ "markdown.h5": Style(underline=True),
158
+ "markdown.h6": Style(italic=True),
159
+ "markdown.h7": Style(italic=True, dim=True),
160
+ "markdown.link": Style(color="bright_blue"),
161
+ "markdown.link_url": Style(color="blue", underline=True),
162
+ "markdown.s": Style(strike=True),
163
+ "iso8601.date": Style(color="blue"),
164
+ "iso8601.time": Style(color="magenta"),
165
+ "iso8601.timezone": Style(color="yellow"),
166
+ }
167
+
168
+
169
+ if __name__ == "__main__": # pragma: no cover
170
+ import argparse
171
+ import io
172
+
173
+ from pip._vendor.rich.console import Console
174
+ from pip._vendor.rich.table import Table
175
+ from pip._vendor.rich.text import Text
176
+
177
+ parser = argparse.ArgumentParser()
178
+ parser.add_argument("--html", action="store_true", help="Export as HTML table")
179
+ args = parser.parse_args()
180
+ html: bool = args.html
181
+ console = Console(record=True, width=70, file=io.StringIO()) if html else Console()
182
+
183
+ table = Table("Name", "Styling")
184
+
185
+ for style_name, style in DEFAULT_STYLES.items():
186
+ table.add_row(Text(style_name, style=style), str(style))
187
+
188
+ console.print(table)
189
+ if html:
190
+ print(console.export_html(inline_styles=True))
.venv/Lib/site-packages/pip/_vendor/rich/diagnose.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import platform
3
+
4
+ from pip._vendor.rich import inspect
5
+ from pip._vendor.rich.console import Console, get_windows_console_features
6
+ from pip._vendor.rich.panel import Panel
7
+ from pip._vendor.rich.pretty import Pretty
8
+
9
+
10
+ def report() -> None: # pragma: no cover
11
+ """Print a report to the terminal with debugging information"""
12
+ console = Console()
13
+ inspect(console)
14
+ features = get_windows_console_features()
15
+ inspect(features)
16
+
17
+ env_names = (
18
+ "TERM",
19
+ "COLORTERM",
20
+ "CLICOLOR",
21
+ "NO_COLOR",
22
+ "TERM_PROGRAM",
23
+ "COLUMNS",
24
+ "LINES",
25
+ "JUPYTER_COLUMNS",
26
+ "JUPYTER_LINES",
27
+ "JPY_PARENT_PID",
28
+ "VSCODE_VERBOSE_LOGGING",
29
+ )
30
+ env = {name: os.getenv(name) for name in env_names}
31
+ console.print(Panel.fit((Pretty(env)), title="[b]Environment Variables"))
32
+
33
+ console.print(f'platform="{platform.system()}"')
34
+
35
+
36
+ if __name__ == "__main__": # pragma: no cover
37
+ report()
.venv/Lib/site-packages/pip/_vendor/rich/emoji.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from typing import TYPE_CHECKING, Optional, Union
3
+
4
+ from .jupyter import JupyterMixin
5
+ from .segment import Segment
6
+ from .style import Style
7
+ from ._emoji_codes import EMOJI
8
+ from ._emoji_replace import _emoji_replace
9
+
10
+ if sys.version_info >= (3, 8):
11
+ from typing import Literal
12
+ else:
13
+ from pip._vendor.typing_extensions import Literal # pragma: no cover
14
+
15
+
16
+ if TYPE_CHECKING:
17
+ from .console import Console, ConsoleOptions, RenderResult
18
+
19
+
20
+ EmojiVariant = Literal["emoji", "text"]
21
+
22
+
23
+ class NoEmoji(Exception):
24
+ """No emoji by that name."""
25
+
26
+
27
+ class Emoji(JupyterMixin):
28
+ __slots__ = ["name", "style", "_char", "variant"]
29
+
30
+ VARIANTS = {"text": "\uFE0E", "emoji": "\uFE0F"}
31
+
32
+ def __init__(
33
+ self,
34
+ name: str,
35
+ style: Union[str, Style] = "none",
36
+ variant: Optional[EmojiVariant] = None,
37
+ ) -> None:
38
+ """A single emoji character.
39
+
40
+ Args:
41
+ name (str): Name of emoji.
42
+ style (Union[str, Style], optional): Optional style. Defaults to None.
43
+
44
+ Raises:
45
+ NoEmoji: If the emoji doesn't exist.
46
+ """
47
+ self.name = name
48
+ self.style = style
49
+ self.variant = variant
50
+ try:
51
+ self._char = EMOJI[name]
52
+ except KeyError:
53
+ raise NoEmoji(f"No emoji called {name!r}")
54
+ if variant is not None:
55
+ self._char += self.VARIANTS.get(variant, "")
56
+
57
+ @classmethod
58
+ def replace(cls, text: str) -> str:
59
+ """Replace emoji markup with corresponding unicode characters.
60
+
61
+ Args:
62
+ text (str): A string with emojis codes, e.g. "Hello :smiley:!"
63
+
64
+ Returns:
65
+ str: A string with emoji codes replaces with actual emoji.
66
+ """
67
+ return _emoji_replace(text)
68
+
69
+ def __repr__(self) -> str:
70
+ return f"<emoji {self.name!r}>"
71
+
72
+ def __str__(self) -> str:
73
+ return self._char
74
+
75
+ def __rich_console__(
76
+ self, console: "Console", options: "ConsoleOptions"
77
+ ) -> "RenderResult":
78
+ yield Segment(self._char, console.get_style(self.style))
79
+
80
+
81
+ if __name__ == "__main__": # pragma: no cover
82
+ import sys
83
+
84
+ from pip._vendor.rich.columns import Columns
85
+ from pip._vendor.rich.console import Console
86
+
87
+ console = Console(record=True)
88
+
89
+ columns = Columns(
90
+ (f":{name}: {name}" for name in sorted(EMOJI.keys()) if "\u200D" not in name),
91
+ column_first=True,
92
+ )
93
+
94
+ console.print(columns)
95
+ if len(sys.argv) > 1:
96
+ console.save_html(sys.argv[1])
.venv/Lib/site-packages/pip/_vendor/rich/errors.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class ConsoleError(Exception):
2
+ """An error in console operation."""
3
+
4
+
5
+ class StyleError(Exception):
6
+ """An error in styles."""
7
+
8
+
9
+ class StyleSyntaxError(ConsoleError):
10
+ """Style was badly formatted."""
11
+
12
+
13
+ class MissingStyle(StyleError):
14
+ """No such style."""
15
+
16
+
17
+ class StyleStackError(ConsoleError):
18
+ """Style stack is invalid."""
19
+
20
+
21
+ class NotRenderableError(ConsoleError):
22
+ """Object is not renderable."""
23
+
24
+
25
+ class MarkupError(ConsoleError):
26
+ """Markup was badly formatted."""
27
+
28
+
29
+ class LiveError(ConsoleError):
30
+ """Error related to Live display."""
31
+
32
+
33
+ class NoAltScreen(ConsoleError):
34
+ """Alt screen mode was required."""
.venv/Lib/site-packages/pip/_vendor/rich/file_proxy.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ from typing import IO, TYPE_CHECKING, Any, List
3
+
4
+ from .ansi import AnsiDecoder
5
+ from .text import Text
6
+
7
+ if TYPE_CHECKING:
8
+ from .console import Console
9
+
10
+
11
+ class FileProxy(io.TextIOBase):
12
+ """Wraps a file (e.g. sys.stdout) and redirects writes to a console."""
13
+
14
+ def __init__(self, console: "Console", file: IO[str]) -> None:
15
+ self.__console = console
16
+ self.__file = file
17
+ self.__buffer: List[str] = []
18
+ self.__ansi_decoder = AnsiDecoder()
19
+
20
+ @property
21
+ def rich_proxied_file(self) -> IO[str]:
22
+ """Get proxied file."""
23
+ return self.__file
24
+
25
+ def __getattr__(self, name: str) -> Any:
26
+ return getattr(self.__file, name)
27
+
28
+ def write(self, text: str) -> int:
29
+ if not isinstance(text, str):
30
+ raise TypeError(f"write() argument must be str, not {type(text).__name__}")
31
+ buffer = self.__buffer
32
+ lines: List[str] = []
33
+ while text:
34
+ line, new_line, text = text.partition("\n")
35
+ if new_line:
36
+ lines.append("".join(buffer) + line)
37
+ buffer.clear()
38
+ else:
39
+ buffer.append(line)
40
+ break
41
+ if lines:
42
+ console = self.__console
43
+ with console:
44
+ output = Text("\n").join(
45
+ self.__ansi_decoder.decode_line(line) for line in lines
46
+ )
47
+ console.print(output)
48
+ return len(text)
49
+
50
+ def flush(self) -> None:
51
+ output = "".join(self.__buffer)
52
+ if output:
53
+ self.__console.print(output)
54
+ del self.__buffer[:]
55
+
56
+ def fileno(self) -> int:
57
+ return self.__file.fileno()
.venv/Lib/site-packages/pip/_vendor/rich/filesize.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ """Functions for reporting filesizes. Borrowed from https://github.com/PyFilesystem/pyfilesystem2
3
+
4
+ The functions declared in this module should cover the different
5
+ use cases needed to generate a string representation of a file size
6
+ using several different units. Since there are many standards regarding
7
+ file size units, three different functions have been implemented.
8
+
9
+ See Also:
10
+ * `Wikipedia: Binary prefix <https://en.wikipedia.org/wiki/Binary_prefix>`_
11
+
12
+ """
13
+
14
+ __all__ = ["decimal"]
15
+
16
+ from typing import Iterable, List, Optional, Tuple
17
+
18
+
19
+ def _to_str(
20
+ size: int,
21
+ suffixes: Iterable[str],
22
+ base: int,
23
+ *,
24
+ precision: Optional[int] = 1,
25
+ separator: Optional[str] = " ",
26
+ ) -> str:
27
+ if size == 1:
28
+ return "1 byte"
29
+ elif size < base:
30
+ return "{:,} bytes".format(size)
31
+
32
+ for i, suffix in enumerate(suffixes, 2): # noqa: B007
33
+ unit = base**i
34
+ if size < unit:
35
+ break
36
+ return "{:,.{precision}f}{separator}{}".format(
37
+ (base * size / unit),
38
+ suffix,
39
+ precision=precision,
40
+ separator=separator,
41
+ )
42
+
43
+
44
+ def pick_unit_and_suffix(size: int, suffixes: List[str], base: int) -> Tuple[int, str]:
45
+ """Pick a suffix and base for the given size."""
46
+ for i, suffix in enumerate(suffixes):
47
+ unit = base**i
48
+ if size < unit * base:
49
+ break
50
+ return unit, suffix
51
+
52
+
53
+ def decimal(
54
+ size: int,
55
+ *,
56
+ precision: Optional[int] = 1,
57
+ separator: Optional[str] = " ",
58
+ ) -> str:
59
+ """Convert a filesize in to a string (powers of 1000, SI prefixes).
60
+
61
+ In this convention, ``1000 B = 1 kB``.
62
+
63
+ This is typically the format used to advertise the storage
64
+ capacity of USB flash drives and the like (*256 MB* meaning
65
+ actually a storage capacity of more than *256 000 000 B*),
66
+ or used by **Mac OS X** since v10.6 to report file sizes.
67
+
68
+ Arguments:
69
+ int (size): A file size.
70
+ int (precision): The number of decimal places to include (default = 1).
71
+ str (separator): The string to separate the value from the units (default = " ").
72
+
73
+ Returns:
74
+ `str`: A string containing a abbreviated file size and units.
75
+
76
+ Example:
77
+ >>> filesize.decimal(30000)
78
+ '30.0 kB'
79
+ >>> filesize.decimal(30000, precision=2, separator="")
80
+ '30.00kB'
81
+
82
+ """
83
+ return _to_str(
84
+ size,
85
+ ("kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"),
86
+ 1000,
87
+ precision=precision,
88
+ separator=separator,
89
+ )
.venv/Lib/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)
.venv/Lib/site-packages/pip/_vendor/rich/json.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
107
+ import argparse
108
+ import sys
109
+
110
+ parser = argparse.ArgumentParser(description="Pretty print json")
111
+ parser.add_argument(
112
+ "path",
113
+ metavar="PATH",
114
+ help="path to file, or - for stdin",
115
+ )
116
+ parser.add_argument(
117
+ "-i",
118
+ "--indent",
119
+ metavar="SPACES",
120
+ type=int,
121
+ help="Number of spaces in an indent",
122
+ default=2,
123
+ )
124
+ args = parser.parse_args()
125
+
126
+ from pip._vendor.rich.console import Console
127
+
128
+ console = Console()
129
+ error_console = Console(stderr=True)
130
+
131
+ try:
132
+ if args.path == "-":
133
+ json_data = sys.stdin.read()
134
+ else:
135
+ json_data = Path(args.path).read_text()
136
+ except Exception as error:
137
+ error_console.print(f"Unable to read {args.path!r}; {error}")
138
+ sys.exit(-1)
139
+
140
+ console.print(JSON(json_data, indent=args.indent), soft_wrap=True)
.venv/Lib/site-packages/pip/_vendor/rich/jupyter.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Sequence
2
+
3
+ if TYPE_CHECKING:
4
+ from pip._vendor.rich.console import ConsoleRenderable
5
+
6
+ from . import get_console
7
+ from .segment import Segment
8
+ from .terminal_theme import DEFAULT_TERMINAL_THEME
9
+
10
+ if TYPE_CHECKING:
11
+ from pip._vendor.rich.console import ConsoleRenderable
12
+
13
+ JUPYTER_HTML_FORMAT = """\
14
+ <pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace">{code}</pre>
15
+ """
16
+
17
+
18
+ class JupyterRenderable:
19
+ """A shim to write html to Jupyter notebook."""
20
+
21
+ def __init__(self, html: str, text: str) -> None:
22
+ self.html = html
23
+ self.text = text
24
+
25
+ def _repr_mimebundle_(
26
+ self, include: Sequence[str], exclude: Sequence[str], **kwargs: Any
27
+ ) -> Dict[str, str]:
28
+ data = {"text/plain": self.text, "text/html": self.html}
29
+ if include:
30
+ data = {k: v for (k, v) in data.items() if k in include}
31
+ if exclude:
32
+ data = {k: v for (k, v) in data.items() if k not in exclude}
33
+ return data
34
+
35
+
36
+ class JupyterMixin:
37
+ """Add to an Rich renderable to make it render in Jupyter notebook."""
38
+
39
+ __slots__ = ()
40
+
41
+ def _repr_mimebundle_(
42
+ self: "ConsoleRenderable",
43
+ include: Sequence[str],
44
+ exclude: Sequence[str],
45
+ **kwargs: Any,
46
+ ) -> Dict[str, str]:
47
+ console = get_console()
48
+ segments = list(console.render(self, console.options))
49
+ html = _render_segments(segments)
50
+ text = console._render_buffer(segments)
51
+ data = {"text/plain": text, "text/html": html}
52
+ if include:
53
+ data = {k: v for (k, v) in data.items() if k in include}
54
+ if exclude:
55
+ data = {k: v for (k, v) in data.items() if k not in exclude}
56
+ return data
57
+
58
+
59
+ def _render_segments(segments: Iterable[Segment]) -> str:
60
+ def escape(text: str) -> str:
61
+ """Escape html."""
62
+ return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
63
+
64
+ fragments: List[str] = []
65
+ append_fragment = fragments.append
66
+ theme = DEFAULT_TERMINAL_THEME
67
+ for text, style, control in Segment.simplify(segments):
68
+ if control:
69
+ continue
70
+ text = escape(text)
71
+ if style:
72
+ rule = style.get_html_style(theme)
73
+ text = f'<span style="{rule}">{text}</span>' if rule else text
74
+ if style.link:
75
+ text = f'<a href="{style.link}" target="_blank">{text}</a>'
76
+ append_fragment(text)
77
+
78
+ code = "".join(fragments)
79
+ html = JUPYTER_HTML_FORMAT.format(code=code)
80
+
81
+ return html
82
+
83
+
84
+ def display(segments: Iterable[Segment], text: str) -> None:
85
+ """Render segments to Jupyter."""
86
+ html = _render_segments(segments)
87
+ jupyter_renderable = JupyterRenderable(html, text)
88
+ try:
89
+ from IPython.display import display as ipython_display
90
+
91
+ ipython_display(jupyter_renderable)
92
+ except ModuleNotFoundError:
93
+ # Handle the case where the Console has force_jupyter=True,
94
+ # but IPython is not installed.
95
+ pass
96
+
97
+
98
+ def print(*args: Any, **kwargs: Any) -> None:
99
+ """Proxy for Console print."""
100
+ console = get_console()
101
+ return console.print(*args, **kwargs)
.venv/Lib/site-packages/pip/_vendor/rich/layout.py ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import ABC, abstractmethod
2
+ from itertools import islice
3
+ from operator import itemgetter
4
+ from threading import RLock
5
+ from typing import (
6
+ TYPE_CHECKING,
7
+ Dict,
8
+ Iterable,
9
+ List,
10
+ NamedTuple,
11
+ Optional,
12
+ Sequence,
13
+ Tuple,
14
+ Union,
15
+ )
16
+
17
+ from ._ratio import ratio_resolve
18
+ from .align import Align
19
+ from .console import Console, ConsoleOptions, RenderableType, RenderResult
20
+ from .highlighter import ReprHighlighter
21
+ from .panel import Panel
22
+ from .pretty import Pretty
23
+ from .region import Region
24
+ from .repr import Result, rich_repr
25
+ from .segment import Segment
26
+ from .style import StyleType
27
+
28
+ if TYPE_CHECKING:
29
+ from pip._vendor.rich.tree import Tree
30
+
31
+
32
+ class LayoutRender(NamedTuple):
33
+ """An individual layout render."""
34
+
35
+ region: Region
36
+ render: List[List[Segment]]
37
+
38
+
39
+ RegionMap = Dict["Layout", Region]
40
+ RenderMap = Dict["Layout", LayoutRender]
41
+
42
+
43
+ class LayoutError(Exception):
44
+ """Layout related error."""
45
+
46
+
47
+ class NoSplitter(LayoutError):
48
+ """Requested splitter does not exist."""
49
+
50
+
51
+ class _Placeholder:
52
+ """An internal renderable used as a Layout placeholder."""
53
+
54
+ highlighter = ReprHighlighter()
55
+
56
+ def __init__(self, layout: "Layout", style: StyleType = "") -> None:
57
+ self.layout = layout
58
+ self.style = style
59
+
60
+ def __rich_console__(
61
+ self, console: Console, options: ConsoleOptions
62
+ ) -> RenderResult:
63
+ width = options.max_width
64
+ height = options.height or options.size.height
65
+ layout = self.layout
66
+ title = (
67
+ f"{layout.name!r} ({width} x {height})"
68
+ if layout.name
69
+ else f"({width} x {height})"
70
+ )
71
+ yield Panel(
72
+ Align.center(Pretty(layout), vertical="middle"),
73
+ style=self.style,
74
+ title=self.highlighter(title),
75
+ border_style="blue",
76
+ height=height,
77
+ )
78
+
79
+
80
+ class Splitter(ABC):
81
+ """Base class for a splitter."""
82
+
83
+ name: str = ""
84
+
85
+ @abstractmethod
86
+ def get_tree_icon(self) -> str:
87
+ """Get the icon (emoji) used in layout.tree"""
88
+
89
+ @abstractmethod
90
+ def divide(
91
+ self, children: Sequence["Layout"], region: Region
92
+ ) -> Iterable[Tuple["Layout", Region]]:
93
+ """Divide a region amongst several child layouts.
94
+
95
+ Args:
96
+ children (Sequence(Layout)): A number of child layouts.
97
+ region (Region): A rectangular region to divide.
98
+ """
99
+
100
+
101
+ class RowSplitter(Splitter):
102
+ """Split a layout region in to rows."""
103
+
104
+ name = "row"
105
+
106
+ def get_tree_icon(self) -> str:
107
+ return "[layout.tree.row]⬌"
108
+
109
+ def divide(
110
+ self, children: Sequence["Layout"], region: Region
111
+ ) -> Iterable[Tuple["Layout", Region]]:
112
+ x, y, width, height = region
113
+ render_widths = ratio_resolve(width, children)
114
+ offset = 0
115
+ _Region = Region
116
+ for child, child_width in zip(children, render_widths):
117
+ yield child, _Region(x + offset, y, child_width, height)
118
+ offset += child_width
119
+
120
+
121
+ class ColumnSplitter(Splitter):
122
+ """Split a layout region in to columns."""
123
+
124
+ name = "column"
125
+
126
+ def get_tree_icon(self) -> str:
127
+ return "[layout.tree.column]⬍"
128
+
129
+ def divide(
130
+ self, children: Sequence["Layout"], region: Region
131
+ ) -> Iterable[Tuple["Layout", Region]]:
132
+ x, y, width, height = region
133
+ render_heights = ratio_resolve(height, children)
134
+ offset = 0
135
+ _Region = Region
136
+ for child, child_height in zip(children, render_heights):
137
+ yield child, _Region(x, y + offset, width, child_height)
138
+ offset += child_height
139
+
140
+
141
+ @rich_repr
142
+ class Layout:
143
+ """A renderable to divide a fixed height in to rows or columns.
144
+
145
+ Args:
146
+ renderable (RenderableType, optional): Renderable content, or None for placeholder. Defaults to None.
147
+ name (str, optional): Optional identifier for Layout. Defaults to None.
148
+ size (int, optional): Optional fixed size of layout. Defaults to None.
149
+ minimum_size (int, optional): Minimum size of layout. Defaults to 1.
150
+ ratio (int, optional): Optional ratio for flexible layout. Defaults to 1.
151
+ visible (bool, optional): Visibility of layout. Defaults to True.
152
+ """
153
+
154
+ splitters = {"row": RowSplitter, "column": ColumnSplitter}
155
+
156
+ def __init__(
157
+ self,
158
+ renderable: Optional[RenderableType] = None,
159
+ *,
160
+ name: Optional[str] = None,
161
+ size: Optional[int] = None,
162
+ minimum_size: int = 1,
163
+ ratio: int = 1,
164
+ visible: bool = True,
165
+ ) -> None:
166
+ self._renderable = renderable or _Placeholder(self)
167
+ self.size = size
168
+ self.minimum_size = minimum_size
169
+ self.ratio = ratio
170
+ self.name = name
171
+ self.visible = visible
172
+ self.splitter: Splitter = self.splitters["column"]()
173
+ self._children: List[Layout] = []
174
+ self._render_map: RenderMap = {}
175
+ self._lock = RLock()
176
+
177
+ def __rich_repr__(self) -> Result:
178
+ yield "name", self.name, None
179
+ yield "size", self.size, None
180
+ yield "minimum_size", self.minimum_size, 1
181
+ yield "ratio", self.ratio, 1
182
+
183
+ @property
184
+ def renderable(self) -> RenderableType:
185
+ """Layout renderable."""
186
+ return self if self._children else self._renderable
187
+
188
+ @property
189
+ def children(self) -> List["Layout"]:
190
+ """Gets (visible) layout children."""
191
+ return [child for child in self._children if child.visible]
192
+
193
+ @property
194
+ def map(self) -> RenderMap:
195
+ """Get a map of the last render."""
196
+ return self._render_map
197
+
198
+ def get(self, name: str) -> Optional["Layout"]:
199
+ """Get a named layout, or None if it doesn't exist.
200
+
201
+ Args:
202
+ name (str): Name of layout.
203
+
204
+ Returns:
205
+ Optional[Layout]: Layout instance or None if no layout was found.
206
+ """
207
+ if self.name == name:
208
+ return self
209
+ else:
210
+ for child in self._children:
211
+ named_layout = child.get(name)
212
+ if named_layout is not None:
213
+ return named_layout
214
+ return None
215
+
216
+ def __getitem__(self, name: str) -> "Layout":
217
+ layout = self.get(name)
218
+ if layout is None:
219
+ raise KeyError(f"No layout with name {name!r}")
220
+ return layout
221
+
222
+ @property
223
+ def tree(self) -> "Tree":
224
+ """Get a tree renderable to show layout structure."""
225
+ from pip._vendor.rich.styled import Styled
226
+ from pip._vendor.rich.table import Table
227
+ from pip._vendor.rich.tree import Tree
228
+
229
+ def summary(layout: "Layout") -> Table:
230
+
231
+ icon = layout.splitter.get_tree_icon()
232
+
233
+ table = Table.grid(padding=(0, 1, 0, 0))
234
+
235
+ text: RenderableType = (
236
+ Pretty(layout) if layout.visible else Styled(Pretty(layout), "dim")
237
+ )
238
+ table.add_row(icon, text)
239
+ _summary = table
240
+ return _summary
241
+
242
+ layout = self
243
+ tree = Tree(
244
+ summary(layout),
245
+ guide_style=f"layout.tree.{layout.splitter.name}",
246
+ highlight=True,
247
+ )
248
+
249
+ def recurse(tree: "Tree", layout: "Layout") -> None:
250
+ for child in layout._children:
251
+ recurse(
252
+ tree.add(
253
+ summary(child),
254
+ guide_style=f"layout.tree.{child.splitter.name}",
255
+ ),
256
+ child,
257
+ )
258
+
259
+ recurse(tree, self)
260
+ return tree
261
+
262
+ def split(
263
+ self,
264
+ *layouts: Union["Layout", RenderableType],
265
+ splitter: Union[Splitter, str] = "column",
266
+ ) -> None:
267
+ """Split the layout in to multiple sub-layouts.
268
+
269
+ Args:
270
+ *layouts (Layout): Positional arguments should be (sub) Layout instances.
271
+ splitter (Union[Splitter, str]): Splitter instance or name of splitter.
272
+ """
273
+ _layouts = [
274
+ layout if isinstance(layout, Layout) else Layout(layout)
275
+ for layout in layouts
276
+ ]
277
+ try:
278
+ self.splitter = (
279
+ splitter
280
+ if isinstance(splitter, Splitter)
281
+ else self.splitters[splitter]()
282
+ )
283
+ except KeyError:
284
+ raise NoSplitter(f"No splitter called {splitter!r}")
285
+ self._children[:] = _layouts
286
+
287
+ def add_split(self, *layouts: Union["Layout", RenderableType]) -> None:
288
+ """Add a new layout(s) to existing split.
289
+
290
+ Args:
291
+ *layouts (Union[Layout, RenderableType]): Positional arguments should be renderables or (sub) Layout instances.
292
+
293
+ """
294
+ _layouts = (
295
+ layout if isinstance(layout, Layout) else Layout(layout)
296
+ for layout in layouts
297
+ )
298
+ self._children.extend(_layouts)
299
+
300
+ def split_row(self, *layouts: Union["Layout", RenderableType]) -> None:
301
+ """Split the layout in to a row (layouts side by side).
302
+
303
+ Args:
304
+ *layouts (Layout): Positional arguments should be (sub) Layout instances.
305
+ """
306
+ self.split(*layouts, splitter="row")
307
+
308
+ def split_column(self, *layouts: Union["Layout", RenderableType]) -> None:
309
+ """Split the layout in to a column (layouts stacked on top of each other).
310
+
311
+ Args:
312
+ *layouts (Layout): Positional arguments should be (sub) Layout instances.
313
+ """
314
+ self.split(*layouts, splitter="column")
315
+
316
+ def unsplit(self) -> None:
317
+ """Reset splits to initial state."""
318
+ del self._children[:]
319
+
320
+ def update(self, renderable: RenderableType) -> None:
321
+ """Update renderable.
322
+
323
+ Args:
324
+ renderable (RenderableType): New renderable object.
325
+ """
326
+ with self._lock:
327
+ self._renderable = renderable
328
+
329
+ def refresh_screen(self, console: "Console", layout_name: str) -> None:
330
+ """Refresh a sub-layout.
331
+
332
+ Args:
333
+ console (Console): Console instance where Layout is to be rendered.
334
+ layout_name (str): Name of layout.
335
+ """
336
+ with self._lock:
337
+ layout = self[layout_name]
338
+ region, _lines = self._render_map[layout]
339
+ (x, y, width, height) = region
340
+ lines = console.render_lines(
341
+ layout, console.options.update_dimensions(width, height)
342
+ )
343
+ self._render_map[layout] = LayoutRender(region, lines)
344
+ console.update_screen_lines(lines, x, y)
345
+
346
+ def _make_region_map(self, width: int, height: int) -> RegionMap:
347
+ """Create a dict that maps layout on to Region."""
348
+ stack: List[Tuple[Layout, Region]] = [(self, Region(0, 0, width, height))]
349
+ push = stack.append
350
+ pop = stack.pop
351
+ layout_regions: List[Tuple[Layout, Region]] = []
352
+ append_layout_region = layout_regions.append
353
+ while stack:
354
+ append_layout_region(pop())
355
+ layout, region = layout_regions[-1]
356
+ children = layout.children
357
+ if children:
358
+ for child_and_region in layout.splitter.divide(children, region):
359
+ push(child_and_region)
360
+
361
+ region_map = {
362
+ layout: region
363
+ for layout, region in sorted(layout_regions, key=itemgetter(1))
364
+ }
365
+ return region_map
366
+
367
+ def render(self, console: Console, options: ConsoleOptions) -> RenderMap:
368
+ """Render the sub_layouts.
369
+
370
+ Args:
371
+ console (Console): Console instance.
372
+ options (ConsoleOptions): Console options.
373
+
374
+ Returns:
375
+ RenderMap: A dict that maps Layout on to a tuple of Region, lines
376
+ """
377
+ render_width = options.max_width
378
+ render_height = options.height or console.height
379
+ region_map = self._make_region_map(render_width, render_height)
380
+ layout_regions = [
381
+ (layout, region)
382
+ for layout, region in region_map.items()
383
+ if not layout.children
384
+ ]
385
+ render_map: Dict["Layout", "LayoutRender"] = {}
386
+ render_lines = console.render_lines
387
+ update_dimensions = options.update_dimensions
388
+
389
+ for layout, region in layout_regions:
390
+ lines = render_lines(
391
+ layout.renderable, update_dimensions(region.width, region.height)
392
+ )
393
+ render_map[layout] = LayoutRender(region, lines)
394
+ return render_map
395
+
396
+ def __rich_console__(
397
+ self, console: Console, options: ConsoleOptions
398
+ ) -> RenderResult:
399
+ with self._lock:
400
+ width = options.max_width or console.width
401
+ height = options.height or console.height
402
+ render_map = self.render(console, options.update_dimensions(width, height))
403
+ self._render_map = render_map
404
+ layout_lines: List[List[Segment]] = [[] for _ in range(height)]
405
+ _islice = islice
406
+ for (region, lines) in render_map.values():
407
+ _x, y, _layout_width, layout_height = region
408
+ for row, line in zip(
409
+ _islice(layout_lines, y, y + layout_height), lines
410
+ ):
411
+ row.extend(line)
412
+
413
+ new_line = Segment.line()
414
+ for layout_row in layout_lines:
415
+ yield from layout_row
416
+ yield new_line
417
+
418
+
419
+ if __name__ == "__main__":
420
+ from pip._vendor.rich.console import Console
421
+
422
+ console = Console()
423
+ layout = Layout()
424
+
425
+ layout.split_column(
426
+ Layout(name="header", size=3),
427
+ Layout(ratio=1, name="main"),
428
+ Layout(size=10, name="footer"),
429
+ )
430
+
431
+ layout["main"].split_row(Layout(name="side"), Layout(name="body", ratio=2))
432
+
433
+ layout["body"].split_row(Layout(name="content", ratio=2), Layout(name="s2"))
434
+
435
+ layout["s2"].split_column(
436
+ Layout(name="top"), Layout(name="middle"), Layout(name="bottom")
437
+ )
438
+
439
+ layout["side"].split_column(Layout(layout.tree, name="left1"), Layout(name="left2"))
440
+
441
+ layout["content"].update("foo")
442
+
443
+ console.print(layout)
.venv/Lib/site-packages/pip/_vendor/rich/live.py ADDED
@@ -0,0 +1,375 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from threading import Event, RLock, Thread
3
+ from types import TracebackType
4
+ from typing import IO, Any, Callable, List, Optional, TextIO, Type, cast
5
+
6
+ from . import get_console
7
+ from .console import Console, ConsoleRenderable, RenderableType, RenderHook
8
+ from .control import Control
9
+ from .file_proxy import FileProxy
10
+ from .jupyter import JupyterMixin
11
+ from .live_render import LiveRender, VerticalOverflowMethod
12
+ from .screen import Screen
13
+ from .text import Text
14
+
15
+
16
+ class _RefreshThread(Thread):
17
+ """A thread that calls refresh() at regular intervals."""
18
+
19
+ def __init__(self, live: "Live", refresh_per_second: float) -> None:
20
+ self.live = live
21
+ self.refresh_per_second = refresh_per_second
22
+ self.done = Event()
23
+ super().__init__(daemon=True)
24
+
25
+ def stop(self) -> None:
26
+ self.done.set()
27
+
28
+ def run(self) -> None:
29
+ while not self.done.wait(1 / self.refresh_per_second):
30
+ with self.live._lock:
31
+ if not self.done.is_set():
32
+ self.live.refresh()
33
+
34
+
35
+ class Live(JupyterMixin, RenderHook):
36
+ """Renders an auto-updating live display of any given renderable.
37
+
38
+ Args:
39
+ renderable (RenderableType, optional): The renderable to live display. Defaults to displaying nothing.
40
+ console (Console, optional): Optional Console instance. Default will an internal Console instance writing to stdout.
41
+ screen (bool, optional): Enable alternate screen mode. Defaults to False.
42
+ auto_refresh (bool, optional): Enable auto refresh. If disabled, you will need to call `refresh()` or `update()` with refresh flag. Defaults to True
43
+ refresh_per_second (float, optional): Number of times per second to refresh the live display. Defaults to 4.
44
+ transient (bool, optional): Clear the renderable on exit (has no effect when screen=True). Defaults to False.
45
+ redirect_stdout (bool, optional): Enable redirection of stdout, so ``print`` may be used. Defaults to True.
46
+ redirect_stderr (bool, optional): Enable redirection of stderr. Defaults to True.
47
+ vertical_overflow (VerticalOverflowMethod, optional): How to handle renderable when it is too tall for the console. Defaults to "ellipsis".
48
+ get_renderable (Callable[[], RenderableType], optional): Optional callable to get renderable. Defaults to None.
49
+ """
50
+
51
+ def __init__(
52
+ self,
53
+ renderable: Optional[RenderableType] = None,
54
+ *,
55
+ console: Optional[Console] = None,
56
+ screen: bool = False,
57
+ auto_refresh: bool = True,
58
+ refresh_per_second: float = 4,
59
+ transient: bool = False,
60
+ redirect_stdout: bool = True,
61
+ redirect_stderr: bool = True,
62
+ vertical_overflow: VerticalOverflowMethod = "ellipsis",
63
+ get_renderable: Optional[Callable[[], RenderableType]] = None,
64
+ ) -> None:
65
+ assert refresh_per_second > 0, "refresh_per_second must be > 0"
66
+ self._renderable = renderable
67
+ self.console = console if console is not None else get_console()
68
+ self._screen = screen
69
+ self._alt_screen = False
70
+
71
+ self._redirect_stdout = redirect_stdout
72
+ self._redirect_stderr = redirect_stderr
73
+ self._restore_stdout: Optional[IO[str]] = None
74
+ self._restore_stderr: Optional[IO[str]] = None
75
+
76
+ self._lock = RLock()
77
+ self.ipy_widget: Optional[Any] = None
78
+ self.auto_refresh = auto_refresh
79
+ self._started: bool = False
80
+ self.transient = True if screen else transient
81
+
82
+ self._refresh_thread: Optional[_RefreshThread] = None
83
+ self.refresh_per_second = refresh_per_second
84
+
85
+ self.vertical_overflow = vertical_overflow
86
+ self._get_renderable = get_renderable
87
+ self._live_render = LiveRender(
88
+ self.get_renderable(), vertical_overflow=vertical_overflow
89
+ )
90
+
91
+ @property
92
+ def is_started(self) -> bool:
93
+ """Check if live display has been started."""
94
+ return self._started
95
+
96
+ def get_renderable(self) -> RenderableType:
97
+ renderable = (
98
+ self._get_renderable()
99
+ if self._get_renderable is not None
100
+ else self._renderable
101
+ )
102
+ return renderable or ""
103
+
104
+ def start(self, refresh: bool = False) -> None:
105
+ """Start live rendering display.
106
+
107
+ Args:
108
+ refresh (bool, optional): Also refresh. Defaults to False.
109
+ """
110
+ with self._lock:
111
+ if self._started:
112
+ return
113
+ self.console.set_live(self)
114
+ self._started = True
115
+ if self._screen:
116
+ self._alt_screen = self.console.set_alt_screen(True)
117
+ self.console.show_cursor(False)
118
+ self._enable_redirect_io()
119
+ self.console.push_render_hook(self)
120
+ if refresh:
121
+ try:
122
+ self.refresh()
123
+ except Exception:
124
+ # If refresh fails, we want to stop the redirection of sys.stderr,
125
+ # so the error stacktrace is properly displayed in the terminal.
126
+ # (or, if the code that calls Rich captures the exception and wants to display something,
127
+ # let this be displayed in the terminal).
128
+ self.stop()
129
+ raise
130
+ if self.auto_refresh:
131
+ self._refresh_thread = _RefreshThread(self, self.refresh_per_second)
132
+ self._refresh_thread.start()
133
+
134
+ def stop(self) -> None:
135
+ """Stop live rendering display."""
136
+ with self._lock:
137
+ if not self._started:
138
+ return
139
+ self.console.clear_live()
140
+ self._started = False
141
+
142
+ if self.auto_refresh and self._refresh_thread is not None:
143
+ self._refresh_thread.stop()
144
+ self._refresh_thread = None
145
+ # allow it to fully render on the last even if overflow
146
+ self.vertical_overflow = "visible"
147
+ with self.console:
148
+ try:
149
+ if not self._alt_screen and not self.console.is_jupyter:
150
+ self.refresh()
151
+ finally:
152
+ self._disable_redirect_io()
153
+ self.console.pop_render_hook()
154
+ if not self._alt_screen and self.console.is_terminal:
155
+ self.console.line()
156
+ self.console.show_cursor(True)
157
+ if self._alt_screen:
158
+ self.console.set_alt_screen(False)
159
+
160
+ if self.transient and not self._alt_screen:
161
+ self.console.control(self._live_render.restore_cursor())
162
+ if self.ipy_widget is not None and self.transient:
163
+ self.ipy_widget.close() # pragma: no cover
164
+
165
+ def __enter__(self) -> "Live":
166
+ self.start(refresh=self._renderable is not None)
167
+ return self
168
+
169
+ def __exit__(
170
+ self,
171
+ exc_type: Optional[Type[BaseException]],
172
+ exc_val: Optional[BaseException],
173
+ exc_tb: Optional[TracebackType],
174
+ ) -> None:
175
+ self.stop()
176
+
177
+ def _enable_redirect_io(self) -> None:
178
+ """Enable redirecting of stdout / stderr."""
179
+ if self.console.is_terminal or self.console.is_jupyter:
180
+ if self._redirect_stdout and not isinstance(sys.stdout, FileProxy):
181
+ self._restore_stdout = sys.stdout
182
+ sys.stdout = cast("TextIO", FileProxy(self.console, sys.stdout))
183
+ if self._redirect_stderr and not isinstance(sys.stderr, FileProxy):
184
+ self._restore_stderr = sys.stderr
185
+ sys.stderr = cast("TextIO", FileProxy(self.console, sys.stderr))
186
+
187
+ def _disable_redirect_io(self) -> None:
188
+ """Disable redirecting of stdout / stderr."""
189
+ if self._restore_stdout:
190
+ sys.stdout = cast("TextIO", self._restore_stdout)
191
+ self._restore_stdout = None
192
+ if self._restore_stderr:
193
+ sys.stderr = cast("TextIO", self._restore_stderr)
194
+ self._restore_stderr = None
195
+
196
+ @property
197
+ def renderable(self) -> RenderableType:
198
+ """Get the renderable that is being displayed
199
+
200
+ Returns:
201
+ RenderableType: Displayed renderable.
202
+ """
203
+ renderable = self.get_renderable()
204
+ return Screen(renderable) if self._alt_screen else renderable
205
+
206
+ def update(self, renderable: RenderableType, *, refresh: bool = False) -> None:
207
+ """Update the renderable that is being displayed
208
+
209
+ Args:
210
+ renderable (RenderableType): New renderable to use.
211
+ refresh (bool, optional): Refresh the display. Defaults to False.
212
+ """
213
+ if isinstance(renderable, str):
214
+ renderable = self.console.render_str(renderable)
215
+ with self._lock:
216
+ self._renderable = renderable
217
+ if refresh:
218
+ self.refresh()
219
+
220
+ def refresh(self) -> None:
221
+ """Update the display of the Live Render."""
222
+ with self._lock:
223
+ self._live_render.set_renderable(self.renderable)
224
+ if self.console.is_jupyter: # pragma: no cover
225
+ try:
226
+ from IPython.display import display
227
+ from ipywidgets import Output
228
+ except ImportError:
229
+ import warnings
230
+
231
+ warnings.warn('install "ipywidgets" for Jupyter support')
232
+ else:
233
+ if self.ipy_widget is None:
234
+ self.ipy_widget = Output()
235
+ display(self.ipy_widget)
236
+
237
+ with self.ipy_widget:
238
+ self.ipy_widget.clear_output(wait=True)
239
+ self.console.print(self._live_render.renderable)
240
+ elif self.console.is_terminal and not self.console.is_dumb_terminal:
241
+ with self.console:
242
+ self.console.print(Control())
243
+ elif (
244
+ not self._started and not self.transient
245
+ ): # if it is finished allow files or dumb-terminals to see final result
246
+ with self.console:
247
+ self.console.print(Control())
248
+
249
+ def process_renderables(
250
+ self, renderables: List[ConsoleRenderable]
251
+ ) -> List[ConsoleRenderable]:
252
+ """Process renderables to restore cursor and display progress."""
253
+ self._live_render.vertical_overflow = self.vertical_overflow
254
+ if self.console.is_interactive:
255
+ # lock needs acquiring as user can modify live_render renderable at any time unlike in Progress.
256
+ with self._lock:
257
+ reset = (
258
+ Control.home()
259
+ if self._alt_screen
260
+ else self._live_render.position_cursor()
261
+ )
262
+ renderables = [reset, *renderables, self._live_render]
263
+ elif (
264
+ not self._started and not self.transient
265
+ ): # if it is finished render the final output for files or dumb_terminals
266
+ renderables = [*renderables, self._live_render]
267
+
268
+ return renderables
269
+
270
+
271
+ if __name__ == "__main__": # pragma: no cover
272
+ import random
273
+ import time
274
+ from itertools import cycle
275
+ from typing import Dict, List, Tuple
276
+
277
+ from .align import Align
278
+ from .console import Console
279
+ from .live import Live as Live
280
+ from .panel import Panel
281
+ from .rule import Rule
282
+ from .syntax import Syntax
283
+ from .table import Table
284
+
285
+ console = Console()
286
+
287
+ syntax = Syntax(
288
+ '''def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
289
+ """Iterate and generate a tuple with a flag for last value."""
290
+ iter_values = iter(values)
291
+ try:
292
+ previous_value = next(iter_values)
293
+ except StopIteration:
294
+ return
295
+ for value in iter_values:
296
+ yield False, previous_value
297
+ previous_value = value
298
+ yield True, previous_value''',
299
+ "python",
300
+ line_numbers=True,
301
+ )
302
+
303
+ table = Table("foo", "bar", "baz")
304
+ table.add_row("1", "2", "3")
305
+
306
+ progress_renderables = [
307
+ "You can make the terminal shorter and taller to see the live table hide"
308
+ "Text may be printed while the progress bars are rendering.",
309
+ Panel("In fact, [i]any[/i] renderable will work"),
310
+ "Such as [magenta]tables[/]...",
311
+ table,
312
+ "Pretty printed structures...",
313
+ {"type": "example", "text": "Pretty printed"},
314
+ "Syntax...",
315
+ syntax,
316
+ Rule("Give it a try!"),
317
+ ]
318
+
319
+ examples = cycle(progress_renderables)
320
+
321
+ exchanges = [
322
+ "SGD",
323
+ "MYR",
324
+ "EUR",
325
+ "USD",
326
+ "AUD",
327
+ "JPY",
328
+ "CNH",
329
+ "HKD",
330
+ "CAD",
331
+ "INR",
332
+ "DKK",
333
+ "GBP",
334
+ "RUB",
335
+ "NZD",
336
+ "MXN",
337
+ "IDR",
338
+ "TWD",
339
+ "THB",
340
+ "VND",
341
+ ]
342
+ with Live(console=console) as live_table:
343
+ exchange_rate_dict: Dict[Tuple[str, str], float] = {}
344
+
345
+ for index in range(100):
346
+ select_exchange = exchanges[index % len(exchanges)]
347
+
348
+ for exchange in exchanges:
349
+ if exchange == select_exchange:
350
+ continue
351
+ time.sleep(0.4)
352
+ if random.randint(0, 10) < 1:
353
+ console.log(next(examples))
354
+ exchange_rate_dict[(select_exchange, exchange)] = 200 / (
355
+ (random.random() * 320) + 1
356
+ )
357
+ if len(exchange_rate_dict) > len(exchanges) - 1:
358
+ exchange_rate_dict.pop(list(exchange_rate_dict.keys())[0])
359
+ table = Table(title="Exchange Rates")
360
+
361
+ table.add_column("Source Currency")
362
+ table.add_column("Destination Currency")
363
+ table.add_column("Exchange Rate")
364
+
365
+ for ((source, dest), exchange_rate) in exchange_rate_dict.items():
366
+ table.add_row(
367
+ source,
368
+ dest,
369
+ Text(
370
+ f"{exchange_rate:.4f}",
371
+ style="red" if exchange_rate < 1.0 else "green",
372
+ ),
373
+ )
374
+
375
+ live_table.update(Align.center(table))
.venv/Lib/site-packages/pip/_vendor/rich/live_render.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from typing import Optional, Tuple
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
+ from .console import Console, ConsoleOptions, RenderableType, RenderResult
12
+ from .control import Control
13
+ from .segment import ControlType, Segment
14
+ from .style import StyleType
15
+ from .text import Text
16
+
17
+ VerticalOverflowMethod = Literal["crop", "ellipsis", "visible"]
18
+
19
+
20
+ class LiveRender:
21
+ """Creates a renderable that may be updated.
22
+
23
+ Args:
24
+ renderable (RenderableType): Any renderable object.
25
+ style (StyleType, optional): An optional style to apply to the renderable. Defaults to "".
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ renderable: RenderableType,
31
+ style: StyleType = "",
32
+ vertical_overflow: VerticalOverflowMethod = "ellipsis",
33
+ ) -> None:
34
+ self.renderable = renderable
35
+ self.style = style
36
+ self.vertical_overflow = vertical_overflow
37
+ self._shape: Optional[Tuple[int, int]] = None
38
+
39
+ def set_renderable(self, renderable: RenderableType) -> None:
40
+ """Set a new renderable.
41
+
42
+ Args:
43
+ renderable (RenderableType): Any renderable object, including str.
44
+ """
45
+ self.renderable = renderable
46
+
47
+ def position_cursor(self) -> Control:
48
+ """Get control codes to move cursor to beginning of live render.
49
+
50
+ Returns:
51
+ Control: A control instance that may be printed.
52
+ """
53
+ if self._shape is not None:
54
+ _, height = self._shape
55
+ return Control(
56
+ ControlType.CARRIAGE_RETURN,
57
+ (ControlType.ERASE_IN_LINE, 2),
58
+ *(
59
+ (
60
+ (ControlType.CURSOR_UP, 1),
61
+ (ControlType.ERASE_IN_LINE, 2),
62
+ )
63
+ * (height - 1)
64
+ )
65
+ )
66
+ return Control()
67
+
68
+ def restore_cursor(self) -> Control:
69
+ """Get control codes to clear the render and restore the cursor to its previous position.
70
+
71
+ Returns:
72
+ Control: A Control instance that may be printed.
73
+ """
74
+ if self._shape is not None:
75
+ _, height = self._shape
76
+ return Control(
77
+ ControlType.CARRIAGE_RETURN,
78
+ *((ControlType.CURSOR_UP, 1), (ControlType.ERASE_IN_LINE, 2)) * height
79
+ )
80
+ return Control()
81
+
82
+ def __rich_console__(
83
+ self, console: Console, options: ConsoleOptions
84
+ ) -> RenderResult:
85
+
86
+ renderable = self.renderable
87
+ style = console.get_style(self.style)
88
+ lines = console.render_lines(renderable, options, style=style, pad=False)
89
+ shape = Segment.get_shape(lines)
90
+
91
+ _, height = shape
92
+ if height > options.size.height:
93
+ if self.vertical_overflow == "crop":
94
+ lines = lines[: options.size.height]
95
+ shape = Segment.get_shape(lines)
96
+ elif self.vertical_overflow == "ellipsis":
97
+ lines = lines[: (options.size.height - 1)]
98
+ overflow_text = Text(
99
+ "...",
100
+ overflow="crop",
101
+ justify="center",
102
+ end="",
103
+ style="live.ellipsis",
104
+ )
105
+ lines.append(list(console.render(overflow_text)))
106
+ shape = Segment.get_shape(lines)
107
+ self._shape = shape
108
+
109
+ new_line = Segment.line()
110
+ for last, line in loop_last(lines):
111
+ yield from line
112
+ if not last:
113
+ yield new_line
.venv/Lib/site-packages/pip/_vendor/rich/logging.py ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from datetime import datetime
3
+ from logging import Handler, LogRecord
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+ from typing import ClassVar, Iterable, List, Optional, Type, Union
7
+
8
+ from pip._vendor.rich._null_file import NullFile
9
+
10
+ from . import get_console
11
+ from ._log_render import FormatTimeCallable, LogRender
12
+ from .console import Console, ConsoleRenderable
13
+ from .highlighter import Highlighter, ReprHighlighter
14
+ from .text import Text
15
+ from .traceback import Traceback
16
+
17
+
18
+ class RichHandler(Handler):
19
+ """A logging handler that renders output with Rich. The time / level / message and file are displayed in columns.
20
+ The level is color coded, and the message is syntax highlighted.
21
+
22
+ Note:
23
+ Be careful when enabling console markup in log messages if you have configured logging for libraries not
24
+ under your control. If a dependency writes messages containing square brackets, it may not produce the intended output.
25
+
26
+ Args:
27
+ level (Union[int, str], optional): Log level. Defaults to logging.NOTSET.
28
+ console (:class:`~rich.console.Console`, optional): Optional console instance to write logs.
29
+ Default will use a global console instance writing to stdout.
30
+ show_time (bool, optional): Show a column for the time. Defaults to True.
31
+ omit_repeated_times (bool, optional): Omit repetition of the same time. Defaults to True.
32
+ show_level (bool, optional): Show a column for the level. Defaults to True.
33
+ show_path (bool, optional): Show the path to the original log call. Defaults to True.
34
+ enable_link_path (bool, optional): Enable terminal link of path column to file. Defaults to True.
35
+ highlighter (Highlighter, optional): Highlighter to style log messages, or None to use ReprHighlighter. Defaults to None.
36
+ markup (bool, optional): Enable console markup in log messages. Defaults to False.
37
+ rich_tracebacks (bool, optional): Enable rich tracebacks with syntax highlighting and formatting. Defaults to False.
38
+ tracebacks_width (Optional[int], optional): Number of characters used to render tracebacks, or None for full width. Defaults to None.
39
+ tracebacks_extra_lines (int, optional): Additional lines of code to render tracebacks, or None for full width. Defaults to None.
40
+ tracebacks_theme (str, optional): Override pygments theme used in traceback.
41
+ tracebacks_word_wrap (bool, optional): Enable word wrapping of long tracebacks lines. Defaults to True.
42
+ tracebacks_show_locals (bool, optional): Enable display of locals in tracebacks. Defaults to False.
43
+ tracebacks_suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
44
+ locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
45
+ Defaults to 10.
46
+ locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
47
+ log_time_format (Union[str, TimeFormatterCallable], optional): If ``log_time`` is enabled, either string for strftime or callable that formats the time. Defaults to "[%x %X] ".
48
+ keywords (List[str], optional): List of words to highlight instead of ``RichHandler.KEYWORDS``.
49
+ """
50
+
51
+ KEYWORDS: ClassVar[Optional[List[str]]] = [
52
+ "GET",
53
+ "POST",
54
+ "HEAD",
55
+ "PUT",
56
+ "DELETE",
57
+ "OPTIONS",
58
+ "TRACE",
59
+ "PATCH",
60
+ ]
61
+ HIGHLIGHTER_CLASS: ClassVar[Type[Highlighter]] = ReprHighlighter
62
+
63
+ def __init__(
64
+ self,
65
+ level: Union[int, str] = logging.NOTSET,
66
+ console: Optional[Console] = None,
67
+ *,
68
+ show_time: bool = True,
69
+ omit_repeated_times: bool = True,
70
+ show_level: bool = True,
71
+ show_path: bool = True,
72
+ enable_link_path: bool = True,
73
+ highlighter: Optional[Highlighter] = None,
74
+ markup: bool = False,
75
+ rich_tracebacks: bool = False,
76
+ tracebacks_width: Optional[int] = None,
77
+ tracebacks_extra_lines: int = 3,
78
+ tracebacks_theme: Optional[str] = None,
79
+ tracebacks_word_wrap: bool = True,
80
+ tracebacks_show_locals: bool = False,
81
+ tracebacks_suppress: Iterable[Union[str, ModuleType]] = (),
82
+ locals_max_length: int = 10,
83
+ locals_max_string: int = 80,
84
+ log_time_format: Union[str, FormatTimeCallable] = "[%x %X]",
85
+ keywords: Optional[List[str]] = None,
86
+ ) -> None:
87
+ super().__init__(level=level)
88
+ self.console = console or get_console()
89
+ self.highlighter = highlighter or self.HIGHLIGHTER_CLASS()
90
+ self._log_render = LogRender(
91
+ show_time=show_time,
92
+ show_level=show_level,
93
+ show_path=show_path,
94
+ time_format=log_time_format,
95
+ omit_repeated_times=omit_repeated_times,
96
+ level_width=None,
97
+ )
98
+ self.enable_link_path = enable_link_path
99
+ self.markup = markup
100
+ self.rich_tracebacks = rich_tracebacks
101
+ self.tracebacks_width = tracebacks_width
102
+ self.tracebacks_extra_lines = tracebacks_extra_lines
103
+ self.tracebacks_theme = tracebacks_theme
104
+ self.tracebacks_word_wrap = tracebacks_word_wrap
105
+ self.tracebacks_show_locals = tracebacks_show_locals
106
+ self.tracebacks_suppress = tracebacks_suppress
107
+ self.locals_max_length = locals_max_length
108
+ self.locals_max_string = locals_max_string
109
+ self.keywords = keywords
110
+
111
+ def get_level_text(self, record: LogRecord) -> Text:
112
+ """Get the level name from the record.
113
+
114
+ Args:
115
+ record (LogRecord): LogRecord instance.
116
+
117
+ Returns:
118
+ Text: A tuple of the style and level name.
119
+ """
120
+ level_name = record.levelname
121
+ level_text = Text.styled(
122
+ level_name.ljust(8), f"logging.level.{level_name.lower()}"
123
+ )
124
+ return level_text
125
+
126
+ def emit(self, record: LogRecord) -> None:
127
+ """Invoked by logging."""
128
+ message = self.format(record)
129
+ traceback = None
130
+ if (
131
+ self.rich_tracebacks
132
+ and record.exc_info
133
+ and record.exc_info != (None, None, None)
134
+ ):
135
+ exc_type, exc_value, exc_traceback = record.exc_info
136
+ assert exc_type is not None
137
+ assert exc_value is not None
138
+ traceback = Traceback.from_exception(
139
+ exc_type,
140
+ exc_value,
141
+ exc_traceback,
142
+ width=self.tracebacks_width,
143
+ extra_lines=self.tracebacks_extra_lines,
144
+ theme=self.tracebacks_theme,
145
+ word_wrap=self.tracebacks_word_wrap,
146
+ show_locals=self.tracebacks_show_locals,
147
+ locals_max_length=self.locals_max_length,
148
+ locals_max_string=self.locals_max_string,
149
+ suppress=self.tracebacks_suppress,
150
+ )
151
+ message = record.getMessage()
152
+ if self.formatter:
153
+ record.message = record.getMessage()
154
+ formatter = self.formatter
155
+ if hasattr(formatter, "usesTime") and formatter.usesTime():
156
+ record.asctime = formatter.formatTime(record, formatter.datefmt)
157
+ message = formatter.formatMessage(record)
158
+
159
+ message_renderable = self.render_message(record, message)
160
+ log_renderable = self.render(
161
+ record=record, traceback=traceback, message_renderable=message_renderable
162
+ )
163
+ if isinstance(self.console.file, NullFile):
164
+ # Handles pythonw, where stdout/stderr are null, and we return NullFile
165
+ # instance from Console.file. In this case, we still want to make a log record
166
+ # even though we won't be writing anything to a file.
167
+ self.handleError(record)
168
+ else:
169
+ try:
170
+ self.console.print(log_renderable)
171
+ except Exception:
172
+ self.handleError(record)
173
+
174
+ def render_message(self, record: LogRecord, message: str) -> "ConsoleRenderable":
175
+ """Render message text in to Text.
176
+
177
+ Args:
178
+ record (LogRecord): logging Record.
179
+ message (str): String containing log message.
180
+
181
+ Returns:
182
+ ConsoleRenderable: Renderable to display log message.
183
+ """
184
+ use_markup = getattr(record, "markup", self.markup)
185
+ message_text = Text.from_markup(message) if use_markup else Text(message)
186
+
187
+ highlighter = getattr(record, "highlighter", self.highlighter)
188
+ if highlighter:
189
+ message_text = highlighter(message_text)
190
+
191
+ if self.keywords is None:
192
+ self.keywords = self.KEYWORDS
193
+
194
+ if self.keywords:
195
+ message_text.highlight_words(self.keywords, "logging.keyword")
196
+
197
+ return message_text
198
+
199
+ def render(
200
+ self,
201
+ *,
202
+ record: LogRecord,
203
+ traceback: Optional[Traceback],
204
+ message_renderable: "ConsoleRenderable",
205
+ ) -> "ConsoleRenderable":
206
+ """Render log for display.
207
+
208
+ Args:
209
+ record (LogRecord): logging Record.
210
+ traceback (Optional[Traceback]): Traceback instance or None for no Traceback.
211
+ message_renderable (ConsoleRenderable): Renderable (typically Text) containing log message contents.
212
+
213
+ Returns:
214
+ ConsoleRenderable: Renderable to display log.
215
+ """
216
+ path = Path(record.pathname).name
217
+ level = self.get_level_text(record)
218
+ time_format = None if self.formatter is None else self.formatter.datefmt
219
+ log_time = datetime.fromtimestamp(record.created)
220
+
221
+ log_renderable = self._log_render(
222
+ self.console,
223
+ [message_renderable] if not traceback else [message_renderable, traceback],
224
+ log_time=log_time,
225
+ time_format=time_format,
226
+ level=level,
227
+ path=path,
228
+ line_no=record.lineno,
229
+ link_path=record.pathname if self.enable_link_path else None,
230
+ )
231
+ return log_renderable
232
+
233
+
234
+ if __name__ == "__main__": # pragma: no cover
235
+ from time import sleep
236
+
237
+ FORMAT = "%(message)s"
238
+ # FORMAT = "%(asctime)-15s - %(levelname)s - %(message)s"
239
+ logging.basicConfig(
240
+ level="NOTSET",
241
+ format=FORMAT,
242
+ datefmt="[%X]",
243
+ handlers=[RichHandler(rich_tracebacks=True, tracebacks_show_locals=True)],
244
+ )
245
+ log = logging.getLogger("rich")
246
+
247
+ log.info("Server starting...")
248
+ log.info("Listening on http://127.0.0.1:8080")
249
+ sleep(1)
250
+
251
+ log.info("GET /index.html 200 1298")
252
+ log.info("GET /imgs/backgrounds/back1.jpg 200 54386")
253
+ log.info("GET /css/styles.css 200 54386")
254
+ log.warning("GET /favicon.ico 404 242")
255
+ sleep(1)
256
+
257
+ log.debug(
258
+ "JSONRPC request\n--> %r\n<-- %r",
259
+ {
260
+ "version": "1.1",
261
+ "method": "confirmFruitPurchase",
262
+ "params": [["apple", "orange", "mangoes", "pomelo"], 1.123],
263
+ "id": "194521489",
264
+ },
265
+ {"version": "1.1", "result": True, "error": None, "id": "194521489"},
266
+ )
267
+ log.debug(
268
+ "Loading configuration file /adasd/asdasd/qeqwe/qwrqwrqwr/sdgsdgsdg/werwerwer/dfgerert/ertertert/ertetert/werwerwer"
269
+ )
270
+ log.error("Unable to find 'pomelo' in database!")
271
+ log.info("POST /jsonrpc/ 200 65532")
272
+ log.info("POST /admin/ 401 42234")
273
+ log.warning("password was rejected for admin site.")
274
+
275
+ def divide() -> None:
276
+ number = 1
277
+ divisor = 0
278
+ foos = ["foo"] * 100
279
+ log.debug("in divide")
280
+ try:
281
+ number / divisor
282
+ except:
283
+ log.exception("An error of some kind occurred!")
284
+
285
+ divide()
286
+ sleep(1)
287
+ log.critical("Out of memory!")
288
+ log.info("Server exited with code=-1")
289
+ log.info("[bold]EXITING...[/bold]", extra=dict(markup=True))
.venv/Lib/site-packages/pip/_vendor/rich/markup.py ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from ast import literal_eval
3
+ from operator import attrgetter
4
+ from typing import Callable, Iterable, List, Match, NamedTuple, Optional, Tuple, Union
5
+
6
+ from ._emoji_replace import _emoji_replace
7
+ from .emoji import EmojiVariant
8
+ from .errors import MarkupError
9
+ from .style import Style
10
+ from .text import Span, Text
11
+
12
+ RE_TAGS = re.compile(
13
+ r"""((\\*)\[([a-z#/@][^[]*?)])""",
14
+ re.VERBOSE,
15
+ )
16
+
17
+ RE_HANDLER = re.compile(r"^([\w.]*?)(\(.*?\))?$")
18
+
19
+
20
+ class Tag(NamedTuple):
21
+ """A tag in console markup."""
22
+
23
+ name: str
24
+ """The tag name. e.g. 'bold'."""
25
+ parameters: Optional[str]
26
+ """Any additional parameters after the name."""
27
+
28
+ def __str__(self) -> str:
29
+ return (
30
+ self.name if self.parameters is None else f"{self.name} {self.parameters}"
31
+ )
32
+
33
+ @property
34
+ def markup(self) -> str:
35
+ """Get the string representation of this tag."""
36
+ return (
37
+ f"[{self.name}]"
38
+ if self.parameters is None
39
+ else f"[{self.name}={self.parameters}]"
40
+ )
41
+
42
+
43
+ _ReStringMatch = Match[str] # regex match object
44
+ _ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub
45
+ _EscapeSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re
46
+
47
+
48
+ def escape(
49
+ markup: str,
50
+ _escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#/@][^[]*?])").sub,
51
+ ) -> str:
52
+ """Escapes text so that it won't be interpreted as markup.
53
+
54
+ Args:
55
+ markup (str): Content to be inserted in to markup.
56
+
57
+ Returns:
58
+ str: Markup with square brackets escaped.
59
+ """
60
+
61
+ def escape_backslashes(match: Match[str]) -> str:
62
+ """Called by re.sub replace matches."""
63
+ backslashes, text = match.groups()
64
+ return f"{backslashes}{backslashes}\\{text}"
65
+
66
+ markup = _escape(escape_backslashes, markup)
67
+ return markup
68
+
69
+
70
+ def _parse(markup: str) -> Iterable[Tuple[int, Optional[str], Optional[Tag]]]:
71
+ """Parse markup in to an iterable of tuples of (position, text, tag).
72
+
73
+ Args:
74
+ markup (str): A string containing console markup
75
+
76
+ """
77
+ position = 0
78
+ _divmod = divmod
79
+ _Tag = Tag
80
+ for match in RE_TAGS.finditer(markup):
81
+ full_text, escapes, tag_text = match.groups()
82
+ start, end = match.span()
83
+ if start > position:
84
+ yield start, markup[position:start], None
85
+ if escapes:
86
+ backslashes, escaped = _divmod(len(escapes), 2)
87
+ if backslashes:
88
+ # Literal backslashes
89
+ yield start, "\\" * backslashes, None
90
+ start += backslashes * 2
91
+ if escaped:
92
+ # Escape of tag
93
+ yield start, full_text[len(escapes) :], None
94
+ position = end
95
+ continue
96
+ text, equals, parameters = tag_text.partition("=")
97
+ yield start, None, _Tag(text, parameters if equals else None)
98
+ position = end
99
+ if position < len(markup):
100
+ yield position, markup[position:], None
101
+
102
+
103
+ def render(
104
+ markup: str,
105
+ style: Union[str, Style] = "",
106
+ emoji: bool = True,
107
+ emoji_variant: Optional[EmojiVariant] = None,
108
+ ) -> Text:
109
+ """Render console markup in to a Text instance.
110
+
111
+ Args:
112
+ markup (str): A string containing console markup.
113
+ emoji (bool, optional): Also render emoji code. Defaults to True.
114
+
115
+ Raises:
116
+ MarkupError: If there is a syntax error in the markup.
117
+
118
+ Returns:
119
+ Text: A test instance.
120
+ """
121
+ emoji_replace = _emoji_replace
122
+ if "[" not in markup:
123
+ return Text(
124
+ emoji_replace(markup, default_variant=emoji_variant) if emoji else markup,
125
+ style=style,
126
+ )
127
+ text = Text(style=style)
128
+ append = text.append
129
+ normalize = Style.normalize
130
+
131
+ style_stack: List[Tuple[int, Tag]] = []
132
+ pop = style_stack.pop
133
+
134
+ spans: List[Span] = []
135
+ append_span = spans.append
136
+
137
+ _Span = Span
138
+ _Tag = Tag
139
+
140
+ def pop_style(style_name: str) -> Tuple[int, Tag]:
141
+ """Pop tag matching given style name."""
142
+ for index, (_, tag) in enumerate(reversed(style_stack), 1):
143
+ if tag.name == style_name:
144
+ return pop(-index)
145
+ raise KeyError(style_name)
146
+
147
+ for position, plain_text, tag in _parse(markup):
148
+ if plain_text is not None:
149
+ # Handle open brace escapes, where the brace is not part of a tag.
150
+ plain_text = plain_text.replace("\\[", "[")
151
+ append(emoji_replace(plain_text) if emoji else plain_text)
152
+ elif tag is not None:
153
+ if tag.name.startswith("/"): # Closing tag
154
+ style_name = tag.name[1:].strip()
155
+
156
+ if style_name: # explicit close
157
+ style_name = normalize(style_name)
158
+ try:
159
+ start, open_tag = pop_style(style_name)
160
+ except KeyError:
161
+ raise MarkupError(
162
+ f"closing tag '{tag.markup}' at position {position} doesn't match any open tag"
163
+ ) from None
164
+ else: # implicit close
165
+ try:
166
+ start, open_tag = pop()
167
+ except IndexError:
168
+ raise MarkupError(
169
+ f"closing tag '[/]' at position {position} has nothing to close"
170
+ ) from None
171
+
172
+ if open_tag.name.startswith("@"):
173
+ if open_tag.parameters:
174
+ handler_name = ""
175
+ parameters = open_tag.parameters.strip()
176
+ handler_match = RE_HANDLER.match(parameters)
177
+ if handler_match is not None:
178
+ handler_name, match_parameters = handler_match.groups()
179
+ parameters = (
180
+ "()" if match_parameters is None else match_parameters
181
+ )
182
+
183
+ try:
184
+ meta_params = literal_eval(parameters)
185
+ except SyntaxError as error:
186
+ raise MarkupError(
187
+ f"error parsing {parameters!r} in {open_tag.parameters!r}; {error.msg}"
188
+ )
189
+ except Exception as error:
190
+ raise MarkupError(
191
+ f"error parsing {open_tag.parameters!r}; {error}"
192
+ ) from None
193
+
194
+ if handler_name:
195
+ meta_params = (
196
+ handler_name,
197
+ meta_params
198
+ if isinstance(meta_params, tuple)
199
+ else (meta_params,),
200
+ )
201
+
202
+ else:
203
+ meta_params = ()
204
+
205
+ append_span(
206
+ _Span(
207
+ start, len(text), Style(meta={open_tag.name: meta_params})
208
+ )
209
+ )
210
+ else:
211
+ append_span(_Span(start, len(text), str(open_tag)))
212
+
213
+ else: # Opening tag
214
+ normalized_tag = _Tag(normalize(tag.name), tag.parameters)
215
+ style_stack.append((len(text), normalized_tag))
216
+
217
+ text_length = len(text)
218
+ while style_stack:
219
+ start, tag = style_stack.pop()
220
+ style = str(tag)
221
+ if style:
222
+ append_span(_Span(start, text_length, style))
223
+
224
+ text.spans = sorted(spans[::-1], key=attrgetter("start"))
225
+ return text
226
+
227
+
228
+ if __name__ == "__main__": # pragma: no cover
229
+
230
+ MARKUP = [
231
+ "[red]Hello World[/red]",
232
+ "[magenta]Hello [b]World[/b]",
233
+ "[bold]Bold[italic] bold and italic [/bold]italic[/italic]",
234
+ "Click [link=https://www.willmcgugan.com]here[/link] to visit my Blog",
235
+ ":warning-emoji: [bold red blink] DANGER![/]",
236
+ ]
237
+
238
+ from pip._vendor.rich import print
239
+ from pip._vendor.rich.table import Table
240
+
241
+ grid = Table("Markup", "Result", padding=(0, 1))
242
+
243
+ for markup in MARKUP:
244
+ grid.add_row(Text(markup), markup)
245
+
246
+ print(grid)
.venv/Lib/site-packages/pip/_vendor/rich/measure.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from operator import itemgetter
2
+ from typing import TYPE_CHECKING, Callable, NamedTuple, Optional, Sequence
3
+
4
+ from . import errors
5
+ from .protocol import is_renderable, rich_cast
6
+
7
+ if TYPE_CHECKING:
8
+ from .console import Console, ConsoleOptions, RenderableType
9
+
10
+
11
+ class Measurement(NamedTuple):
12
+ """Stores the minimum and maximum widths (in characters) required to render an object."""
13
+
14
+ minimum: int
15
+ """Minimum number of cells required to render."""
16
+ maximum: int
17
+ """Maximum number of cells required to render."""
18
+
19
+ @property
20
+ def span(self) -> int:
21
+ """Get difference between maximum and minimum."""
22
+ return self.maximum - self.minimum
23
+
24
+ def normalize(self) -> "Measurement":
25
+ """Get measurement that ensures that minimum <= maximum and minimum >= 0
26
+
27
+ Returns:
28
+ Measurement: A normalized measurement.
29
+ """
30
+ minimum, maximum = self
31
+ minimum = min(max(0, minimum), maximum)
32
+ return Measurement(max(0, minimum), max(0, max(minimum, maximum)))
33
+
34
+ def with_maximum(self, width: int) -> "Measurement":
35
+ """Get a RenderableWith where the widths are <= width.
36
+
37
+ Args:
38
+ width (int): Maximum desired width.
39
+
40
+ Returns:
41
+ Measurement: New Measurement object.
42
+ """
43
+ minimum, maximum = self
44
+ return Measurement(min(minimum, width), min(maximum, width))
45
+
46
+ def with_minimum(self, width: int) -> "Measurement":
47
+ """Get a RenderableWith where the widths are >= width.
48
+
49
+ Args:
50
+ width (int): Minimum desired width.
51
+
52
+ Returns:
53
+ Measurement: New Measurement object.
54
+ """
55
+ minimum, maximum = self
56
+ width = max(0, width)
57
+ return Measurement(max(minimum, width), max(maximum, width))
58
+
59
+ def clamp(
60
+ self, min_width: Optional[int] = None, max_width: Optional[int] = None
61
+ ) -> "Measurement":
62
+ """Clamp a measurement within the specified range.
63
+
64
+ Args:
65
+ min_width (int): Minimum desired width, or ``None`` for no minimum. Defaults to None.
66
+ max_width (int): Maximum desired width, or ``None`` for no maximum. Defaults to None.
67
+
68
+ Returns:
69
+ Measurement: New Measurement object.
70
+ """
71
+ measurement = self
72
+ if min_width is not None:
73
+ measurement = measurement.with_minimum(min_width)
74
+ if max_width is not None:
75
+ measurement = measurement.with_maximum(max_width)
76
+ return measurement
77
+
78
+ @classmethod
79
+ def get(
80
+ cls, console: "Console", options: "ConsoleOptions", renderable: "RenderableType"
81
+ ) -> "Measurement":
82
+ """Get a measurement for a renderable.
83
+
84
+ Args:
85
+ console (~rich.console.Console): Console instance.
86
+ options (~rich.console.ConsoleOptions): Console options.
87
+ renderable (RenderableType): An object that may be rendered with Rich.
88
+
89
+ Raises:
90
+ errors.NotRenderableError: If the object is not renderable.
91
+
92
+ Returns:
93
+ Measurement: Measurement object containing range of character widths required to render the object.
94
+ """
95
+ _max_width = options.max_width
96
+ if _max_width < 1:
97
+ return Measurement(0, 0)
98
+ if isinstance(renderable, str):
99
+ renderable = console.render_str(
100
+ renderable, markup=options.markup, highlight=False
101
+ )
102
+ renderable = rich_cast(renderable)
103
+ if is_renderable(renderable):
104
+ get_console_width: Optional[
105
+ Callable[["Console", "ConsoleOptions"], "Measurement"]
106
+ ] = getattr(renderable, "__rich_measure__", None)
107
+ if get_console_width is not None:
108
+ render_width = (
109
+ get_console_width(console, options)
110
+ .normalize()
111
+ .with_maximum(_max_width)
112
+ )
113
+ if render_width.maximum < 1:
114
+ return Measurement(0, 0)
115
+ return render_width.normalize()
116
+ else:
117
+ return Measurement(0, _max_width)
118
+ else:
119
+ raise errors.NotRenderableError(
120
+ f"Unable to get render width for {renderable!r}; "
121
+ "a str, Segment, or object with __rich_console__ method is required"
122
+ )
123
+
124
+
125
+ def measure_renderables(
126
+ console: "Console",
127
+ options: "ConsoleOptions",
128
+ renderables: Sequence["RenderableType"],
129
+ ) -> "Measurement":
130
+ """Get a measurement that would fit a number of renderables.
131
+
132
+ Args:
133
+ console (~rich.console.Console): Console instance.
134
+ options (~rich.console.ConsoleOptions): Console options.
135
+ renderables (Iterable[RenderableType]): One or more renderable objects.
136
+
137
+ Returns:
138
+ Measurement: Measurement object containing range of character widths required to
139
+ contain all given renderables.
140
+ """
141
+ if not renderables:
142
+ return Measurement(0, 0)
143
+ get_measurement = Measurement.get
144
+ measurements = [
145
+ get_measurement(console, options, renderable) for renderable in renderables
146
+ ]
147
+ measured_width = Measurement(
148
+ max(measurements, key=itemgetter(0)).minimum,
149
+ max(measurements, key=itemgetter(1)).maximum,
150
+ )
151
+ return measured_width
.venv/Lib/site-packages/pip/_vendor/rich/padding.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import cast, List, Optional, Tuple, TYPE_CHECKING, Union
2
+
3
+ if TYPE_CHECKING:
4
+ from .console import (
5
+ Console,
6
+ ConsoleOptions,
7
+ RenderableType,
8
+ RenderResult,
9
+ )
10
+ from .jupyter import JupyterMixin
11
+ from .measure import Measurement
12
+ from .style import Style
13
+ from .segment import Segment
14
+
15
+
16
+ PaddingDimensions = Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int, int]]
17
+
18
+
19
+ class Padding(JupyterMixin):
20
+ """Draw space around content.
21
+
22
+ Example:
23
+ >>> print(Padding("Hello", (2, 4), style="on blue"))
24
+
25
+ Args:
26
+ renderable (RenderableType): String or other renderable.
27
+ pad (Union[int, Tuple[int]]): Padding for top, right, bottom, and left borders.
28
+ May be specified with 1, 2, or 4 integers (CSS style).
29
+ style (Union[str, Style], optional): Style for padding characters. Defaults to "none".
30
+ expand (bool, optional): Expand padding to fit available width. Defaults to True.
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ renderable: "RenderableType",
36
+ pad: "PaddingDimensions" = (0, 0, 0, 0),
37
+ *,
38
+ style: Union[str, Style] = "none",
39
+ expand: bool = True,
40
+ ):
41
+ self.renderable = renderable
42
+ self.top, self.right, self.bottom, self.left = self.unpack(pad)
43
+ self.style = style
44
+ self.expand = expand
45
+
46
+ @classmethod
47
+ def indent(cls, renderable: "RenderableType", level: int) -> "Padding":
48
+ """Make padding instance to render an indent.
49
+
50
+ Args:
51
+ renderable (RenderableType): String or other renderable.
52
+ level (int): Number of characters to indent.
53
+
54
+ Returns:
55
+ Padding: A Padding instance.
56
+ """
57
+
58
+ return Padding(renderable, pad=(0, 0, 0, level), expand=False)
59
+
60
+ @staticmethod
61
+ def unpack(pad: "PaddingDimensions") -> Tuple[int, int, int, int]:
62
+ """Unpack padding specified in CSS style."""
63
+ if isinstance(pad, int):
64
+ return (pad, pad, pad, pad)
65
+ if len(pad) == 1:
66
+ _pad = pad[0]
67
+ return (_pad, _pad, _pad, _pad)
68
+ if len(pad) == 2:
69
+ pad_top, pad_right = cast(Tuple[int, int], pad)
70
+ return (pad_top, pad_right, pad_top, pad_right)
71
+ if len(pad) == 4:
72
+ top, right, bottom, left = cast(Tuple[int, int, int, int], pad)
73
+ return (top, right, bottom, left)
74
+ raise ValueError(f"1, 2 or 4 integers required for padding; {len(pad)} given")
75
+
76
+ def __repr__(self) -> str:
77
+ return f"Padding({self.renderable!r}, ({self.top},{self.right},{self.bottom},{self.left}))"
78
+
79
+ def __rich_console__(
80
+ self, console: "Console", options: "ConsoleOptions"
81
+ ) -> "RenderResult":
82
+ style = console.get_style(self.style)
83
+ if self.expand:
84
+ width = options.max_width
85
+ else:
86
+ width = min(
87
+ Measurement.get(console, options, self.renderable).maximum
88
+ + self.left
89
+ + self.right,
90
+ options.max_width,
91
+ )
92
+ render_options = options.update_width(width - self.left - self.right)
93
+ if render_options.height is not None:
94
+ render_options = render_options.update_height(
95
+ height=render_options.height - self.top - self.bottom
96
+ )
97
+ lines = console.render_lines(
98
+ self.renderable, render_options, style=style, pad=True
99
+ )
100
+ _Segment = Segment
101
+
102
+ left = _Segment(" " * self.left, style) if self.left else None
103
+ right = (
104
+ [_Segment(f'{" " * self.right}', style), _Segment.line()]
105
+ if self.right
106
+ else [_Segment.line()]
107
+ )
108
+ blank_line: Optional[List[Segment]] = None
109
+ if self.top:
110
+ blank_line = [_Segment(f'{" " * width}\n', style)]
111
+ yield from blank_line * self.top
112
+ if left:
113
+ for line in lines:
114
+ yield left
115
+ yield from line
116
+ yield from right
117
+ else:
118
+ for line in lines:
119
+ yield from line
120
+ yield from right
121
+ if self.bottom:
122
+ blank_line = blank_line or [_Segment(f'{" " * width}\n', style)]
123
+ yield from blank_line * self.bottom
124
+
125
+ def __rich_measure__(
126
+ self, console: "Console", options: "ConsoleOptions"
127
+ ) -> "Measurement":
128
+ max_width = options.max_width
129
+ extra_width = self.left + self.right
130
+ if max_width - extra_width < 1:
131
+ return Measurement(max_width, max_width)
132
+ measure_min, measure_max = Measurement.get(console, options, self.renderable)
133
+ measurement = Measurement(measure_min + extra_width, measure_max + extra_width)
134
+ measurement = measurement.with_maximum(max_width)
135
+ return measurement
136
+
137
+
138
+ if __name__ == "__main__": # pragma: no cover
139
+ from pip._vendor.rich import print
140
+
141
+ print(Padding("Hello, World", (2, 4), style="on blue"))
.venv/Lib/site-packages/pip/_vendor/rich/pager.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import ABC, abstractmethod
2
+ from typing import Any
3
+
4
+
5
+ class Pager(ABC):
6
+ """Base class for a pager."""
7
+
8
+ @abstractmethod
9
+ def show(self, content: str) -> None:
10
+ """Show content in pager.
11
+
12
+ Args:
13
+ content (str): Content to be displayed.
14
+ """
15
+
16
+
17
+ class SystemPager(Pager):
18
+ """Uses the pager installed on the system."""
19
+
20
+ def _pager(self, content: str) -> Any: #  pragma: no cover
21
+ return __import__("pydoc").pager(content)
22
+
23
+ def show(self, content: str) -> None:
24
+ """Use the same pager used by pydoc."""
25
+ self._pager(content)
26
+
27
+
28
+ if __name__ == "__main__": # pragma: no cover
29
+ from .__main__ import make_test_card
30
+ from .console import Console
31
+
32
+ console = Console()
33
+ with console.pager(styles=True):
34
+ console.print(make_test_card())