Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__main__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/cmdline.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/console.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/plugin.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/scanner.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/style.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/token.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/util.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/filters/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__init__.py +153 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/_mapping.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/bbcode.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/groff.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/html.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/img.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/irc.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/latex.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/other.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/pangomarkup.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/rtf.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/svg.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/terminal.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/terminal256.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/_mapping.py +84 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/bbcode.py +108 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/groff.py +168 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/html.py +983 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/img.py +641 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/irc.py +179 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/latex.py +511 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/other.py +161 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/pangomarkup.py +83 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/rtf.py +146 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/svg.py +188 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/terminal.py +127 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/terminal256.py +338 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/styles/__init__.py +93 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/styles/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/__init__.py +172 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/__main__.py +280 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_cell_widths.py +451 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_emoji_codes.py +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_lru_cache.py +34 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_ratio.py +160 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_spinners.py +848 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_windows.py +72 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_wrap.py +55 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/abc.py +33 -0
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (3 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__main__.cpython-310.pyc
ADDED
Binary file (591 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/cmdline.cpython-310.pyc
ADDED
Binary file (15.5 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/console.cpython-310.pyc
ADDED
Binary file (1.89 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/plugin.cpython-310.pyc
ADDED
Binary file (2.05 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/scanner.cpython-310.pyc
ADDED
Binary file (3.56 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/style.cpython-310.pyc
ADDED
Binary file (4.58 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/token.cpython-310.pyc
ADDED
Binary file (4.65 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/util.cpython-310.pyc
ADDED
Binary file (9.17 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/filters/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (29.5 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__init__.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters
|
3 |
+
~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Pygments formatters.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
import re
|
12 |
+
import sys
|
13 |
+
import types
|
14 |
+
import fnmatch
|
15 |
+
from os.path import basename
|
16 |
+
|
17 |
+
from pip._vendor.pygments.formatters._mapping import FORMATTERS
|
18 |
+
from pip._vendor.pygments.plugin import find_plugin_formatters
|
19 |
+
from pip._vendor.pygments.util import ClassNotFound
|
20 |
+
|
21 |
+
__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
|
22 |
+
'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS)
|
23 |
+
|
24 |
+
_formatter_cache = {} # classes by name
|
25 |
+
_pattern_cache = {}
|
26 |
+
|
27 |
+
|
28 |
+
def _fn_matches(fn, glob):
|
29 |
+
"""Return whether the supplied file name fn matches pattern filename."""
|
30 |
+
if glob not in _pattern_cache:
|
31 |
+
pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
|
32 |
+
return pattern.match(fn)
|
33 |
+
return _pattern_cache[glob].match(fn)
|
34 |
+
|
35 |
+
|
36 |
+
def _load_formatters(module_name):
|
37 |
+
"""Load a formatter (and all others in the module too)."""
|
38 |
+
mod = __import__(module_name, None, None, ['__all__'])
|
39 |
+
for formatter_name in mod.__all__:
|
40 |
+
cls = getattr(mod, formatter_name)
|
41 |
+
_formatter_cache[cls.name] = cls
|
42 |
+
|
43 |
+
|
44 |
+
def get_all_formatters():
|
45 |
+
"""Return a generator for all formatter classes."""
|
46 |
+
# NB: this returns formatter classes, not info like get_all_lexers().
|
47 |
+
for info in FORMATTERS.values():
|
48 |
+
if info[1] not in _formatter_cache:
|
49 |
+
_load_formatters(info[0])
|
50 |
+
yield _formatter_cache[info[1]]
|
51 |
+
for _, formatter in find_plugin_formatters():
|
52 |
+
yield formatter
|
53 |
+
|
54 |
+
|
55 |
+
def find_formatter_class(alias):
|
56 |
+
"""Lookup a formatter by alias.
|
57 |
+
|
58 |
+
Returns None if not found.
|
59 |
+
"""
|
60 |
+
for module_name, name, aliases, _, _ in FORMATTERS.values():
|
61 |
+
if alias in aliases:
|
62 |
+
if name not in _formatter_cache:
|
63 |
+
_load_formatters(module_name)
|
64 |
+
return _formatter_cache[name]
|
65 |
+
for _, cls in find_plugin_formatters():
|
66 |
+
if alias in cls.aliases:
|
67 |
+
return cls
|
68 |
+
|
69 |
+
|
70 |
+
def get_formatter_by_name(_alias, **options):
|
71 |
+
"""Lookup and instantiate a formatter by alias.
|
72 |
+
|
73 |
+
Raises ClassNotFound if not found.
|
74 |
+
"""
|
75 |
+
cls = find_formatter_class(_alias)
|
76 |
+
if cls is None:
|
77 |
+
raise ClassNotFound("no formatter found for name %r" % _alias)
|
78 |
+
return cls(**options)
|
79 |
+
|
80 |
+
|
81 |
+
def load_formatter_from_file(filename, formattername="CustomFormatter",
|
82 |
+
**options):
|
83 |
+
"""Load a formatter from a file.
|
84 |
+
|
85 |
+
This method expects a file located relative to the current working
|
86 |
+
directory, which contains a class named CustomFormatter. By default,
|
87 |
+
it expects the Formatter to be named CustomFormatter; you can specify
|
88 |
+
your own class name as the second argument to this function.
|
89 |
+
|
90 |
+
Users should be very careful with the input, because this method
|
91 |
+
is equivalent to running eval on the input file.
|
92 |
+
|
93 |
+
Raises ClassNotFound if there are any problems importing the Formatter.
|
94 |
+
|
95 |
+
.. versionadded:: 2.2
|
96 |
+
"""
|
97 |
+
try:
|
98 |
+
# This empty dict will contain the namespace for the exec'd file
|
99 |
+
custom_namespace = {}
|
100 |
+
with open(filename, 'rb') as f:
|
101 |
+
exec(f.read(), custom_namespace)
|
102 |
+
# Retrieve the class `formattername` from that namespace
|
103 |
+
if formattername not in custom_namespace:
|
104 |
+
raise ClassNotFound('no valid %s class found in %s' %
|
105 |
+
(formattername, filename))
|
106 |
+
formatter_class = custom_namespace[formattername]
|
107 |
+
# And finally instantiate it with the options
|
108 |
+
return formatter_class(**options)
|
109 |
+
except OSError as err:
|
110 |
+
raise ClassNotFound('cannot read %s: %s' % (filename, err))
|
111 |
+
except ClassNotFound:
|
112 |
+
raise
|
113 |
+
except Exception as err:
|
114 |
+
raise ClassNotFound('error when loading custom formatter: %s' % err)
|
115 |
+
|
116 |
+
|
117 |
+
def get_formatter_for_filename(fn, **options):
|
118 |
+
"""Lookup and instantiate a formatter by filename pattern.
|
119 |
+
|
120 |
+
Raises ClassNotFound if not found.
|
121 |
+
"""
|
122 |
+
fn = basename(fn)
|
123 |
+
for modname, name, _, filenames, _ in FORMATTERS.values():
|
124 |
+
for filename in filenames:
|
125 |
+
if _fn_matches(fn, filename):
|
126 |
+
if name not in _formatter_cache:
|
127 |
+
_load_formatters(modname)
|
128 |
+
return _formatter_cache[name](**options)
|
129 |
+
for cls in find_plugin_formatters():
|
130 |
+
for filename in cls.filenames:
|
131 |
+
if _fn_matches(fn, filename):
|
132 |
+
return cls(**options)
|
133 |
+
raise ClassNotFound("no formatter found for file name %r" % fn)
|
134 |
+
|
135 |
+
|
136 |
+
class _automodule(types.ModuleType):
|
137 |
+
"""Automatically import formatters."""
|
138 |
+
|
139 |
+
def __getattr__(self, name):
|
140 |
+
info = FORMATTERS.get(name)
|
141 |
+
if info:
|
142 |
+
_load_formatters(info[0])
|
143 |
+
cls = _formatter_cache[info[1]]
|
144 |
+
setattr(self, name, cls)
|
145 |
+
return cls
|
146 |
+
raise AttributeError(name)
|
147 |
+
|
148 |
+
|
149 |
+
oldmod = sys.modules[__name__]
|
150 |
+
newmod = _automodule(__name__)
|
151 |
+
newmod.__dict__.update(oldmod.__dict__)
|
152 |
+
sys.modules[__name__] = newmod
|
153 |
+
del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (4.67 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/_mapping.cpython-310.pyc
ADDED
Binary file (5.54 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/bbcode.cpython-310.pyc
ADDED
Binary file (3.09 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/groff.cpython-310.pyc
ADDED
Binary file (4.36 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/html.cpython-310.pyc
ADDED
Binary file (29.1 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/img.cpython-310.pyc
ADDED
Binary file (17.5 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/irc.cpython-310.pyc
ADDED
Binary file (4.59 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/latex.cpython-310.pyc
ADDED
Binary file (13.5 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/other.cpython-310.pyc
ADDED
Binary file (4.81 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/pangomarkup.cpython-310.pyc
ADDED
Binary file (2.11 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/rtf.cpython-310.pyc
ADDED
Binary file (4.14 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/svg.cpython-310.pyc
ADDED
Binary file (6.34 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/terminal.cpython-310.pyc
ADDED
Binary file (4 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/terminal256.cpython-310.pyc
ADDED
Binary file (9.25 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/_mapping.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters._mapping
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter mapping definitions. This file is generated by itself. Everytime
|
6 |
+
you change something on a builtin formatter definition, run this script from
|
7 |
+
the formatters folder to update it.
|
8 |
+
|
9 |
+
Do not alter the FORMATTERS dictionary by hand.
|
10 |
+
|
11 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
12 |
+
:license: BSD, see LICENSE for details.
|
13 |
+
"""
|
14 |
+
|
15 |
+
FORMATTERS = {
|
16 |
+
'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'),
|
17 |
+
'BmpImageFormatter': ('pygments.formatters.img', 'img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
18 |
+
'GifImageFormatter': ('pygments.formatters.img', 'img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
19 |
+
'GroffFormatter': ('pygments.formatters.groff', 'groff', ('groff', 'troff', 'roff'), (), 'Format tokens with groff escapes to change their color and font style.'),
|
20 |
+
'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` option."),
|
21 |
+
'IRCFormatter': ('pygments.formatters.irc', 'IRC', ('irc', 'IRC'), (), 'Format tokens with IRC color sequences'),
|
22 |
+
'ImageFormatter': ('pygments.formatters.img', 'img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
23 |
+
'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
|
24 |
+
'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
|
25 |
+
'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
|
26 |
+
'PangoMarkupFormatter': ('pygments.formatters.pangomarkup', 'Pango Markup', ('pango', 'pangomarkup'), (), 'Format tokens as Pango Markup code. It can then be rendered to an SVG.'),
|
27 |
+
'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
|
28 |
+
'RtfFormatter': ('pygments.formatters.rtf', 'RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.'),
|
29 |
+
'SvgFormatter': ('pygments.formatters.svg', 'SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'),
|
30 |
+
'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
|
31 |
+
'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'),
|
32 |
+
'TerminalTrueColorFormatter': ('pygments.formatters.terminal256', 'TerminalTrueColor', ('terminal16m', 'console16m', '16m'), (), 'Format tokens with ANSI color sequences, for output in a true-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
|
33 |
+
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
|
34 |
+
}
|
35 |
+
|
36 |
+
if __name__ == '__main__': # pragma: no cover
|
37 |
+
import sys
|
38 |
+
import os
|
39 |
+
|
40 |
+
# lookup formatters
|
41 |
+
found_formatters = []
|
42 |
+
imports = []
|
43 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
44 |
+
from pip._vendor.pygments.util import docstring_headline
|
45 |
+
|
46 |
+
for root, dirs, files in os.walk('.'):
|
47 |
+
for filename in files:
|
48 |
+
if filename.endswith('.py') and not filename.startswith('_'):
|
49 |
+
module_name = 'pygments.formatters%s.%s' % (
|
50 |
+
root[1:].replace('/', '.'), filename[:-3])
|
51 |
+
print(module_name)
|
52 |
+
module = __import__(module_name, None, None, [''])
|
53 |
+
for formatter_name in module.__all__:
|
54 |
+
formatter = getattr(module, formatter_name)
|
55 |
+
found_formatters.append(
|
56 |
+
'%r: %r' % (formatter_name,
|
57 |
+
(module_name,
|
58 |
+
formatter.name,
|
59 |
+
tuple(formatter.aliases),
|
60 |
+
tuple(formatter.filenames),
|
61 |
+
docstring_headline(formatter))))
|
62 |
+
# sort them to make the diff minimal
|
63 |
+
found_formatters.sort()
|
64 |
+
|
65 |
+
# extract useful sourcecode from this file
|
66 |
+
with open(__file__) as fp:
|
67 |
+
content = fp.read()
|
68 |
+
# replace crnl to nl for Windows.
|
69 |
+
#
|
70 |
+
# Note that, originally, contributers should keep nl of master
|
71 |
+
# repository, for example by using some kind of automatic
|
72 |
+
# management EOL, like `EolExtension
|
73 |
+
# <https://www.mercurial-scm.org/wiki/EolExtension>`.
|
74 |
+
content = content.replace("\r\n", "\n")
|
75 |
+
header = content[:content.find('FORMATTERS = {')]
|
76 |
+
footer = content[content.find("if __name__ == '__main__':"):]
|
77 |
+
|
78 |
+
# write new file
|
79 |
+
with open(__file__, 'w') as fp:
|
80 |
+
fp.write(header)
|
81 |
+
fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
|
82 |
+
fp.write(footer)
|
83 |
+
|
84 |
+
print ('=== %d formatters processed.' % len(found_formatters))
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/bbcode.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.bbcode
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
BBcode formatter.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
|
12 |
+
from pip._vendor.pygments.formatter import Formatter
|
13 |
+
from pip._vendor.pygments.util import get_bool_opt
|
14 |
+
|
15 |
+
__all__ = ['BBCodeFormatter']
|
16 |
+
|
17 |
+
|
18 |
+
class BBCodeFormatter(Formatter):
|
19 |
+
"""
|
20 |
+
Format tokens with BBcodes. These formatting codes are used by many
|
21 |
+
bulletin boards, so you can highlight your sourcecode with pygments before
|
22 |
+
posting it there.
|
23 |
+
|
24 |
+
This formatter has no support for background colors and borders, as there
|
25 |
+
are no common BBcode tags for that.
|
26 |
+
|
27 |
+
Some board systems (e.g. phpBB) don't support colors in their [code] tag,
|
28 |
+
so you can't use the highlighting together with that tag.
|
29 |
+
Text in a [code] tag usually is shown with a monospace font (which this
|
30 |
+
formatter can do with the ``monofont`` option) and no spaces (which you
|
31 |
+
need for indentation) are removed.
|
32 |
+
|
33 |
+
Additional options accepted:
|
34 |
+
|
35 |
+
`style`
|
36 |
+
The style to use, can be a string or a Style subclass (default:
|
37 |
+
``'default'``).
|
38 |
+
|
39 |
+
`codetag`
|
40 |
+
If set to true, put the output into ``[code]`` tags (default:
|
41 |
+
``false``)
|
42 |
+
|
43 |
+
`monofont`
|
44 |
+
If set to true, add a tag to show the code with a monospace font
|
45 |
+
(default: ``false``).
|
46 |
+
"""
|
47 |
+
name = 'BBCode'
|
48 |
+
aliases = ['bbcode', 'bb']
|
49 |
+
filenames = []
|
50 |
+
|
51 |
+
def __init__(self, **options):
|
52 |
+
Formatter.__init__(self, **options)
|
53 |
+
self._code = get_bool_opt(options, 'codetag', False)
|
54 |
+
self._mono = get_bool_opt(options, 'monofont', False)
|
55 |
+
|
56 |
+
self.styles = {}
|
57 |
+
self._make_styles()
|
58 |
+
|
59 |
+
def _make_styles(self):
|
60 |
+
for ttype, ndef in self.style:
|
61 |
+
start = end = ''
|
62 |
+
if ndef['color']:
|
63 |
+
start += '[color=#%s]' % ndef['color']
|
64 |
+
end = '[/color]' + end
|
65 |
+
if ndef['bold']:
|
66 |
+
start += '[b]'
|
67 |
+
end = '[/b]' + end
|
68 |
+
if ndef['italic']:
|
69 |
+
start += '[i]'
|
70 |
+
end = '[/i]' + end
|
71 |
+
if ndef['underline']:
|
72 |
+
start += '[u]'
|
73 |
+
end = '[/u]' + end
|
74 |
+
# there are no common BBcodes for background-color and border
|
75 |
+
|
76 |
+
self.styles[ttype] = start, end
|
77 |
+
|
78 |
+
def format_unencoded(self, tokensource, outfile):
|
79 |
+
if self._code:
|
80 |
+
outfile.write('[code]')
|
81 |
+
if self._mono:
|
82 |
+
outfile.write('[font=monospace]')
|
83 |
+
|
84 |
+
lastval = ''
|
85 |
+
lasttype = None
|
86 |
+
|
87 |
+
for ttype, value in tokensource:
|
88 |
+
while ttype not in self.styles:
|
89 |
+
ttype = ttype.parent
|
90 |
+
if ttype == lasttype:
|
91 |
+
lastval += value
|
92 |
+
else:
|
93 |
+
if lastval:
|
94 |
+
start, end = self.styles[lasttype]
|
95 |
+
outfile.write(''.join((start, lastval, end)))
|
96 |
+
lastval = value
|
97 |
+
lasttype = ttype
|
98 |
+
|
99 |
+
if lastval:
|
100 |
+
start, end = self.styles[lasttype]
|
101 |
+
outfile.write(''.join((start, lastval, end)))
|
102 |
+
|
103 |
+
if self._mono:
|
104 |
+
outfile.write('[/font]')
|
105 |
+
if self._code:
|
106 |
+
outfile.write('[/code]')
|
107 |
+
if self._code or self._mono:
|
108 |
+
outfile.write('\n')
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/groff.py
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.groff
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for groff output.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
import math
|
12 |
+
from pip._vendor.pygments.formatter import Formatter
|
13 |
+
from pip._vendor.pygments.util import get_bool_opt, get_int_opt
|
14 |
+
|
15 |
+
__all__ = ['GroffFormatter']
|
16 |
+
|
17 |
+
|
18 |
+
class GroffFormatter(Formatter):
|
19 |
+
"""
|
20 |
+
Format tokens with groff escapes to change their color and font style.
|
21 |
+
|
22 |
+
.. versionadded:: 2.11
|
23 |
+
|
24 |
+
Additional options accepted:
|
25 |
+
|
26 |
+
`style`
|
27 |
+
The style to use, can be a string or a Style subclass (default:
|
28 |
+
``'default'``).
|
29 |
+
|
30 |
+
`monospaced`
|
31 |
+
If set to true, monospace font will be used (default: ``true``).
|
32 |
+
|
33 |
+
`linenos`
|
34 |
+
If set to true, print the line numbers (default: ``false``).
|
35 |
+
|
36 |
+
`wrap`
|
37 |
+
Wrap lines to the specified number of characters. Disabled if set to 0
|
38 |
+
(default: ``0``).
|
39 |
+
"""
|
40 |
+
|
41 |
+
name = 'groff'
|
42 |
+
aliases = ['groff','troff','roff']
|
43 |
+
filenames = []
|
44 |
+
|
45 |
+
def __init__(self, **options):
|
46 |
+
Formatter.__init__(self, **options)
|
47 |
+
|
48 |
+
self.monospaced = get_bool_opt(options, 'monospaced', True)
|
49 |
+
self.linenos = get_bool_opt(options, 'linenos', False)
|
50 |
+
self._lineno = 0
|
51 |
+
self.wrap = get_int_opt(options, 'wrap', 0)
|
52 |
+
self._linelen = 0
|
53 |
+
|
54 |
+
self.styles = {}
|
55 |
+
self._make_styles()
|
56 |
+
|
57 |
+
|
58 |
+
def _make_styles(self):
|
59 |
+
regular = '\\f[CR]' if self.monospaced else '\\f[R]'
|
60 |
+
bold = '\\f[CB]' if self.monospaced else '\\f[B]'
|
61 |
+
italic = '\\f[CI]' if self.monospaced else '\\f[I]'
|
62 |
+
|
63 |
+
for ttype, ndef in self.style:
|
64 |
+
start = end = ''
|
65 |
+
if ndef['color']:
|
66 |
+
start += '\\m[%s]' % ndef['color']
|
67 |
+
end = '\\m[]' + end
|
68 |
+
if ndef['bold']:
|
69 |
+
start += bold
|
70 |
+
end = regular + end
|
71 |
+
if ndef['italic']:
|
72 |
+
start += italic
|
73 |
+
end = regular + end
|
74 |
+
if ndef['bgcolor']:
|
75 |
+
start += '\\M[%s]' % ndef['bgcolor']
|
76 |
+
end = '\\M[]' + end
|
77 |
+
|
78 |
+
self.styles[ttype] = start, end
|
79 |
+
|
80 |
+
|
81 |
+
def _define_colors(self, outfile):
|
82 |
+
colors = set()
|
83 |
+
for _, ndef in self.style:
|
84 |
+
if ndef['color'] is not None:
|
85 |
+
colors.add(ndef['color'])
|
86 |
+
|
87 |
+
for color in colors:
|
88 |
+
outfile.write('.defcolor ' + color + ' rgb #' + color + '\n')
|
89 |
+
|
90 |
+
|
91 |
+
def _write_lineno(self, outfile):
|
92 |
+
self._lineno += 1
|
93 |
+
outfile.write("%s% 4d " % (self._lineno != 1 and '\n' or '', self._lineno))
|
94 |
+
|
95 |
+
|
96 |
+
def _wrap_line(self, line):
|
97 |
+
length = len(line.rstrip('\n'))
|
98 |
+
space = ' ' if self.linenos else ''
|
99 |
+
newline = ''
|
100 |
+
|
101 |
+
if length > self.wrap:
|
102 |
+
for i in range(0, math.floor(length / self.wrap)):
|
103 |
+
chunk = line[i*self.wrap:i*self.wrap+self.wrap]
|
104 |
+
newline += (chunk + '\n' + space)
|
105 |
+
remainder = length % self.wrap
|
106 |
+
if remainder > 0:
|
107 |
+
newline += line[-remainder-1:]
|
108 |
+
self._linelen = remainder
|
109 |
+
elif self._linelen + length > self.wrap:
|
110 |
+
newline = ('\n' + space) + line
|
111 |
+
self._linelen = length
|
112 |
+
else:
|
113 |
+
newline = line
|
114 |
+
self._linelen += length
|
115 |
+
|
116 |
+
return newline
|
117 |
+
|
118 |
+
|
119 |
+
def _escape_chars(self, text):
|
120 |
+
text = text.replace('\\', '\\[u005C]'). \
|
121 |
+
replace('.', '\\[char46]'). \
|
122 |
+
replace('\'', '\\[u0027]'). \
|
123 |
+
replace('`', '\\[u0060]'). \
|
124 |
+
replace('~', '\\[u007E]')
|
125 |
+
copy = text
|
126 |
+
|
127 |
+
for char in copy:
|
128 |
+
if len(char) != len(char.encode()):
|
129 |
+
uni = char.encode('unicode_escape') \
|
130 |
+
.decode()[1:] \
|
131 |
+
.replace('x', 'u00') \
|
132 |
+
.upper()
|
133 |
+
text = text.replace(char, '\\[u' + uni[1:] + ']')
|
134 |
+
|
135 |
+
return text
|
136 |
+
|
137 |
+
|
138 |
+
def format_unencoded(self, tokensource, outfile):
|
139 |
+
self._define_colors(outfile)
|
140 |
+
|
141 |
+
outfile.write('.nf\n\\f[CR]\n')
|
142 |
+
|
143 |
+
if self.linenos:
|
144 |
+
self._write_lineno(outfile)
|
145 |
+
|
146 |
+
for ttype, value in tokensource:
|
147 |
+
start, end = self.styles[ttype]
|
148 |
+
|
149 |
+
for line in value.splitlines(True):
|
150 |
+
if self.wrap > 0:
|
151 |
+
line = self._wrap_line(line)
|
152 |
+
|
153 |
+
if start and end:
|
154 |
+
text = self._escape_chars(line.rstrip('\n'))
|
155 |
+
if text != '':
|
156 |
+
outfile.write(''.join((start, text, end)))
|
157 |
+
else:
|
158 |
+
outfile.write(self._escape_chars(line.rstrip('\n')))
|
159 |
+
|
160 |
+
if line.endswith('\n'):
|
161 |
+
if self.linenos:
|
162 |
+
self._write_lineno(outfile)
|
163 |
+
self._linelen = 0
|
164 |
+
else:
|
165 |
+
outfile.write('\n')
|
166 |
+
self._linelen = 0
|
167 |
+
|
168 |
+
outfile.write('\n.fi')
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/html.py
ADDED
@@ -0,0 +1,983 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.html
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for HTML output.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
import functools
|
12 |
+
import os
|
13 |
+
import sys
|
14 |
+
import os.path
|
15 |
+
from io import StringIO
|
16 |
+
|
17 |
+
from pip._vendor.pygments.formatter import Formatter
|
18 |
+
from pip._vendor.pygments.token import Token, Text, STANDARD_TYPES
|
19 |
+
from pip._vendor.pygments.util import get_bool_opt, get_int_opt, get_list_opt
|
20 |
+
|
21 |
+
try:
|
22 |
+
import ctags
|
23 |
+
except ImportError:
|
24 |
+
ctags = None
|
25 |
+
|
26 |
+
__all__ = ['HtmlFormatter']
|
27 |
+
|
28 |
+
|
29 |
+
_escape_html_table = {
|
30 |
+
ord('&'): '&',
|
31 |
+
ord('<'): '<',
|
32 |
+
ord('>'): '>',
|
33 |
+
ord('"'): '"',
|
34 |
+
ord("'"): ''',
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
def escape_html(text, table=_escape_html_table):
|
39 |
+
"""Escape &, <, > as well as single and double quotes for HTML."""
|
40 |
+
return text.translate(table)
|
41 |
+
|
42 |
+
|
43 |
+
def webify(color):
|
44 |
+
if color.startswith('calc') or color.startswith('var'):
|
45 |
+
return color
|
46 |
+
else:
|
47 |
+
return '#' + color
|
48 |
+
|
49 |
+
|
50 |
+
def _get_ttype_class(ttype):
|
51 |
+
fname = STANDARD_TYPES.get(ttype)
|
52 |
+
if fname:
|
53 |
+
return fname
|
54 |
+
aname = ''
|
55 |
+
while fname is None:
|
56 |
+
aname = '-' + ttype[-1] + aname
|
57 |
+
ttype = ttype.parent
|
58 |
+
fname = STANDARD_TYPES.get(ttype)
|
59 |
+
return fname + aname
|
60 |
+
|
61 |
+
|
62 |
+
CSSFILE_TEMPLATE = '''\
|
63 |
+
/*
|
64 |
+
generated by Pygments <https://pygments.org/>
|
65 |
+
Copyright 2006-2021 by the Pygments team.
|
66 |
+
Licensed under the BSD license, see LICENSE for details.
|
67 |
+
*/
|
68 |
+
%(styledefs)s
|
69 |
+
'''
|
70 |
+
|
71 |
+
DOC_HEADER = '''\
|
72 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
73 |
+
"http://www.w3.org/TR/html4/strict.dtd">
|
74 |
+
<!--
|
75 |
+
generated by Pygments <https://pygments.org/>
|
76 |
+
Copyright 2006-2021 by the Pygments team.
|
77 |
+
Licensed under the BSD license, see LICENSE for details.
|
78 |
+
-->
|
79 |
+
<html>
|
80 |
+
<head>
|
81 |
+
<title>%(title)s</title>
|
82 |
+
<meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
|
83 |
+
<style type="text/css">
|
84 |
+
''' + CSSFILE_TEMPLATE + '''
|
85 |
+
</style>
|
86 |
+
</head>
|
87 |
+
<body>
|
88 |
+
<h2>%(title)s</h2>
|
89 |
+
|
90 |
+
'''
|
91 |
+
|
92 |
+
DOC_HEADER_EXTERNALCSS = '''\
|
93 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
94 |
+
"http://www.w3.org/TR/html4/strict.dtd">
|
95 |
+
|
96 |
+
<html>
|
97 |
+
<head>
|
98 |
+
<title>%(title)s</title>
|
99 |
+
<meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
|
100 |
+
<link rel="stylesheet" href="%(cssfile)s" type="text/css">
|
101 |
+
</head>
|
102 |
+
<body>
|
103 |
+
<h2>%(title)s</h2>
|
104 |
+
|
105 |
+
'''
|
106 |
+
|
107 |
+
DOC_FOOTER = '''\
|
108 |
+
</body>
|
109 |
+
</html>
|
110 |
+
'''
|
111 |
+
|
112 |
+
|
113 |
+
class HtmlFormatter(Formatter):
|
114 |
+
r"""
|
115 |
+
Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped
|
116 |
+
in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass`
|
117 |
+
option.
|
118 |
+
|
119 |
+
If the `linenos` option is set to ``"table"``, the ``<pre>`` is
|
120 |
+
additionally wrapped inside a ``<table>`` which has one row and two
|
121 |
+
cells: one containing the line numbers and one containing the code.
|
122 |
+
Example:
|
123 |
+
|
124 |
+
.. sourcecode:: html
|
125 |
+
|
126 |
+
<div class="highlight" >
|
127 |
+
<table><tr>
|
128 |
+
<td class="linenos" title="click to toggle"
|
129 |
+
onclick="with (this.firstChild.style)
|
130 |
+
{ display = (display == '') ? 'none' : '' }">
|
131 |
+
<pre>1
|
132 |
+
2</pre>
|
133 |
+
</td>
|
134 |
+
<td class="code">
|
135 |
+
<pre><span class="Ke">def </span><span class="NaFu">foo</span>(bar):
|
136 |
+
<span class="Ke">pass</span>
|
137 |
+
</pre>
|
138 |
+
</td>
|
139 |
+
</tr></table></div>
|
140 |
+
|
141 |
+
(whitespace added to improve clarity).
|
142 |
+
|
143 |
+
Wrapping can be disabled using the `nowrap` option.
|
144 |
+
|
145 |
+
A list of lines can be specified using the `hl_lines` option to make these
|
146 |
+
lines highlighted (as of Pygments 0.11).
|
147 |
+
|
148 |
+
With the `full` option, a complete HTML 4 document is output, including
|
149 |
+
the style definitions inside a ``<style>`` tag, or in a separate file if
|
150 |
+
the `cssfile` option is given.
|
151 |
+
|
152 |
+
When `tagsfile` is set to the path of a ctags index file, it is used to
|
153 |
+
generate hyperlinks from names to their definition. You must enable
|
154 |
+
`lineanchors` and run ctags with the `-n` option for this to work. The
|
155 |
+
`python-ctags` module from PyPI must be installed to use this feature;
|
156 |
+
otherwise a `RuntimeError` will be raised.
|
157 |
+
|
158 |
+
The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string
|
159 |
+
containing CSS rules for the CSS classes used by the formatter. The
|
160 |
+
argument `arg` can be used to specify additional CSS selectors that
|
161 |
+
are prepended to the classes. A call `fmter.get_style_defs('td .code')`
|
162 |
+
would result in the following CSS classes:
|
163 |
+
|
164 |
+
.. sourcecode:: css
|
165 |
+
|
166 |
+
td .code .kw { font-weight: bold; color: #00FF00 }
|
167 |
+
td .code .cm { color: #999999 }
|
168 |
+
...
|
169 |
+
|
170 |
+
If you have Pygments 0.6 or higher, you can also pass a list or tuple to the
|
171 |
+
`get_style_defs()` method to request multiple prefixes for the tokens:
|
172 |
+
|
173 |
+
.. sourcecode:: python
|
174 |
+
|
175 |
+
formatter.get_style_defs(['div.syntax pre', 'pre.syntax'])
|
176 |
+
|
177 |
+
The output would then look like this:
|
178 |
+
|
179 |
+
.. sourcecode:: css
|
180 |
+
|
181 |
+
div.syntax pre .kw,
|
182 |
+
pre.syntax .kw { font-weight: bold; color: #00FF00 }
|
183 |
+
div.syntax pre .cm,
|
184 |
+
pre.syntax .cm { color: #999999 }
|
185 |
+
...
|
186 |
+
|
187 |
+
Additional options accepted:
|
188 |
+
|
189 |
+
`nowrap`
|
190 |
+
If set to ``True``, don't wrap the tokens at all, not even inside a ``<pre>``
|
191 |
+
tag. This disables most other options (default: ``False``).
|
192 |
+
|
193 |
+
`full`
|
194 |
+
Tells the formatter to output a "full" document, i.e. a complete
|
195 |
+
self-contained document (default: ``False``).
|
196 |
+
|
197 |
+
`title`
|
198 |
+
If `full` is true, the title that should be used to caption the
|
199 |
+
document (default: ``''``).
|
200 |
+
|
201 |
+
`style`
|
202 |
+
The style to use, can be a string or a Style subclass (default:
|
203 |
+
``'default'``). This option has no effect if the `cssfile`
|
204 |
+
and `noclobber_cssfile` option are given and the file specified in
|
205 |
+
`cssfile` exists.
|
206 |
+
|
207 |
+
`noclasses`
|
208 |
+
If set to true, token ``<span>`` tags (as well as line number elements)
|
209 |
+
will not use CSS classes, but inline styles. This is not recommended
|
210 |
+
for larger pieces of code since it increases output size by quite a bit
|
211 |
+
(default: ``False``).
|
212 |
+
|
213 |
+
`classprefix`
|
214 |
+
Since the token types use relatively short class names, they may clash
|
215 |
+
with some of your own class names. In this case you can use the
|
216 |
+
`classprefix` option to give a string to prepend to all Pygments-generated
|
217 |
+
CSS class names for token types.
|
218 |
+
Note that this option also affects the output of `get_style_defs()`.
|
219 |
+
|
220 |
+
`cssclass`
|
221 |
+
CSS class for the wrapping ``<div>`` tag (default: ``'highlight'``).
|
222 |
+
If you set this option, the default selector for `get_style_defs()`
|
223 |
+
will be this class.
|
224 |
+
|
225 |
+
.. versionadded:: 0.9
|
226 |
+
If you select the ``'table'`` line numbers, the wrapping table will
|
227 |
+
have a CSS class of this string plus ``'table'``, the default is
|
228 |
+
accordingly ``'highlighttable'``.
|
229 |
+
|
230 |
+
`cssstyles`
|
231 |
+
Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
|
232 |
+
|
233 |
+
`prestyles`
|
234 |
+
Inline CSS styles for the ``<pre>`` tag (default: ``''``).
|
235 |
+
|
236 |
+
.. versionadded:: 0.11
|
237 |
+
|
238 |
+
`cssfile`
|
239 |
+
If the `full` option is true and this option is given, it must be the
|
240 |
+
name of an external file. If the filename does not include an absolute
|
241 |
+
path, the file's path will be assumed to be relative to the main output
|
242 |
+
file's path, if the latter can be found. The stylesheet is then written
|
243 |
+
to this file instead of the HTML file.
|
244 |
+
|
245 |
+
.. versionadded:: 0.6
|
246 |
+
|
247 |
+
`noclobber_cssfile`
|
248 |
+
If `cssfile` is given and the specified file exists, the css file will
|
249 |
+
not be overwritten. This allows the use of the `full` option in
|
250 |
+
combination with a user specified css file. Default is ``False``.
|
251 |
+
|
252 |
+
.. versionadded:: 1.1
|
253 |
+
|
254 |
+
`linenos`
|
255 |
+
If set to ``'table'``, output line numbers as a table with two cells,
|
256 |
+
one containing the line numbers, the other the whole code. This is
|
257 |
+
copy-and-paste-friendly, but may cause alignment problems with some
|
258 |
+
browsers or fonts. If set to ``'inline'``, the line numbers will be
|
259 |
+
integrated in the ``<pre>`` tag that contains the code (that setting
|
260 |
+
is *new in Pygments 0.8*).
|
261 |
+
|
262 |
+
For compatibility with Pygments 0.7 and earlier, every true value
|
263 |
+
except ``'inline'`` means the same as ``'table'`` (in particular, that
|
264 |
+
means also ``True``).
|
265 |
+
|
266 |
+
The default value is ``False``, which means no line numbers at all.
|
267 |
+
|
268 |
+
**Note:** with the default ("table") line number mechanism, the line
|
269 |
+
numbers and code can have different line heights in Internet Explorer
|
270 |
+
unless you give the enclosing ``<pre>`` tags an explicit ``line-height``
|
271 |
+
CSS property (you get the default line spacing with ``line-height:
|
272 |
+
125%``).
|
273 |
+
|
274 |
+
`hl_lines`
|
275 |
+
Specify a list of lines to be highlighted. The line numbers are always
|
276 |
+
relative to the input (i.e. the first line is line 1) and are
|
277 |
+
independent of `linenostart`.
|
278 |
+
|
279 |
+
.. versionadded:: 0.11
|
280 |
+
|
281 |
+
`linenostart`
|
282 |
+
The line number for the first line (default: ``1``).
|
283 |
+
|
284 |
+
`linenostep`
|
285 |
+
If set to a number n > 1, only every nth line number is printed.
|
286 |
+
|
287 |
+
`linenospecial`
|
288 |
+
If set to a number n > 0, every nth line number is given the CSS
|
289 |
+
class ``"special"`` (default: ``0``).
|
290 |
+
|
291 |
+
`nobackground`
|
292 |
+
If set to ``True``, the formatter won't output the background color
|
293 |
+
for the wrapping element (this automatically defaults to ``False``
|
294 |
+
when there is no wrapping element [eg: no argument for the
|
295 |
+
`get_syntax_defs` method given]) (default: ``False``).
|
296 |
+
|
297 |
+
.. versionadded:: 0.6
|
298 |
+
|
299 |
+
`lineseparator`
|
300 |
+
This string is output between lines of code. It defaults to ``"\n"``,
|
301 |
+
which is enough to break a line inside ``<pre>`` tags, but you can
|
302 |
+
e.g. set it to ``"<br>"`` to get HTML line breaks.
|
303 |
+
|
304 |
+
.. versionadded:: 0.7
|
305 |
+
|
306 |
+
`lineanchors`
|
307 |
+
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
|
308 |
+
output line in an anchor tag with an ``id`` (and `name`) of ``foo-linenumber``.
|
309 |
+
This allows easy linking to certain lines.
|
310 |
+
|
311 |
+
.. versionadded:: 0.9
|
312 |
+
|
313 |
+
`linespans`
|
314 |
+
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
|
315 |
+
output line in a span tag with an ``id`` of ``foo-linenumber``.
|
316 |
+
This allows easy access to lines via javascript.
|
317 |
+
|
318 |
+
.. versionadded:: 1.6
|
319 |
+
|
320 |
+
`anchorlinenos`
|
321 |
+
If set to `True`, will wrap line numbers in <a> tags. Used in
|
322 |
+
combination with `linenos` and `lineanchors`.
|
323 |
+
|
324 |
+
`tagsfile`
|
325 |
+
If set to the path of a ctags file, wrap names in anchor tags that
|
326 |
+
link to their definitions. `lineanchors` should be used, and the
|
327 |
+
tags file should specify line numbers (see the `-n` option to ctags).
|
328 |
+
|
329 |
+
.. versionadded:: 1.6
|
330 |
+
|
331 |
+
`tagurlformat`
|
332 |
+
A string formatting pattern used to generate links to ctags definitions.
|
333 |
+
Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
|
334 |
+
Defaults to an empty string, resulting in just `#prefix-number` links.
|
335 |
+
|
336 |
+
.. versionadded:: 1.6
|
337 |
+
|
338 |
+
`filename`
|
339 |
+
A string used to generate a filename when rendering ``<pre>`` blocks,
|
340 |
+
for example if displaying source code. If `linenos` is set to
|
341 |
+
``'table'`` then the filename will be rendered in an initial row
|
342 |
+
containing a single `<th>` which spans both columns.
|
343 |
+
|
344 |
+
.. versionadded:: 2.1
|
345 |
+
|
346 |
+
`wrapcode`
|
347 |
+
Wrap the code inside ``<pre>`` blocks using ``<code>``, as recommended
|
348 |
+
by the HTML5 specification.
|
349 |
+
|
350 |
+
.. versionadded:: 2.4
|
351 |
+
|
352 |
+
`debug_token_types`
|
353 |
+
Add ``title`` attributes to all token ``<span>`` tags that show the
|
354 |
+
name of the token.
|
355 |
+
|
356 |
+
.. versionadded:: 2.10
|
357 |
+
|
358 |
+
|
359 |
+
**Subclassing the HTML formatter**
|
360 |
+
|
361 |
+
.. versionadded:: 0.7
|
362 |
+
|
363 |
+
The HTML formatter is now built in a way that allows easy subclassing, thus
|
364 |
+
customizing the output HTML code. The `format()` method calls
|
365 |
+
`self._format_lines()` which returns a generator that yields tuples of ``(1,
|
366 |
+
line)``, where the ``1`` indicates that the ``line`` is a line of the
|
367 |
+
formatted source code.
|
368 |
+
|
369 |
+
If the `nowrap` option is set, the generator is the iterated over and the
|
370 |
+
resulting HTML is output.
|
371 |
+
|
372 |
+
Otherwise, `format()` calls `self.wrap()`, which wraps the generator with
|
373 |
+
other generators. These may add some HTML code to the one generated by
|
374 |
+
`_format_lines()`, either by modifying the lines generated by the latter,
|
375 |
+
then yielding them again with ``(1, line)``, and/or by yielding other HTML
|
376 |
+
code before or after the lines, with ``(0, html)``. The distinction between
|
377 |
+
source lines and other code makes it possible to wrap the generator multiple
|
378 |
+
times.
|
379 |
+
|
380 |
+
The default `wrap()` implementation adds a ``<div>`` and a ``<pre>`` tag.
|
381 |
+
|
382 |
+
A custom `HtmlFormatter` subclass could look like this:
|
383 |
+
|
384 |
+
.. sourcecode:: python
|
385 |
+
|
386 |
+
class CodeHtmlFormatter(HtmlFormatter):
|
387 |
+
|
388 |
+
def wrap(self, source, outfile):
|
389 |
+
return self._wrap_code(source)
|
390 |
+
|
391 |
+
def _wrap_code(self, source):
|
392 |
+
yield 0, '<code>'
|
393 |
+
for i, t in source:
|
394 |
+
if i == 1:
|
395 |
+
# it's a line of formatted code
|
396 |
+
t += '<br>'
|
397 |
+
yield i, t
|
398 |
+
yield 0, '</code>'
|
399 |
+
|
400 |
+
This results in wrapping the formatted lines with a ``<code>`` tag, where the
|
401 |
+
source lines are broken using ``<br>`` tags.
|
402 |
+
|
403 |
+
After calling `wrap()`, the `format()` method also adds the "line numbers"
|
404 |
+
and/or "full document" wrappers if the respective options are set. Then, all
|
405 |
+
HTML yielded by the wrapped generator is output.
|
406 |
+
"""
|
407 |
+
|
408 |
+
name = 'HTML'
|
409 |
+
aliases = ['html']
|
410 |
+
filenames = ['*.html', '*.htm']
|
411 |
+
|
412 |
+
def __init__(self, **options):
|
413 |
+
Formatter.__init__(self, **options)
|
414 |
+
self.title = self._decodeifneeded(self.title)
|
415 |
+
self.nowrap = get_bool_opt(options, 'nowrap', False)
|
416 |
+
self.noclasses = get_bool_opt(options, 'noclasses', False)
|
417 |
+
self.classprefix = options.get('classprefix', '')
|
418 |
+
self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
|
419 |
+
self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
|
420 |
+
self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
|
421 |
+
self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
|
422 |
+
self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
|
423 |
+
self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
|
424 |
+
self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
|
425 |
+
self.filename = self._decodeifneeded(options.get('filename', ''))
|
426 |
+
self.wrapcode = get_bool_opt(options, 'wrapcode', False)
|
427 |
+
self.span_element_openers = {}
|
428 |
+
self.debug_token_types = get_bool_opt(options, 'debug_token_types', False)
|
429 |
+
|
430 |
+
if self.tagsfile:
|
431 |
+
if not ctags:
|
432 |
+
raise RuntimeError('The "ctags" package must to be installed '
|
433 |
+
'to be able to use the "tagsfile" feature.')
|
434 |
+
self._ctags = ctags.CTags(self.tagsfile)
|
435 |
+
|
436 |
+
linenos = options.get('linenos', False)
|
437 |
+
if linenos == 'inline':
|
438 |
+
self.linenos = 2
|
439 |
+
elif linenos:
|
440 |
+
# compatibility with <= 0.7
|
441 |
+
self.linenos = 1
|
442 |
+
else:
|
443 |
+
self.linenos = 0
|
444 |
+
self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
|
445 |
+
self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
|
446 |
+
self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
|
447 |
+
self.nobackground = get_bool_opt(options, 'nobackground', False)
|
448 |
+
self.lineseparator = options.get('lineseparator', '\n')
|
449 |
+
self.lineanchors = options.get('lineanchors', '')
|
450 |
+
self.linespans = options.get('linespans', '')
|
451 |
+
self.anchorlinenos = get_bool_opt(options, 'anchorlinenos', False)
|
452 |
+
self.hl_lines = set()
|
453 |
+
for lineno in get_list_opt(options, 'hl_lines', []):
|
454 |
+
try:
|
455 |
+
self.hl_lines.add(int(lineno))
|
456 |
+
except ValueError:
|
457 |
+
pass
|
458 |
+
|
459 |
+
self._create_stylesheet()
|
460 |
+
|
461 |
+
def _get_css_class(self, ttype):
|
462 |
+
"""Return the css class of this token type prefixed with
|
463 |
+
the classprefix option."""
|
464 |
+
ttypeclass = _get_ttype_class(ttype)
|
465 |
+
if ttypeclass:
|
466 |
+
return self.classprefix + ttypeclass
|
467 |
+
return ''
|
468 |
+
|
469 |
+
def _get_css_classes(self, ttype):
|
470 |
+
"""Return the CSS classes of this token type prefixed with the classprefix option."""
|
471 |
+
cls = self._get_css_class(ttype)
|
472 |
+
while ttype not in STANDARD_TYPES:
|
473 |
+
ttype = ttype.parent
|
474 |
+
cls = self._get_css_class(ttype) + ' ' + cls
|
475 |
+
return cls or ''
|
476 |
+
|
477 |
+
def _get_css_inline_styles(self, ttype):
|
478 |
+
"""Return the inline CSS styles for this token type."""
|
479 |
+
cclass = self.ttype2class.get(ttype)
|
480 |
+
while cclass is None:
|
481 |
+
ttype = ttype.parent
|
482 |
+
cclass = self.ttype2class.get(ttype)
|
483 |
+
return cclass or ''
|
484 |
+
|
485 |
+
def _create_stylesheet(self):
|
486 |
+
t2c = self.ttype2class = {Token: ''}
|
487 |
+
c2s = self.class2style = {}
|
488 |
+
for ttype, ndef in self.style:
|
489 |
+
name = self._get_css_class(ttype)
|
490 |
+
style = ''
|
491 |
+
if ndef['color']:
|
492 |
+
style += 'color: %s; ' % webify(ndef['color'])
|
493 |
+
if ndef['bold']:
|
494 |
+
style += 'font-weight: bold; '
|
495 |
+
if ndef['italic']:
|
496 |
+
style += 'font-style: italic; '
|
497 |
+
if ndef['underline']:
|
498 |
+
style += 'text-decoration: underline; '
|
499 |
+
if ndef['bgcolor']:
|
500 |
+
style += 'background-color: %s; ' % webify(ndef['bgcolor'])
|
501 |
+
if ndef['border']:
|
502 |
+
style += 'border: 1px solid %s; ' % webify(ndef['border'])
|
503 |
+
if style:
|
504 |
+
t2c[ttype] = name
|
505 |
+
# save len(ttype) to enable ordering the styles by
|
506 |
+
# hierarchy (necessary for CSS cascading rules!)
|
507 |
+
c2s[name] = (style[:-2], ttype, len(ttype))
|
508 |
+
|
509 |
+
def get_style_defs(self, arg=None):
|
510 |
+
"""
|
511 |
+
Return CSS style definitions for the classes produced by the current
|
512 |
+
highlighting style. ``arg`` can be a string or list of selectors to
|
513 |
+
insert before the token type classes.
|
514 |
+
"""
|
515 |
+
style_lines = []
|
516 |
+
|
517 |
+
style_lines.extend(self.get_linenos_style_defs())
|
518 |
+
style_lines.extend(self.get_background_style_defs(arg))
|
519 |
+
style_lines.extend(self.get_token_style_defs(arg))
|
520 |
+
|
521 |
+
return '\n'.join(style_lines)
|
522 |
+
|
523 |
+
def get_token_style_defs(self, arg=None):
|
524 |
+
prefix = self.get_css_prefix(arg)
|
525 |
+
|
526 |
+
styles = [
|
527 |
+
(level, ttype, cls, style)
|
528 |
+
for cls, (style, ttype, level) in self.class2style.items()
|
529 |
+
if cls and style
|
530 |
+
]
|
531 |
+
styles.sort()
|
532 |
+
|
533 |
+
lines = [
|
534 |
+
'%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
|
535 |
+
for (level, ttype, cls, style) in styles
|
536 |
+
]
|
537 |
+
|
538 |
+
return lines
|
539 |
+
|
540 |
+
def get_background_style_defs(self, arg=None):
|
541 |
+
prefix = self.get_css_prefix(arg)
|
542 |
+
bg_color = self.style.background_color
|
543 |
+
hl_color = self.style.highlight_color
|
544 |
+
|
545 |
+
lines = []
|
546 |
+
|
547 |
+
if arg and not self.nobackground and bg_color is not None:
|
548 |
+
text_style = ''
|
549 |
+
if Text in self.ttype2class:
|
550 |
+
text_style = ' ' + self.class2style[self.ttype2class[Text]][0]
|
551 |
+
lines.insert(
|
552 |
+
0, '%s{ background: %s;%s }' % (
|
553 |
+
prefix(''), bg_color, text_style
|
554 |
+
)
|
555 |
+
)
|
556 |
+
if hl_color is not None:
|
557 |
+
lines.insert(
|
558 |
+
0, '%s { background-color: %s }' % (prefix('hll'), hl_color)
|
559 |
+
)
|
560 |
+
|
561 |
+
return lines
|
562 |
+
|
563 |
+
def get_linenos_style_defs(self):
|
564 |
+
lines = [
|
565 |
+
'pre { %s }' % self._pre_style,
|
566 |
+
'td.linenos .normal { %s }' % self._linenos_style,
|
567 |
+
'span.linenos { %s }' % self._linenos_style,
|
568 |
+
'td.linenos .special { %s }' % self._linenos_special_style,
|
569 |
+
'span.linenos.special { %s }' % self._linenos_special_style,
|
570 |
+
]
|
571 |
+
|
572 |
+
return lines
|
573 |
+
|
574 |
+
def get_css_prefix(self, arg):
|
575 |
+
if arg is None:
|
576 |
+
arg = ('cssclass' in self.options and '.'+self.cssclass or '')
|
577 |
+
if isinstance(arg, str):
|
578 |
+
args = [arg]
|
579 |
+
else:
|
580 |
+
args = list(arg)
|
581 |
+
|
582 |
+
def prefix(cls):
|
583 |
+
if cls:
|
584 |
+
cls = '.' + cls
|
585 |
+
tmp = []
|
586 |
+
for arg in args:
|
587 |
+
tmp.append((arg and arg + ' ' or '') + cls)
|
588 |
+
return ', '.join(tmp)
|
589 |
+
|
590 |
+
return prefix
|
591 |
+
|
592 |
+
@property
|
593 |
+
def _pre_style(self):
|
594 |
+
return 'line-height: 125%;'
|
595 |
+
|
596 |
+
@property
|
597 |
+
def _linenos_style(self):
|
598 |
+
return 'color: %s; background-color: %s; padding-left: 5px; padding-right: 5px;' % (
|
599 |
+
self.style.line_number_color,
|
600 |
+
self.style.line_number_background_color
|
601 |
+
)
|
602 |
+
|
603 |
+
@property
|
604 |
+
def _linenos_special_style(self):
|
605 |
+
return 'color: %s; background-color: %s; padding-left: 5px; padding-right: 5px;' % (
|
606 |
+
self.style.line_number_special_color,
|
607 |
+
self.style.line_number_special_background_color
|
608 |
+
)
|
609 |
+
|
610 |
+
def _decodeifneeded(self, value):
|
611 |
+
if isinstance(value, bytes):
|
612 |
+
if self.encoding:
|
613 |
+
return value.decode(self.encoding)
|
614 |
+
return value.decode()
|
615 |
+
return value
|
616 |
+
|
617 |
+
def _wrap_full(self, inner, outfile):
|
618 |
+
if self.cssfile:
|
619 |
+
if os.path.isabs(self.cssfile):
|
620 |
+
# it's an absolute filename
|
621 |
+
cssfilename = self.cssfile
|
622 |
+
else:
|
623 |
+
try:
|
624 |
+
filename = outfile.name
|
625 |
+
if not filename or filename[0] == '<':
|
626 |
+
# pseudo files, e.g. name == '<fdopen>'
|
627 |
+
raise AttributeError
|
628 |
+
cssfilename = os.path.join(os.path.dirname(filename),
|
629 |
+
self.cssfile)
|
630 |
+
except AttributeError:
|
631 |
+
print('Note: Cannot determine output file name, '
|
632 |
+
'using current directory as base for the CSS file name',
|
633 |
+
file=sys.stderr)
|
634 |
+
cssfilename = self.cssfile
|
635 |
+
# write CSS file only if noclobber_cssfile isn't given as an option.
|
636 |
+
try:
|
637 |
+
if not os.path.exists(cssfilename) or not self.noclobber_cssfile:
|
638 |
+
with open(cssfilename, "w") as cf:
|
639 |
+
cf.write(CSSFILE_TEMPLATE %
|
640 |
+
{'styledefs': self.get_style_defs('body')})
|
641 |
+
except OSError as err:
|
642 |
+
err.strerror = 'Error writing CSS file: ' + err.strerror
|
643 |
+
raise
|
644 |
+
|
645 |
+
yield 0, (DOC_HEADER_EXTERNALCSS %
|
646 |
+
dict(title=self.title,
|
647 |
+
cssfile=self.cssfile,
|
648 |
+
encoding=self.encoding))
|
649 |
+
else:
|
650 |
+
yield 0, (DOC_HEADER %
|
651 |
+
dict(title=self.title,
|
652 |
+
styledefs=self.get_style_defs('body'),
|
653 |
+
encoding=self.encoding))
|
654 |
+
|
655 |
+
yield from inner
|
656 |
+
yield 0, DOC_FOOTER
|
657 |
+
|
658 |
+
def _wrap_tablelinenos(self, inner):
|
659 |
+
dummyoutfile = StringIO()
|
660 |
+
lncount = 0
|
661 |
+
for t, line in inner:
|
662 |
+
if t:
|
663 |
+
lncount += 1
|
664 |
+
dummyoutfile.write(line)
|
665 |
+
|
666 |
+
fl = self.linenostart
|
667 |
+
mw = len(str(lncount + fl - 1))
|
668 |
+
sp = self.linenospecial
|
669 |
+
st = self.linenostep
|
670 |
+
la = self.lineanchors
|
671 |
+
aln = self.anchorlinenos
|
672 |
+
nocls = self.noclasses
|
673 |
+
|
674 |
+
lines = []
|
675 |
+
|
676 |
+
for i in range(fl, fl+lncount):
|
677 |
+
print_line = i % st == 0
|
678 |
+
special_line = sp and i % sp == 0
|
679 |
+
|
680 |
+
if print_line:
|
681 |
+
line = '%*d' % (mw, i)
|
682 |
+
if aln:
|
683 |
+
line = '<a href="#%s-%d">%s</a>' % (la, i, line)
|
684 |
+
else:
|
685 |
+
line = ' ' * mw
|
686 |
+
|
687 |
+
if nocls:
|
688 |
+
if special_line:
|
689 |
+
style = ' style="%s"' % self._linenos_special_style
|
690 |
+
else:
|
691 |
+
style = ' style="%s"' % self._linenos_style
|
692 |
+
else:
|
693 |
+
if special_line:
|
694 |
+
style = ' class="special"'
|
695 |
+
else:
|
696 |
+
style = ' class="normal"'
|
697 |
+
|
698 |
+
if style:
|
699 |
+
line = '<span%s>%s</span>' % (style, line)
|
700 |
+
|
701 |
+
lines.append(line)
|
702 |
+
|
703 |
+
ls = '\n'.join(lines)
|
704 |
+
|
705 |
+
# If a filename was specified, we can't put it into the code table as it
|
706 |
+
# would misalign the line numbers. Hence we emit a separate row for it.
|
707 |
+
filename_tr = ""
|
708 |
+
if self.filename:
|
709 |
+
filename_tr = (
|
710 |
+
'<tr><th colspan="2" class="filename"><div class="highlight">'
|
711 |
+
'<span class="filename">' + self.filename + '</span></div>'
|
712 |
+
'</th></tr>')
|
713 |
+
|
714 |
+
# in case you wonder about the seemingly redundant <div> here: since the
|
715 |
+
# content in the other cell also is wrapped in a div, some browsers in
|
716 |
+
# some configurations seem to mess up the formatting...
|
717 |
+
yield 0, (
|
718 |
+
'<table class="%stable">' % self.cssclass + filename_tr +
|
719 |
+
'<tr><td class="linenos"><div class="linenodiv"><pre>' +
|
720 |
+
ls + '</pre></div></td><td class="code">'
|
721 |
+
)
|
722 |
+
yield 0, dummyoutfile.getvalue()
|
723 |
+
yield 0, '</td></tr></table>'
|
724 |
+
|
725 |
+
def _wrap_inlinelinenos(self, inner):
|
726 |
+
# need a list of lines since we need the width of a single number :(
|
727 |
+
inner_lines = list(inner)
|
728 |
+
sp = self.linenospecial
|
729 |
+
st = self.linenostep
|
730 |
+
num = self.linenostart
|
731 |
+
mw = len(str(len(inner_lines) + num - 1))
|
732 |
+
la = self.lineanchors
|
733 |
+
aln = self.anchorlinenos
|
734 |
+
nocls = self.noclasses
|
735 |
+
|
736 |
+
for _, inner_line in inner_lines:
|
737 |
+
print_line = num % st == 0
|
738 |
+
special_line = sp and num % sp == 0
|
739 |
+
|
740 |
+
if print_line:
|
741 |
+
line = '%*d' % (mw, num)
|
742 |
+
else:
|
743 |
+
line = ' ' * mw
|
744 |
+
|
745 |
+
if nocls:
|
746 |
+
if special_line:
|
747 |
+
style = ' style="%s"' % self._linenos_special_style
|
748 |
+
else:
|
749 |
+
style = ' style="%s"' % self._linenos_style
|
750 |
+
else:
|
751 |
+
if special_line:
|
752 |
+
style = ' class="linenos special"'
|
753 |
+
else:
|
754 |
+
style = ' class="linenos"'
|
755 |
+
|
756 |
+
if style:
|
757 |
+
linenos = '<span%s>%s</span>' % (style, line)
|
758 |
+
else:
|
759 |
+
linenos = line
|
760 |
+
|
761 |
+
if aln:
|
762 |
+
yield 1, ('<a href="#%s-%d">%s</a>' % (la, num, linenos) +
|
763 |
+
inner_line)
|
764 |
+
else:
|
765 |
+
yield 1, linenos + inner_line
|
766 |
+
num += 1
|
767 |
+
|
768 |
+
def _wrap_lineanchors(self, inner):
|
769 |
+
s = self.lineanchors
|
770 |
+
# subtract 1 since we have to increment i *before* yielding
|
771 |
+
i = self.linenostart - 1
|
772 |
+
for t, line in inner:
|
773 |
+
if t:
|
774 |
+
i += 1
|
775 |
+
href = "" if self.linenos else ' href="#%s-%d"' % (s, i)
|
776 |
+
yield 1, '<a id="%s-%d" name="%s-%d"%s></a>' % (s, i, s, i, href) + line
|
777 |
+
else:
|
778 |
+
yield 0, line
|
779 |
+
|
780 |
+
def _wrap_linespans(self, inner):
|
781 |
+
s = self.linespans
|
782 |
+
i = self.linenostart - 1
|
783 |
+
for t, line in inner:
|
784 |
+
if t:
|
785 |
+
i += 1
|
786 |
+
yield 1, '<span id="%s-%d">%s</span>' % (s, i, line)
|
787 |
+
else:
|
788 |
+
yield 0, line
|
789 |
+
|
790 |
+
def _wrap_div(self, inner):
|
791 |
+
style = []
|
792 |
+
if (self.noclasses and not self.nobackground and
|
793 |
+
self.style.background_color is not None):
|
794 |
+
style.append('background: %s' % (self.style.background_color,))
|
795 |
+
if self.cssstyles:
|
796 |
+
style.append(self.cssstyles)
|
797 |
+
style = '; '.join(style)
|
798 |
+
|
799 |
+
yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) +
|
800 |
+
(style and (' style="%s"' % style)) + '>')
|
801 |
+
yield from inner
|
802 |
+
yield 0, '</div>\n'
|
803 |
+
|
804 |
+
def _wrap_pre(self, inner):
|
805 |
+
style = []
|
806 |
+
if self.prestyles:
|
807 |
+
style.append(self.prestyles)
|
808 |
+
if self.noclasses:
|
809 |
+
style.append(self._pre_style)
|
810 |
+
style = '; '.join(style)
|
811 |
+
|
812 |
+
if self.filename and self.linenos != 1:
|
813 |
+
yield 0, ('<span class="filename">' + self.filename + '</span>')
|
814 |
+
|
815 |
+
# the empty span here is to keep leading empty lines from being
|
816 |
+
# ignored by HTML parsers
|
817 |
+
yield 0, ('<pre' + (style and ' style="%s"' % style) + '><span></span>')
|
818 |
+
yield from inner
|
819 |
+
yield 0, '</pre>'
|
820 |
+
|
821 |
+
def _wrap_code(self, inner):
|
822 |
+
yield 0, '<code>'
|
823 |
+
yield from inner
|
824 |
+
yield 0, '</code>'
|
825 |
+
|
826 |
+
@functools.lru_cache(maxsize=100)
|
827 |
+
def _translate_parts(self, value):
|
828 |
+
"""HTML-escape a value and split it by newlines."""
|
829 |
+
return value.translate(_escape_html_table).split('\n')
|
830 |
+
|
831 |
+
def _format_lines(self, tokensource):
|
832 |
+
"""
|
833 |
+
Just format the tokens, without any wrapping tags.
|
834 |
+
Yield individual lines.
|
835 |
+
"""
|
836 |
+
nocls = self.noclasses
|
837 |
+
lsep = self.lineseparator
|
838 |
+
tagsfile = self.tagsfile
|
839 |
+
|
840 |
+
lspan = ''
|
841 |
+
line = []
|
842 |
+
for ttype, value in tokensource:
|
843 |
+
try:
|
844 |
+
cspan = self.span_element_openers[ttype]
|
845 |
+
except KeyError:
|
846 |
+
title = ' title="%s"' % '.'.join(ttype) if self.debug_token_types else ''
|
847 |
+
if nocls:
|
848 |
+
css_style = self._get_css_inline_styles(ttype)
|
849 |
+
if css_style:
|
850 |
+
css_style = self.class2style[css_style][0]
|
851 |
+
cspan = '<span style="%s"%s>' % (css_style, title)
|
852 |
+
else:
|
853 |
+
cspan = ''
|
854 |
+
else:
|
855 |
+
css_class = self._get_css_classes(ttype)
|
856 |
+
if css_class:
|
857 |
+
cspan = '<span class="%s"%s>' % (css_class, title)
|
858 |
+
else:
|
859 |
+
cspan = ''
|
860 |
+
self.span_element_openers[ttype] = cspan
|
861 |
+
|
862 |
+
parts = self._translate_parts(value)
|
863 |
+
|
864 |
+
if tagsfile and ttype in Token.Name:
|
865 |
+
filename, linenumber = self._lookup_ctag(value)
|
866 |
+
if linenumber:
|
867 |
+
base, filename = os.path.split(filename)
|
868 |
+
if base:
|
869 |
+
base += '/'
|
870 |
+
filename, extension = os.path.splitext(filename)
|
871 |
+
url = self.tagurlformat % {'path': base, 'fname': filename,
|
872 |
+
'fext': extension}
|
873 |
+
parts[0] = "<a href=\"%s#%s-%d\">%s" % \
|
874 |
+
(url, self.lineanchors, linenumber, parts[0])
|
875 |
+
parts[-1] = parts[-1] + "</a>"
|
876 |
+
|
877 |
+
# for all but the last line
|
878 |
+
for part in parts[:-1]:
|
879 |
+
if line:
|
880 |
+
if lspan != cspan:
|
881 |
+
line.extend(((lspan and '</span>'), cspan, part,
|
882 |
+
(cspan and '</span>'), lsep))
|
883 |
+
else: # both are the same
|
884 |
+
line.extend((part, (lspan and '</span>'), lsep))
|
885 |
+
yield 1, ''.join(line)
|
886 |
+
line = []
|
887 |
+
elif part:
|
888 |
+
yield 1, ''.join((cspan, part, (cspan and '</span>'), lsep))
|
889 |
+
else:
|
890 |
+
yield 1, lsep
|
891 |
+
# for the last line
|
892 |
+
if line and parts[-1]:
|
893 |
+
if lspan != cspan:
|
894 |
+
line.extend(((lspan and '</span>'), cspan, parts[-1]))
|
895 |
+
lspan = cspan
|
896 |
+
else:
|
897 |
+
line.append(parts[-1])
|
898 |
+
elif parts[-1]:
|
899 |
+
line = [cspan, parts[-1]]
|
900 |
+
lspan = cspan
|
901 |
+
# else we neither have to open a new span nor set lspan
|
902 |
+
|
903 |
+
if line:
|
904 |
+
line.extend(((lspan and '</span>'), lsep))
|
905 |
+
yield 1, ''.join(line)
|
906 |
+
|
907 |
+
def _lookup_ctag(self, token):
|
908 |
+
entry = ctags.TagEntry()
|
909 |
+
if self._ctags.find(entry, token.encode(), 0):
|
910 |
+
return entry['file'], entry['lineNumber']
|
911 |
+
else:
|
912 |
+
return None, None
|
913 |
+
|
914 |
+
def _highlight_lines(self, tokensource):
|
915 |
+
"""
|
916 |
+
Highlighted the lines specified in the `hl_lines` option by
|
917 |
+
post-processing the token stream coming from `_format_lines`.
|
918 |
+
"""
|
919 |
+
hls = self.hl_lines
|
920 |
+
|
921 |
+
for i, (t, value) in enumerate(tokensource):
|
922 |
+
if t != 1:
|
923 |
+
yield t, value
|
924 |
+
if i + 1 in hls: # i + 1 because Python indexes start at 0
|
925 |
+
if self.noclasses:
|
926 |
+
style = ''
|
927 |
+
if self.style.highlight_color is not None:
|
928 |
+
style = (' style="background-color: %s"' %
|
929 |
+
(self.style.highlight_color,))
|
930 |
+
yield 1, '<span%s>%s</span>' % (style, value)
|
931 |
+
else:
|
932 |
+
yield 1, '<span class="hll">%s</span>' % value
|
933 |
+
else:
|
934 |
+
yield 1, value
|
935 |
+
|
936 |
+
def wrap(self, source, outfile):
|
937 |
+
"""
|
938 |
+
Wrap the ``source``, which is a generator yielding
|
939 |
+
individual lines, in custom generators. See docstring
|
940 |
+
for `format`. Can be overridden.
|
941 |
+
"""
|
942 |
+
if self.wrapcode:
|
943 |
+
return self._wrap_div(self._wrap_pre(self._wrap_code(source)))
|
944 |
+
else:
|
945 |
+
return self._wrap_div(self._wrap_pre(source))
|
946 |
+
|
947 |
+
def format_unencoded(self, tokensource, outfile):
|
948 |
+
"""
|
949 |
+
The formatting process uses several nested generators; which of
|
950 |
+
them are used is determined by the user's options.
|
951 |
+
|
952 |
+
Each generator should take at least one argument, ``inner``,
|
953 |
+
and wrap the pieces of text generated by this.
|
954 |
+
|
955 |
+
Always yield 2-tuples: (code, text). If "code" is 1, the text
|
956 |
+
is part of the original tokensource being highlighted, if it's
|
957 |
+
0, the text is some piece of wrapping. This makes it possible to
|
958 |
+
use several different wrappers that process the original source
|
959 |
+
linewise, e.g. line number generators.
|
960 |
+
"""
|
961 |
+
source = self._format_lines(tokensource)
|
962 |
+
|
963 |
+
# As a special case, we wrap line numbers before line highlighting
|
964 |
+
# so the line numbers get wrapped in the highlighting tag.
|
965 |
+
if not self.nowrap and self.linenos == 2:
|
966 |
+
source = self._wrap_inlinelinenos(source)
|
967 |
+
|
968 |
+
if self.hl_lines:
|
969 |
+
source = self._highlight_lines(source)
|
970 |
+
|
971 |
+
if not self.nowrap:
|
972 |
+
if self.lineanchors:
|
973 |
+
source = self._wrap_lineanchors(source)
|
974 |
+
if self.linespans:
|
975 |
+
source = self._wrap_linespans(source)
|
976 |
+
source = self.wrap(source, outfile)
|
977 |
+
if self.linenos == 1:
|
978 |
+
source = self._wrap_tablelinenos(source)
|
979 |
+
if self.full:
|
980 |
+
source = self._wrap_full(source, outfile)
|
981 |
+
|
982 |
+
for t, piece in source:
|
983 |
+
outfile.write(piece)
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/img.py
ADDED
@@ -0,0 +1,641 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.img
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for Pixmap output.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
import os
|
12 |
+
import sys
|
13 |
+
|
14 |
+
from pip._vendor.pygments.formatter import Formatter
|
15 |
+
from pip._vendor.pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
|
16 |
+
get_choice_opt
|
17 |
+
|
18 |
+
import subprocess
|
19 |
+
|
20 |
+
# Import this carefully
|
21 |
+
try:
|
22 |
+
from PIL import Image, ImageDraw, ImageFont
|
23 |
+
pil_available = True
|
24 |
+
except ImportError:
|
25 |
+
pil_available = False
|
26 |
+
|
27 |
+
try:
|
28 |
+
import _winreg
|
29 |
+
except ImportError:
|
30 |
+
try:
|
31 |
+
import winreg as _winreg
|
32 |
+
except ImportError:
|
33 |
+
_winreg = None
|
34 |
+
|
35 |
+
__all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
|
36 |
+
'BmpImageFormatter']
|
37 |
+
|
38 |
+
|
39 |
+
# For some unknown reason every font calls it something different
|
40 |
+
STYLES = {
|
41 |
+
'NORMAL': ['', 'Roman', 'Book', 'Normal', 'Regular', 'Medium'],
|
42 |
+
'ITALIC': ['Oblique', 'Italic'],
|
43 |
+
'BOLD': ['Bold'],
|
44 |
+
'BOLDITALIC': ['Bold Oblique', 'Bold Italic'],
|
45 |
+
}
|
46 |
+
|
47 |
+
# A sane default for modern systems
|
48 |
+
DEFAULT_FONT_NAME_NIX = 'DejaVu Sans Mono'
|
49 |
+
DEFAULT_FONT_NAME_WIN = 'Courier New'
|
50 |
+
DEFAULT_FONT_NAME_MAC = 'Menlo'
|
51 |
+
|
52 |
+
|
53 |
+
class PilNotAvailable(ImportError):
|
54 |
+
"""When Python imaging library is not available"""
|
55 |
+
|
56 |
+
|
57 |
+
class FontNotFound(Exception):
|
58 |
+
"""When there are no usable fonts specified"""
|
59 |
+
|
60 |
+
|
61 |
+
class FontManager:
|
62 |
+
"""
|
63 |
+
Manages a set of fonts: normal, italic, bold, etc...
|
64 |
+
"""
|
65 |
+
|
66 |
+
def __init__(self, font_name, font_size=14):
|
67 |
+
self.font_name = font_name
|
68 |
+
self.font_size = font_size
|
69 |
+
self.fonts = {}
|
70 |
+
self.encoding = None
|
71 |
+
if sys.platform.startswith('win'):
|
72 |
+
if not font_name:
|
73 |
+
self.font_name = DEFAULT_FONT_NAME_WIN
|
74 |
+
self._create_win()
|
75 |
+
elif sys.platform.startswith('darwin'):
|
76 |
+
if not font_name:
|
77 |
+
self.font_name = DEFAULT_FONT_NAME_MAC
|
78 |
+
self._create_mac()
|
79 |
+
else:
|
80 |
+
if not font_name:
|
81 |
+
self.font_name = DEFAULT_FONT_NAME_NIX
|
82 |
+
self._create_nix()
|
83 |
+
|
84 |
+
def _get_nix_font_path(self, name, style):
|
85 |
+
proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'],
|
86 |
+
stdout=subprocess.PIPE, stderr=None)
|
87 |
+
stdout, _ = proc.communicate()
|
88 |
+
if proc.returncode == 0:
|
89 |
+
lines = stdout.splitlines()
|
90 |
+
for line in lines:
|
91 |
+
if line.startswith(b'Fontconfig warning:'):
|
92 |
+
continue
|
93 |
+
path = line.decode().strip().strip(':')
|
94 |
+
if path:
|
95 |
+
return path
|
96 |
+
return None
|
97 |
+
|
98 |
+
def _create_nix(self):
|
99 |
+
for name in STYLES['NORMAL']:
|
100 |
+
path = self._get_nix_font_path(self.font_name, name)
|
101 |
+
if path is not None:
|
102 |
+
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
103 |
+
break
|
104 |
+
else:
|
105 |
+
raise FontNotFound('No usable fonts named: "%s"' %
|
106 |
+
self.font_name)
|
107 |
+
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
108 |
+
for stylename in STYLES[style]:
|
109 |
+
path = self._get_nix_font_path(self.font_name, stylename)
|
110 |
+
if path is not None:
|
111 |
+
self.fonts[style] = ImageFont.truetype(path, self.font_size)
|
112 |
+
break
|
113 |
+
else:
|
114 |
+
if style == 'BOLDITALIC':
|
115 |
+
self.fonts[style] = self.fonts['BOLD']
|
116 |
+
else:
|
117 |
+
self.fonts[style] = self.fonts['NORMAL']
|
118 |
+
|
119 |
+
def _get_mac_font_path(self, font_map, name, style):
|
120 |
+
return font_map.get((name + ' ' + style).strip().lower())
|
121 |
+
|
122 |
+
def _create_mac(self):
|
123 |
+
font_map = {}
|
124 |
+
for font_dir in (os.path.join(os.getenv("HOME"), 'Library/Fonts/'),
|
125 |
+
'/Library/Fonts/', '/System/Library/Fonts/'):
|
126 |
+
font_map.update(
|
127 |
+
(os.path.splitext(f)[0].lower(), os.path.join(font_dir, f))
|
128 |
+
for f in os.listdir(font_dir)
|
129 |
+
if f.lower().endswith(('ttf', 'ttc')))
|
130 |
+
|
131 |
+
for name in STYLES['NORMAL']:
|
132 |
+
path = self._get_mac_font_path(font_map, self.font_name, name)
|
133 |
+
if path is not None:
|
134 |
+
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
135 |
+
break
|
136 |
+
else:
|
137 |
+
raise FontNotFound('No usable fonts named: "%s"' %
|
138 |
+
self.font_name)
|
139 |
+
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
140 |
+
for stylename in STYLES[style]:
|
141 |
+
path = self._get_mac_font_path(font_map, self.font_name, stylename)
|
142 |
+
if path is not None:
|
143 |
+
self.fonts[style] = ImageFont.truetype(path, self.font_size)
|
144 |
+
break
|
145 |
+
else:
|
146 |
+
if style == 'BOLDITALIC':
|
147 |
+
self.fonts[style] = self.fonts['BOLD']
|
148 |
+
else:
|
149 |
+
self.fonts[style] = self.fonts['NORMAL']
|
150 |
+
|
151 |
+
def _lookup_win(self, key, basename, styles, fail=False):
|
152 |
+
for suffix in ('', ' (TrueType)'):
|
153 |
+
for style in styles:
|
154 |
+
try:
|
155 |
+
valname = '%s%s%s' % (basename, style and ' '+style, suffix)
|
156 |
+
val, _ = _winreg.QueryValueEx(key, valname)
|
157 |
+
return val
|
158 |
+
except OSError:
|
159 |
+
continue
|
160 |
+
else:
|
161 |
+
if fail:
|
162 |
+
raise FontNotFound('Font %s (%s) not found in registry' %
|
163 |
+
(basename, styles[0]))
|
164 |
+
return None
|
165 |
+
|
166 |
+
def _create_win(self):
|
167 |
+
lookuperror = None
|
168 |
+
keynames = [ (_winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows NT\CurrentVersion\Fonts'),
|
169 |
+
(_winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Fonts'),
|
170 |
+
(_winreg.HKEY_LOCAL_MACHINE, r'Software\Microsoft\Windows NT\CurrentVersion\Fonts'),
|
171 |
+
(_winreg.HKEY_LOCAL_MACHINE, r'Software\Microsoft\Windows\CurrentVersion\Fonts') ]
|
172 |
+
for keyname in keynames:
|
173 |
+
try:
|
174 |
+
key = _winreg.OpenKey(*keyname)
|
175 |
+
try:
|
176 |
+
path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
|
177 |
+
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
178 |
+
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
179 |
+
path = self._lookup_win(key, self.font_name, STYLES[style])
|
180 |
+
if path:
|
181 |
+
self.fonts[style] = ImageFont.truetype(path, self.font_size)
|
182 |
+
else:
|
183 |
+
if style == 'BOLDITALIC':
|
184 |
+
self.fonts[style] = self.fonts['BOLD']
|
185 |
+
else:
|
186 |
+
self.fonts[style] = self.fonts['NORMAL']
|
187 |
+
return
|
188 |
+
except FontNotFound as err:
|
189 |
+
lookuperror = err
|
190 |
+
finally:
|
191 |
+
_winreg.CloseKey(key)
|
192 |
+
except OSError:
|
193 |
+
pass
|
194 |
+
else:
|
195 |
+
# If we get here, we checked all registry keys and had no luck
|
196 |
+
# We can be in one of two situations now:
|
197 |
+
# * All key lookups failed. In this case lookuperror is None and we
|
198 |
+
# will raise a generic error
|
199 |
+
# * At least one lookup failed with a FontNotFound error. In this
|
200 |
+
# case, we will raise that as a more specific error
|
201 |
+
if lookuperror:
|
202 |
+
raise lookuperror
|
203 |
+
raise FontNotFound('Can\'t open Windows font registry key')
|
204 |
+
|
205 |
+
def get_char_size(self):
|
206 |
+
"""
|
207 |
+
Get the character size.
|
208 |
+
"""
|
209 |
+
return self.fonts['NORMAL'].getsize('M')
|
210 |
+
|
211 |
+
def get_text_size(self, text):
|
212 |
+
"""
|
213 |
+
Get the text size(width, height).
|
214 |
+
"""
|
215 |
+
return self.fonts['NORMAL'].getsize(text)
|
216 |
+
|
217 |
+
def get_font(self, bold, oblique):
|
218 |
+
"""
|
219 |
+
Get the font based on bold and italic flags.
|
220 |
+
"""
|
221 |
+
if bold and oblique:
|
222 |
+
return self.fonts['BOLDITALIC']
|
223 |
+
elif bold:
|
224 |
+
return self.fonts['BOLD']
|
225 |
+
elif oblique:
|
226 |
+
return self.fonts['ITALIC']
|
227 |
+
else:
|
228 |
+
return self.fonts['NORMAL']
|
229 |
+
|
230 |
+
|
231 |
+
class ImageFormatter(Formatter):
|
232 |
+
"""
|
233 |
+
Create a PNG image from source code. This uses the Python Imaging Library to
|
234 |
+
generate a pixmap from the source code.
|
235 |
+
|
236 |
+
.. versionadded:: 0.10
|
237 |
+
|
238 |
+
Additional options accepted:
|
239 |
+
|
240 |
+
`image_format`
|
241 |
+
An image format to output to that is recognised by PIL, these include:
|
242 |
+
|
243 |
+
* "PNG" (default)
|
244 |
+
* "JPEG"
|
245 |
+
* "BMP"
|
246 |
+
* "GIF"
|
247 |
+
|
248 |
+
`line_pad`
|
249 |
+
The extra spacing (in pixels) between each line of text.
|
250 |
+
|
251 |
+
Default: 2
|
252 |
+
|
253 |
+
`font_name`
|
254 |
+
The font name to be used as the base font from which others, such as
|
255 |
+
bold and italic fonts will be generated. This really should be a
|
256 |
+
monospace font to look sane.
|
257 |
+
|
258 |
+
Default: "Courier New" on Windows, "Menlo" on Mac OS, and
|
259 |
+
"DejaVu Sans Mono" on \\*nix
|
260 |
+
|
261 |
+
`font_size`
|
262 |
+
The font size in points to be used.
|
263 |
+
|
264 |
+
Default: 14
|
265 |
+
|
266 |
+
`image_pad`
|
267 |
+
The padding, in pixels to be used at each edge of the resulting image.
|
268 |
+
|
269 |
+
Default: 10
|
270 |
+
|
271 |
+
`line_numbers`
|
272 |
+
Whether line numbers should be shown: True/False
|
273 |
+
|
274 |
+
Default: True
|
275 |
+
|
276 |
+
`line_number_start`
|
277 |
+
The line number of the first line.
|
278 |
+
|
279 |
+
Default: 1
|
280 |
+
|
281 |
+
`line_number_step`
|
282 |
+
The step used when printing line numbers.
|
283 |
+
|
284 |
+
Default: 1
|
285 |
+
|
286 |
+
`line_number_bg`
|
287 |
+
The background colour (in "#123456" format) of the line number bar, or
|
288 |
+
None to use the style background color.
|
289 |
+
|
290 |
+
Default: "#eed"
|
291 |
+
|
292 |
+
`line_number_fg`
|
293 |
+
The text color of the line numbers (in "#123456"-like format).
|
294 |
+
|
295 |
+
Default: "#886"
|
296 |
+
|
297 |
+
`line_number_chars`
|
298 |
+
The number of columns of line numbers allowable in the line number
|
299 |
+
margin.
|
300 |
+
|
301 |
+
Default: 2
|
302 |
+
|
303 |
+
`line_number_bold`
|
304 |
+
Whether line numbers will be bold: True/False
|
305 |
+
|
306 |
+
Default: False
|
307 |
+
|
308 |
+
`line_number_italic`
|
309 |
+
Whether line numbers will be italicized: True/False
|
310 |
+
|
311 |
+
Default: False
|
312 |
+
|
313 |
+
`line_number_separator`
|
314 |
+
Whether a line will be drawn between the line number area and the
|
315 |
+
source code area: True/False
|
316 |
+
|
317 |
+
Default: True
|
318 |
+
|
319 |
+
`line_number_pad`
|
320 |
+
The horizontal padding (in pixels) between the line number margin, and
|
321 |
+
the source code area.
|
322 |
+
|
323 |
+
Default: 6
|
324 |
+
|
325 |
+
`hl_lines`
|
326 |
+
Specify a list of lines to be highlighted.
|
327 |
+
|
328 |
+
.. versionadded:: 1.2
|
329 |
+
|
330 |
+
Default: empty list
|
331 |
+
|
332 |
+
`hl_color`
|
333 |
+
Specify the color for highlighting lines.
|
334 |
+
|
335 |
+
.. versionadded:: 1.2
|
336 |
+
|
337 |
+
Default: highlight color of the selected style
|
338 |
+
"""
|
339 |
+
|
340 |
+
# Required by the pygments mapper
|
341 |
+
name = 'img'
|
342 |
+
aliases = ['img', 'IMG', 'png']
|
343 |
+
filenames = ['*.png']
|
344 |
+
|
345 |
+
unicodeoutput = False
|
346 |
+
|
347 |
+
default_image_format = 'png'
|
348 |
+
|
349 |
+
def __init__(self, **options):
|
350 |
+
"""
|
351 |
+
See the class docstring for explanation of options.
|
352 |
+
"""
|
353 |
+
if not pil_available:
|
354 |
+
raise PilNotAvailable(
|
355 |
+
'Python Imaging Library is required for this formatter')
|
356 |
+
Formatter.__init__(self, **options)
|
357 |
+
self.encoding = 'latin1' # let pygments.format() do the right thing
|
358 |
+
# Read the style
|
359 |
+
self.styles = dict(self.style)
|
360 |
+
if self.style.background_color is None:
|
361 |
+
self.background_color = '#fff'
|
362 |
+
else:
|
363 |
+
self.background_color = self.style.background_color
|
364 |
+
# Image options
|
365 |
+
self.image_format = get_choice_opt(
|
366 |
+
options, 'image_format', ['png', 'jpeg', 'gif', 'bmp'],
|
367 |
+
self.default_image_format, normcase=True)
|
368 |
+
self.image_pad = get_int_opt(options, 'image_pad', 10)
|
369 |
+
self.line_pad = get_int_opt(options, 'line_pad', 2)
|
370 |
+
# The fonts
|
371 |
+
fontsize = get_int_opt(options, 'font_size', 14)
|
372 |
+
self.fonts = FontManager(options.get('font_name', ''), fontsize)
|
373 |
+
self.fontw, self.fonth = self.fonts.get_char_size()
|
374 |
+
# Line number options
|
375 |
+
self.line_number_fg = options.get('line_number_fg', '#886')
|
376 |
+
self.line_number_bg = options.get('line_number_bg', '#eed')
|
377 |
+
self.line_number_chars = get_int_opt(options,
|
378 |
+
'line_number_chars', 2)
|
379 |
+
self.line_number_bold = get_bool_opt(options,
|
380 |
+
'line_number_bold', False)
|
381 |
+
self.line_number_italic = get_bool_opt(options,
|
382 |
+
'line_number_italic', False)
|
383 |
+
self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
|
384 |
+
self.line_numbers = get_bool_opt(options, 'line_numbers', True)
|
385 |
+
self.line_number_separator = get_bool_opt(options,
|
386 |
+
'line_number_separator', True)
|
387 |
+
self.line_number_step = get_int_opt(options, 'line_number_step', 1)
|
388 |
+
self.line_number_start = get_int_opt(options, 'line_number_start', 1)
|
389 |
+
if self.line_numbers:
|
390 |
+
self.line_number_width = (self.fontw * self.line_number_chars +
|
391 |
+
self.line_number_pad * 2)
|
392 |
+
else:
|
393 |
+
self.line_number_width = 0
|
394 |
+
self.hl_lines = []
|
395 |
+
hl_lines_str = get_list_opt(options, 'hl_lines', [])
|
396 |
+
for line in hl_lines_str:
|
397 |
+
try:
|
398 |
+
self.hl_lines.append(int(line))
|
399 |
+
except ValueError:
|
400 |
+
pass
|
401 |
+
self.hl_color = options.get('hl_color',
|
402 |
+
self.style.highlight_color) or '#f90'
|
403 |
+
self.drawables = []
|
404 |
+
|
405 |
+
def get_style_defs(self, arg=''):
|
406 |
+
raise NotImplementedError('The -S option is meaningless for the image '
|
407 |
+
'formatter. Use -O style=<stylename> instead.')
|
408 |
+
|
409 |
+
def _get_line_height(self):
|
410 |
+
"""
|
411 |
+
Get the height of a line.
|
412 |
+
"""
|
413 |
+
return self.fonth + self.line_pad
|
414 |
+
|
415 |
+
def _get_line_y(self, lineno):
|
416 |
+
"""
|
417 |
+
Get the Y coordinate of a line number.
|
418 |
+
"""
|
419 |
+
return lineno * self._get_line_height() + self.image_pad
|
420 |
+
|
421 |
+
def _get_char_width(self):
|
422 |
+
"""
|
423 |
+
Get the width of a character.
|
424 |
+
"""
|
425 |
+
return self.fontw
|
426 |
+
|
427 |
+
def _get_char_x(self, linelength):
|
428 |
+
"""
|
429 |
+
Get the X coordinate of a character position.
|
430 |
+
"""
|
431 |
+
return linelength + self.image_pad + self.line_number_width
|
432 |
+
|
433 |
+
def _get_text_pos(self, linelength, lineno):
|
434 |
+
"""
|
435 |
+
Get the actual position for a character and line position.
|
436 |
+
"""
|
437 |
+
return self._get_char_x(linelength), self._get_line_y(lineno)
|
438 |
+
|
439 |
+
def _get_linenumber_pos(self, lineno):
|
440 |
+
"""
|
441 |
+
Get the actual position for the start of a line number.
|
442 |
+
"""
|
443 |
+
return (self.image_pad, self._get_line_y(lineno))
|
444 |
+
|
445 |
+
def _get_text_color(self, style):
|
446 |
+
"""
|
447 |
+
Get the correct color for the token from the style.
|
448 |
+
"""
|
449 |
+
if style['color'] is not None:
|
450 |
+
fill = '#' + style['color']
|
451 |
+
else:
|
452 |
+
fill = '#000'
|
453 |
+
return fill
|
454 |
+
|
455 |
+
def _get_text_bg_color(self, style):
|
456 |
+
"""
|
457 |
+
Get the correct background color for the token from the style.
|
458 |
+
"""
|
459 |
+
if style['bgcolor'] is not None:
|
460 |
+
bg_color = '#' + style['bgcolor']
|
461 |
+
else:
|
462 |
+
bg_color = None
|
463 |
+
return bg_color
|
464 |
+
|
465 |
+
def _get_style_font(self, style):
|
466 |
+
"""
|
467 |
+
Get the correct font for the style.
|
468 |
+
"""
|
469 |
+
return self.fonts.get_font(style['bold'], style['italic'])
|
470 |
+
|
471 |
+
def _get_image_size(self, maxlinelength, maxlineno):
|
472 |
+
"""
|
473 |
+
Get the required image size.
|
474 |
+
"""
|
475 |
+
return (self._get_char_x(maxlinelength) + self.image_pad,
|
476 |
+
self._get_line_y(maxlineno + 0) + self.image_pad)
|
477 |
+
|
478 |
+
def _draw_linenumber(self, posno, lineno):
|
479 |
+
"""
|
480 |
+
Remember a line number drawable to paint later.
|
481 |
+
"""
|
482 |
+
self._draw_text(
|
483 |
+
self._get_linenumber_pos(posno),
|
484 |
+
str(lineno).rjust(self.line_number_chars),
|
485 |
+
font=self.fonts.get_font(self.line_number_bold,
|
486 |
+
self.line_number_italic),
|
487 |
+
text_fg=self.line_number_fg,
|
488 |
+
text_bg=None,
|
489 |
+
)
|
490 |
+
|
491 |
+
def _draw_text(self, pos, text, font, text_fg, text_bg):
|
492 |
+
"""
|
493 |
+
Remember a single drawable tuple to paint later.
|
494 |
+
"""
|
495 |
+
self.drawables.append((pos, text, font, text_fg, text_bg))
|
496 |
+
|
497 |
+
def _create_drawables(self, tokensource):
|
498 |
+
"""
|
499 |
+
Create drawables for the token content.
|
500 |
+
"""
|
501 |
+
lineno = charno = maxcharno = 0
|
502 |
+
maxlinelength = linelength = 0
|
503 |
+
for ttype, value in tokensource:
|
504 |
+
while ttype not in self.styles:
|
505 |
+
ttype = ttype.parent
|
506 |
+
style = self.styles[ttype]
|
507 |
+
# TODO: make sure tab expansion happens earlier in the chain. It
|
508 |
+
# really ought to be done on the input, as to do it right here is
|
509 |
+
# quite complex.
|
510 |
+
value = value.expandtabs(4)
|
511 |
+
lines = value.splitlines(True)
|
512 |
+
# print lines
|
513 |
+
for i, line in enumerate(lines):
|
514 |
+
temp = line.rstrip('\n')
|
515 |
+
if temp:
|
516 |
+
self._draw_text(
|
517 |
+
self._get_text_pos(linelength, lineno),
|
518 |
+
temp,
|
519 |
+
font = self._get_style_font(style),
|
520 |
+
text_fg = self._get_text_color(style),
|
521 |
+
text_bg = self._get_text_bg_color(style),
|
522 |
+
)
|
523 |
+
temp_width, temp_hight = self.fonts.get_text_size(temp)
|
524 |
+
linelength += temp_width
|
525 |
+
maxlinelength = max(maxlinelength, linelength)
|
526 |
+
charno += len(temp)
|
527 |
+
maxcharno = max(maxcharno, charno)
|
528 |
+
if line.endswith('\n'):
|
529 |
+
# add a line for each extra line in the value
|
530 |
+
linelength = 0
|
531 |
+
charno = 0
|
532 |
+
lineno += 1
|
533 |
+
self.maxlinelength = maxlinelength
|
534 |
+
self.maxcharno = maxcharno
|
535 |
+
self.maxlineno = lineno
|
536 |
+
|
537 |
+
def _draw_line_numbers(self):
|
538 |
+
"""
|
539 |
+
Create drawables for the line numbers.
|
540 |
+
"""
|
541 |
+
if not self.line_numbers:
|
542 |
+
return
|
543 |
+
for p in range(self.maxlineno):
|
544 |
+
n = p + self.line_number_start
|
545 |
+
if (n % self.line_number_step) == 0:
|
546 |
+
self._draw_linenumber(p, n)
|
547 |
+
|
548 |
+
def _paint_line_number_bg(self, im):
|
549 |
+
"""
|
550 |
+
Paint the line number background on the image.
|
551 |
+
"""
|
552 |
+
if not self.line_numbers:
|
553 |
+
return
|
554 |
+
if self.line_number_fg is None:
|
555 |
+
return
|
556 |
+
draw = ImageDraw.Draw(im)
|
557 |
+
recth = im.size[-1]
|
558 |
+
rectw = self.image_pad + self.line_number_width - self.line_number_pad
|
559 |
+
draw.rectangle([(0, 0), (rectw, recth)],
|
560 |
+
fill=self.line_number_bg)
|
561 |
+
if self.line_number_separator:
|
562 |
+
draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg)
|
563 |
+
del draw
|
564 |
+
|
565 |
+
def format(self, tokensource, outfile):
|
566 |
+
"""
|
567 |
+
Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
|
568 |
+
tuples and write it into ``outfile``.
|
569 |
+
|
570 |
+
This implementation calculates where it should draw each token on the
|
571 |
+
pixmap, then calculates the required pixmap size and draws the items.
|
572 |
+
"""
|
573 |
+
self._create_drawables(tokensource)
|
574 |
+
self._draw_line_numbers()
|
575 |
+
im = Image.new(
|
576 |
+
'RGB',
|
577 |
+
self._get_image_size(self.maxlinelength, self.maxlineno),
|
578 |
+
self.background_color
|
579 |
+
)
|
580 |
+
self._paint_line_number_bg(im)
|
581 |
+
draw = ImageDraw.Draw(im)
|
582 |
+
# Highlight
|
583 |
+
if self.hl_lines:
|
584 |
+
x = self.image_pad + self.line_number_width - self.line_number_pad + 1
|
585 |
+
recth = self._get_line_height()
|
586 |
+
rectw = im.size[0] - x
|
587 |
+
for linenumber in self.hl_lines:
|
588 |
+
y = self._get_line_y(linenumber - 1)
|
589 |
+
draw.rectangle([(x, y), (x + rectw, y + recth)],
|
590 |
+
fill=self.hl_color)
|
591 |
+
for pos, value, font, text_fg, text_bg in self.drawables:
|
592 |
+
if text_bg:
|
593 |
+
text_size = draw.textsize(text=value, font=font)
|
594 |
+
draw.rectangle([pos[0], pos[1], pos[0] + text_size[0], pos[1] + text_size[1]], fill=text_bg)
|
595 |
+
draw.text(pos, value, font=font, fill=text_fg)
|
596 |
+
im.save(outfile, self.image_format.upper())
|
597 |
+
|
598 |
+
|
599 |
+
# Add one formatter per format, so that the "-f gif" option gives the correct result
|
600 |
+
# when used in pygmentize.
|
601 |
+
|
602 |
+
class GifImageFormatter(ImageFormatter):
|
603 |
+
"""
|
604 |
+
Create a GIF image from source code. This uses the Python Imaging Library to
|
605 |
+
generate a pixmap from the source code.
|
606 |
+
|
607 |
+
.. versionadded:: 1.0
|
608 |
+
"""
|
609 |
+
|
610 |
+
name = 'img_gif'
|
611 |
+
aliases = ['gif']
|
612 |
+
filenames = ['*.gif']
|
613 |
+
default_image_format = 'gif'
|
614 |
+
|
615 |
+
|
616 |
+
class JpgImageFormatter(ImageFormatter):
|
617 |
+
"""
|
618 |
+
Create a JPEG image from source code. This uses the Python Imaging Library to
|
619 |
+
generate a pixmap from the source code.
|
620 |
+
|
621 |
+
.. versionadded:: 1.0
|
622 |
+
"""
|
623 |
+
|
624 |
+
name = 'img_jpg'
|
625 |
+
aliases = ['jpg', 'jpeg']
|
626 |
+
filenames = ['*.jpg']
|
627 |
+
default_image_format = 'jpeg'
|
628 |
+
|
629 |
+
|
630 |
+
class BmpImageFormatter(ImageFormatter):
|
631 |
+
"""
|
632 |
+
Create a bitmap image from source code. This uses the Python Imaging Library to
|
633 |
+
generate a pixmap from the source code.
|
634 |
+
|
635 |
+
.. versionadded:: 1.0
|
636 |
+
"""
|
637 |
+
|
638 |
+
name = 'img_bmp'
|
639 |
+
aliases = ['bmp', 'bitmap']
|
640 |
+
filenames = ['*.bmp']
|
641 |
+
default_image_format = 'bmp'
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/irc.py
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.irc
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for IRC output
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor.pygments.formatter import Formatter
|
12 |
+
from pip._vendor.pygments.token import Keyword, Name, Comment, String, Error, \
|
13 |
+
Number, Operator, Generic, Token, Whitespace
|
14 |
+
from pip._vendor.pygments.util import get_choice_opt
|
15 |
+
|
16 |
+
|
17 |
+
__all__ = ['IRCFormatter']
|
18 |
+
|
19 |
+
|
20 |
+
#: Map token types to a tuple of color values for light and dark
|
21 |
+
#: backgrounds.
|
22 |
+
IRC_COLORS = {
|
23 |
+
Token: ('', ''),
|
24 |
+
|
25 |
+
Whitespace: ('gray', 'brightblack'),
|
26 |
+
Comment: ('gray', 'brightblack'),
|
27 |
+
Comment.Preproc: ('cyan', 'brightcyan'),
|
28 |
+
Keyword: ('blue', 'brightblue'),
|
29 |
+
Keyword.Type: ('cyan', 'brightcyan'),
|
30 |
+
Operator.Word: ('magenta', 'brightcyan'),
|
31 |
+
Name.Builtin: ('cyan', 'brightcyan'),
|
32 |
+
Name.Function: ('green', 'brightgreen'),
|
33 |
+
Name.Namespace: ('_cyan_', '_brightcyan_'),
|
34 |
+
Name.Class: ('_green_', '_brightgreen_'),
|
35 |
+
Name.Exception: ('cyan', 'brightcyan'),
|
36 |
+
Name.Decorator: ('brightblack', 'gray'),
|
37 |
+
Name.Variable: ('red', 'brightred'),
|
38 |
+
Name.Constant: ('red', 'brightred'),
|
39 |
+
Name.Attribute: ('cyan', 'brightcyan'),
|
40 |
+
Name.Tag: ('brightblue', 'brightblue'),
|
41 |
+
String: ('yellow', 'yellow'),
|
42 |
+
Number: ('blue', 'brightblue'),
|
43 |
+
|
44 |
+
Generic.Deleted: ('brightred', 'brightred'),
|
45 |
+
Generic.Inserted: ('green', 'brightgreen'),
|
46 |
+
Generic.Heading: ('**', '**'),
|
47 |
+
Generic.Subheading: ('*magenta*', '*brightmagenta*'),
|
48 |
+
Generic.Error: ('brightred', 'brightred'),
|
49 |
+
|
50 |
+
Error: ('_brightred_', '_brightred_'),
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
IRC_COLOR_MAP = {
|
55 |
+
'white': 0,
|
56 |
+
'black': 1,
|
57 |
+
'blue': 2,
|
58 |
+
'brightgreen': 3,
|
59 |
+
'brightred': 4,
|
60 |
+
'yellow': 5,
|
61 |
+
'magenta': 6,
|
62 |
+
'orange': 7,
|
63 |
+
'green': 7, #compat w/ ansi
|
64 |
+
'brightyellow': 8,
|
65 |
+
'lightgreen': 9,
|
66 |
+
'brightcyan': 9, # compat w/ ansi
|
67 |
+
'cyan': 10,
|
68 |
+
'lightblue': 11,
|
69 |
+
'red': 11, # compat w/ ansi
|
70 |
+
'brightblue': 12,
|
71 |
+
'brightmagenta': 13,
|
72 |
+
'brightblack': 14,
|
73 |
+
'gray': 15,
|
74 |
+
}
|
75 |
+
|
76 |
+
def ircformat(color, text):
|
77 |
+
if len(color) < 1:
|
78 |
+
return text
|
79 |
+
add = sub = ''
|
80 |
+
if '_' in color: # italic
|
81 |
+
add += '\x1D'
|
82 |
+
sub = '\x1D' + sub
|
83 |
+
color = color.strip('_')
|
84 |
+
if '*' in color: # bold
|
85 |
+
add += '\x02'
|
86 |
+
sub = '\x02' + sub
|
87 |
+
color = color.strip('*')
|
88 |
+
# underline (\x1F) not supported
|
89 |
+
# backgrounds (\x03FF,BB) not supported
|
90 |
+
if len(color) > 0: # actual color - may have issues with ircformat("red", "blah")+"10" type stuff
|
91 |
+
add += '\x03' + str(IRC_COLOR_MAP[color]).zfill(2)
|
92 |
+
sub = '\x03' + sub
|
93 |
+
return add + text + sub
|
94 |
+
return '<'+add+'>'+text+'</'+sub+'>'
|
95 |
+
|
96 |
+
|
97 |
+
class IRCFormatter(Formatter):
|
98 |
+
r"""
|
99 |
+
Format tokens with IRC color sequences
|
100 |
+
|
101 |
+
The `get_style_defs()` method doesn't do anything special since there is
|
102 |
+
no support for common styles.
|
103 |
+
|
104 |
+
Options accepted:
|
105 |
+
|
106 |
+
`bg`
|
107 |
+
Set to ``"light"`` or ``"dark"`` depending on the terminal's background
|
108 |
+
(default: ``"light"``).
|
109 |
+
|
110 |
+
`colorscheme`
|
111 |
+
A dictionary mapping token types to (lightbg, darkbg) color names or
|
112 |
+
``None`` (default: ``None`` = use builtin colorscheme).
|
113 |
+
|
114 |
+
`linenos`
|
115 |
+
Set to ``True`` to have line numbers in the output as well
|
116 |
+
(default: ``False`` = no line numbers).
|
117 |
+
"""
|
118 |
+
name = 'IRC'
|
119 |
+
aliases = ['irc', 'IRC']
|
120 |
+
filenames = []
|
121 |
+
|
122 |
+
def __init__(self, **options):
|
123 |
+
Formatter.__init__(self, **options)
|
124 |
+
self.darkbg = get_choice_opt(options, 'bg',
|
125 |
+
['light', 'dark'], 'light') == 'dark'
|
126 |
+
self.colorscheme = options.get('colorscheme', None) or IRC_COLORS
|
127 |
+
self.linenos = options.get('linenos', False)
|
128 |
+
self._lineno = 0
|
129 |
+
|
130 |
+
def _write_lineno(self, outfile):
|
131 |
+
self._lineno += 1
|
132 |
+
outfile.write("\n%04d: " % self._lineno)
|
133 |
+
|
134 |
+
def _format_unencoded_with_lineno(self, tokensource, outfile):
|
135 |
+
self._write_lineno(outfile)
|
136 |
+
|
137 |
+
for ttype, value in tokensource:
|
138 |
+
if value.endswith("\n"):
|
139 |
+
self._write_lineno(outfile)
|
140 |
+
value = value[:-1]
|
141 |
+
color = self.colorscheme.get(ttype)
|
142 |
+
while color is None:
|
143 |
+
ttype = ttype.parent
|
144 |
+
color = self.colorscheme.get(ttype)
|
145 |
+
if color:
|
146 |
+
color = color[self.darkbg]
|
147 |
+
spl = value.split('\n')
|
148 |
+
for line in spl[:-1]:
|
149 |
+
self._write_lineno(outfile)
|
150 |
+
if line:
|
151 |
+
outfile.write(ircformat(color, line[:-1]))
|
152 |
+
if spl[-1]:
|
153 |
+
outfile.write(ircformat(color, spl[-1]))
|
154 |
+
else:
|
155 |
+
outfile.write(value)
|
156 |
+
|
157 |
+
outfile.write("\n")
|
158 |
+
|
159 |
+
def format_unencoded(self, tokensource, outfile):
|
160 |
+
if self.linenos:
|
161 |
+
self._format_unencoded_with_lineno(tokensource, outfile)
|
162 |
+
return
|
163 |
+
|
164 |
+
for ttype, value in tokensource:
|
165 |
+
color = self.colorscheme.get(ttype)
|
166 |
+
while color is None:
|
167 |
+
ttype = ttype[:-1]
|
168 |
+
color = self.colorscheme.get(ttype)
|
169 |
+
if color:
|
170 |
+
color = color[self.darkbg]
|
171 |
+
spl = value.split('\n')
|
172 |
+
for line in spl[:-1]:
|
173 |
+
if line:
|
174 |
+
outfile.write(ircformat(color, line))
|
175 |
+
outfile.write('\n')
|
176 |
+
if spl[-1]:
|
177 |
+
outfile.write(ircformat(color, spl[-1]))
|
178 |
+
else:
|
179 |
+
outfile.write(value)
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/latex.py
ADDED
@@ -0,0 +1,511 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.latex
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for LaTeX fancyvrb output.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from io import StringIO
|
12 |
+
|
13 |
+
from pip._vendor.pygments.formatter import Formatter
|
14 |
+
from pip._vendor.pygments.lexer import Lexer, do_insertions
|
15 |
+
from pip._vendor.pygments.token import Token, STANDARD_TYPES
|
16 |
+
from pip._vendor.pygments.util import get_bool_opt, get_int_opt
|
17 |
+
|
18 |
+
|
19 |
+
__all__ = ['LatexFormatter']
|
20 |
+
|
21 |
+
|
22 |
+
def escape_tex(text, commandprefix):
|
23 |
+
return text.replace('\\', '\x00'). \
|
24 |
+
replace('{', '\x01'). \
|
25 |
+
replace('}', '\x02'). \
|
26 |
+
replace('\x00', r'\%sZbs{}' % commandprefix). \
|
27 |
+
replace('\x01', r'\%sZob{}' % commandprefix). \
|
28 |
+
replace('\x02', r'\%sZcb{}' % commandprefix). \
|
29 |
+
replace('^', r'\%sZca{}' % commandprefix). \
|
30 |
+
replace('_', r'\%sZus{}' % commandprefix). \
|
31 |
+
replace('&', r'\%sZam{}' % commandprefix). \
|
32 |
+
replace('<', r'\%sZlt{}' % commandprefix). \
|
33 |
+
replace('>', r'\%sZgt{}' % commandprefix). \
|
34 |
+
replace('#', r'\%sZsh{}' % commandprefix). \
|
35 |
+
replace('%', r'\%sZpc{}' % commandprefix). \
|
36 |
+
replace('$', r'\%sZdl{}' % commandprefix). \
|
37 |
+
replace('-', r'\%sZhy{}' % commandprefix). \
|
38 |
+
replace("'", r'\%sZsq{}' % commandprefix). \
|
39 |
+
replace('"', r'\%sZdq{}' % commandprefix). \
|
40 |
+
replace('~', r'\%sZti{}' % commandprefix)
|
41 |
+
|
42 |
+
|
43 |
+
DOC_TEMPLATE = r'''
|
44 |
+
\documentclass{%(docclass)s}
|
45 |
+
\usepackage{fancyvrb}
|
46 |
+
\usepackage{color}
|
47 |
+
\usepackage[%(encoding)s]{inputenc}
|
48 |
+
%(preamble)s
|
49 |
+
|
50 |
+
%(styledefs)s
|
51 |
+
|
52 |
+
\begin{document}
|
53 |
+
|
54 |
+
\section*{%(title)s}
|
55 |
+
|
56 |
+
%(code)s
|
57 |
+
\end{document}
|
58 |
+
'''
|
59 |
+
|
60 |
+
## Small explanation of the mess below :)
|
61 |
+
#
|
62 |
+
# The previous version of the LaTeX formatter just assigned a command to
|
63 |
+
# each token type defined in the current style. That obviously is
|
64 |
+
# problematic if the highlighted code is produced for a different style
|
65 |
+
# than the style commands themselves.
|
66 |
+
#
|
67 |
+
# This version works much like the HTML formatter which assigns multiple
|
68 |
+
# CSS classes to each <span> tag, from the most specific to the least
|
69 |
+
# specific token type, thus falling back to the parent token type if one
|
70 |
+
# is not defined. Here, the classes are there too and use the same short
|
71 |
+
# forms given in token.STANDARD_TYPES.
|
72 |
+
#
|
73 |
+
# Highlighted code now only uses one custom command, which by default is
|
74 |
+
# \PY and selectable by the commandprefix option (and in addition the
|
75 |
+
# escapes \PYZat, \PYZlb and \PYZrb which haven't been renamed for
|
76 |
+
# backwards compatibility purposes).
|
77 |
+
#
|
78 |
+
# \PY has two arguments: the classes, separated by +, and the text to
|
79 |
+
# render in that style. The classes are resolved into the respective
|
80 |
+
# style commands by magic, which serves to ignore unknown classes.
|
81 |
+
#
|
82 |
+
# The magic macros are:
|
83 |
+
# * \PY@it, \PY@bf, etc. are unconditionally wrapped around the text
|
84 |
+
# to render in \PY@do. Their definition determines the style.
|
85 |
+
# * \PY@reset resets \PY@it etc. to do nothing.
|
86 |
+
# * \PY@toks parses the list of classes, using magic inspired by the
|
87 |
+
# keyval package (but modified to use plusses instead of commas
|
88 |
+
# because fancyvrb redefines commas inside its environments).
|
89 |
+
# * \PY@tok processes one class, calling the \PY@tok@classname command
|
90 |
+
# if it exists.
|
91 |
+
# * \PY@tok@classname sets the \PY@it etc. to reflect the chosen style
|
92 |
+
# for its class.
|
93 |
+
# * \PY resets the style, parses the classnames and then calls \PY@do.
|
94 |
+
#
|
95 |
+
# Tip: to read this code, print it out in substituted form using e.g.
|
96 |
+
# >>> print STYLE_TEMPLATE % {'cp': 'PY'}
|
97 |
+
|
98 |
+
STYLE_TEMPLATE = r'''
|
99 |
+
\makeatletter
|
100 |
+
\def\%(cp)s@reset{\let\%(cp)s@it=\relax \let\%(cp)s@bf=\relax%%
|
101 |
+
\let\%(cp)s@ul=\relax \let\%(cp)s@tc=\relax%%
|
102 |
+
\let\%(cp)s@bc=\relax \let\%(cp)s@ff=\relax}
|
103 |
+
\def\%(cp)s@tok#1{\csname %(cp)s@tok@#1\endcsname}
|
104 |
+
\def\%(cp)s@toks#1+{\ifx\relax#1\empty\else%%
|
105 |
+
\%(cp)s@tok{#1}\expandafter\%(cp)s@toks\fi}
|
106 |
+
\def\%(cp)s@do#1{\%(cp)s@bc{\%(cp)s@tc{\%(cp)s@ul{%%
|
107 |
+
\%(cp)s@it{\%(cp)s@bf{\%(cp)s@ff{#1}}}}}}}
|
108 |
+
\def\%(cp)s#1#2{\%(cp)s@reset\%(cp)s@toks#1+\relax+\%(cp)s@do{#2}}
|
109 |
+
|
110 |
+
%(styles)s
|
111 |
+
|
112 |
+
\def\%(cp)sZbs{\char`\\}
|
113 |
+
\def\%(cp)sZus{\char`\_}
|
114 |
+
\def\%(cp)sZob{\char`\{}
|
115 |
+
\def\%(cp)sZcb{\char`\}}
|
116 |
+
\def\%(cp)sZca{\char`\^}
|
117 |
+
\def\%(cp)sZam{\char`\&}
|
118 |
+
\def\%(cp)sZlt{\char`\<}
|
119 |
+
\def\%(cp)sZgt{\char`\>}
|
120 |
+
\def\%(cp)sZsh{\char`\#}
|
121 |
+
\def\%(cp)sZpc{\char`\%%}
|
122 |
+
\def\%(cp)sZdl{\char`\$}
|
123 |
+
\def\%(cp)sZhy{\char`\-}
|
124 |
+
\def\%(cp)sZsq{\char`\'}
|
125 |
+
\def\%(cp)sZdq{\char`\"}
|
126 |
+
\def\%(cp)sZti{\char`\~}
|
127 |
+
%% for compatibility with earlier versions
|
128 |
+
\def\%(cp)sZat{@}
|
129 |
+
\def\%(cp)sZlb{[}
|
130 |
+
\def\%(cp)sZrb{]}
|
131 |
+
\makeatother
|
132 |
+
'''
|
133 |
+
|
134 |
+
|
135 |
+
def _get_ttype_name(ttype):
|
136 |
+
fname = STANDARD_TYPES.get(ttype)
|
137 |
+
if fname:
|
138 |
+
return fname
|
139 |
+
aname = ''
|
140 |
+
while fname is None:
|
141 |
+
aname = ttype[-1] + aname
|
142 |
+
ttype = ttype.parent
|
143 |
+
fname = STANDARD_TYPES.get(ttype)
|
144 |
+
return fname + aname
|
145 |
+
|
146 |
+
|
147 |
+
class LatexFormatter(Formatter):
|
148 |
+
r"""
|
149 |
+
Format tokens as LaTeX code. This needs the `fancyvrb` and `color`
|
150 |
+
standard packages.
|
151 |
+
|
152 |
+
Without the `full` option, code is formatted as one ``Verbatim``
|
153 |
+
environment, like this:
|
154 |
+
|
155 |
+
.. sourcecode:: latex
|
156 |
+
|
157 |
+
\begin{Verbatim}[commandchars=\\\{\}]
|
158 |
+
\PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}):
|
159 |
+
\PY{k}{pass}
|
160 |
+
\end{Verbatim}
|
161 |
+
|
162 |
+
The special command used here (``\PY``) and all the other macros it needs
|
163 |
+
are output by the `get_style_defs` method.
|
164 |
+
|
165 |
+
With the `full` option, a complete LaTeX document is output, including
|
166 |
+
the command definitions in the preamble.
|
167 |
+
|
168 |
+
The `get_style_defs()` method of a `LatexFormatter` returns a string
|
169 |
+
containing ``\def`` commands defining the macros needed inside the
|
170 |
+
``Verbatim`` environments.
|
171 |
+
|
172 |
+
Additional options accepted:
|
173 |
+
|
174 |
+
`style`
|
175 |
+
The style to use, can be a string or a Style subclass (default:
|
176 |
+
``'default'``).
|
177 |
+
|
178 |
+
`full`
|
179 |
+
Tells the formatter to output a "full" document, i.e. a complete
|
180 |
+
self-contained document (default: ``False``).
|
181 |
+
|
182 |
+
`title`
|
183 |
+
If `full` is true, the title that should be used to caption the
|
184 |
+
document (default: ``''``).
|
185 |
+
|
186 |
+
`docclass`
|
187 |
+
If the `full` option is enabled, this is the document class to use
|
188 |
+
(default: ``'article'``).
|
189 |
+
|
190 |
+
`preamble`
|
191 |
+
If the `full` option is enabled, this can be further preamble commands,
|
192 |
+
e.g. ``\usepackage`` (default: ``''``).
|
193 |
+
|
194 |
+
`linenos`
|
195 |
+
If set to ``True``, output line numbers (default: ``False``).
|
196 |
+
|
197 |
+
`linenostart`
|
198 |
+
The line number for the first line (default: ``1``).
|
199 |
+
|
200 |
+
`linenostep`
|
201 |
+
If set to a number n > 1, only every nth line number is printed.
|
202 |
+
|
203 |
+
`verboptions`
|
204 |
+
Additional options given to the Verbatim environment (see the *fancyvrb*
|
205 |
+
docs for possible values) (default: ``''``).
|
206 |
+
|
207 |
+
`commandprefix`
|
208 |
+
The LaTeX commands used to produce colored output are constructed
|
209 |
+
using this prefix and some letters (default: ``'PY'``).
|
210 |
+
|
211 |
+
.. versionadded:: 0.7
|
212 |
+
.. versionchanged:: 0.10
|
213 |
+
The default is now ``'PY'`` instead of ``'C'``.
|
214 |
+
|
215 |
+
`texcomments`
|
216 |
+
If set to ``True``, enables LaTeX comment lines. That is, LaTex markup
|
217 |
+
in comment tokens is not escaped so that LaTeX can render it (default:
|
218 |
+
``False``).
|
219 |
+
|
220 |
+
.. versionadded:: 1.2
|
221 |
+
|
222 |
+
`mathescape`
|
223 |
+
If set to ``True``, enables LaTeX math mode escape in comments. That
|
224 |
+
is, ``'$...$'`` inside a comment will trigger math mode (default:
|
225 |
+
``False``).
|
226 |
+
|
227 |
+
.. versionadded:: 1.2
|
228 |
+
|
229 |
+
`escapeinside`
|
230 |
+
If set to a string of length 2, enables escaping to LaTeX. Text
|
231 |
+
delimited by these 2 characters is read as LaTeX code and
|
232 |
+
typeset accordingly. It has no effect in string literals. It has
|
233 |
+
no effect in comments if `texcomments` or `mathescape` is
|
234 |
+
set. (default: ``''``).
|
235 |
+
|
236 |
+
.. versionadded:: 2.0
|
237 |
+
|
238 |
+
`envname`
|
239 |
+
Allows you to pick an alternative environment name replacing Verbatim.
|
240 |
+
The alternate environment still has to support Verbatim's option syntax.
|
241 |
+
(default: ``'Verbatim'``).
|
242 |
+
|
243 |
+
.. versionadded:: 2.0
|
244 |
+
"""
|
245 |
+
name = 'LaTeX'
|
246 |
+
aliases = ['latex', 'tex']
|
247 |
+
filenames = ['*.tex']
|
248 |
+
|
249 |
+
def __init__(self, **options):
|
250 |
+
Formatter.__init__(self, **options)
|
251 |
+
self.docclass = options.get('docclass', 'article')
|
252 |
+
self.preamble = options.get('preamble', '')
|
253 |
+
self.linenos = get_bool_opt(options, 'linenos', False)
|
254 |
+
self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
|
255 |
+
self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
|
256 |
+
self.verboptions = options.get('verboptions', '')
|
257 |
+
self.nobackground = get_bool_opt(options, 'nobackground', False)
|
258 |
+
self.commandprefix = options.get('commandprefix', 'PY')
|
259 |
+
self.texcomments = get_bool_opt(options, 'texcomments', False)
|
260 |
+
self.mathescape = get_bool_opt(options, 'mathescape', False)
|
261 |
+
self.escapeinside = options.get('escapeinside', '')
|
262 |
+
if len(self.escapeinside) == 2:
|
263 |
+
self.left = self.escapeinside[0]
|
264 |
+
self.right = self.escapeinside[1]
|
265 |
+
else:
|
266 |
+
self.escapeinside = ''
|
267 |
+
self.envname = options.get('envname', 'Verbatim')
|
268 |
+
|
269 |
+
self._create_stylesheet()
|
270 |
+
|
271 |
+
def _create_stylesheet(self):
|
272 |
+
t2n = self.ttype2name = {Token: ''}
|
273 |
+
c2d = self.cmd2def = {}
|
274 |
+
cp = self.commandprefix
|
275 |
+
|
276 |
+
def rgbcolor(col):
|
277 |
+
if col:
|
278 |
+
return ','.join(['%.2f' % (int(col[i] + col[i + 1], 16) / 255.0)
|
279 |
+
for i in (0, 2, 4)])
|
280 |
+
else:
|
281 |
+
return '1,1,1'
|
282 |
+
|
283 |
+
for ttype, ndef in self.style:
|
284 |
+
name = _get_ttype_name(ttype)
|
285 |
+
cmndef = ''
|
286 |
+
if ndef['bold']:
|
287 |
+
cmndef += r'\let\$$@bf=\textbf'
|
288 |
+
if ndef['italic']:
|
289 |
+
cmndef += r'\let\$$@it=\textit'
|
290 |
+
if ndef['underline']:
|
291 |
+
cmndef += r'\let\$$@ul=\underline'
|
292 |
+
if ndef['roman']:
|
293 |
+
cmndef += r'\let\$$@ff=\textrm'
|
294 |
+
if ndef['sans']:
|
295 |
+
cmndef += r'\let\$$@ff=\textsf'
|
296 |
+
if ndef['mono']:
|
297 |
+
cmndef += r'\let\$$@ff=\textsf'
|
298 |
+
if ndef['color']:
|
299 |
+
cmndef += (r'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}' %
|
300 |
+
rgbcolor(ndef['color']))
|
301 |
+
if ndef['border']:
|
302 |
+
cmndef += (r'\def\$$@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}'
|
303 |
+
r'\fcolorbox[rgb]{%s}{%s}{\strut ##1}}}' %
|
304 |
+
(rgbcolor(ndef['border']),
|
305 |
+
rgbcolor(ndef['bgcolor'])))
|
306 |
+
elif ndef['bgcolor']:
|
307 |
+
cmndef += (r'\def\$$@bc##1{{\setlength{\fboxsep}{0pt}'
|
308 |
+
r'\colorbox[rgb]{%s}{\strut ##1}}}' %
|
309 |
+
rgbcolor(ndef['bgcolor']))
|
310 |
+
if cmndef == '':
|
311 |
+
continue
|
312 |
+
cmndef = cmndef.replace('$$', cp)
|
313 |
+
t2n[ttype] = name
|
314 |
+
c2d[name] = cmndef
|
315 |
+
|
316 |
+
def get_style_defs(self, arg=''):
|
317 |
+
"""
|
318 |
+
Return the command sequences needed to define the commands
|
319 |
+
used to format text in the verbatim environment. ``arg`` is ignored.
|
320 |
+
"""
|
321 |
+
cp = self.commandprefix
|
322 |
+
styles = []
|
323 |
+
for name, definition in self.cmd2def.items():
|
324 |
+
styles.append(r'\@namedef{%s@tok@%s}{%s}' % (cp, name, definition))
|
325 |
+
return STYLE_TEMPLATE % {'cp': self.commandprefix,
|
326 |
+
'styles': '\n'.join(styles)}
|
327 |
+
|
328 |
+
def format_unencoded(self, tokensource, outfile):
|
329 |
+
# TODO: add support for background colors
|
330 |
+
t2n = self.ttype2name
|
331 |
+
cp = self.commandprefix
|
332 |
+
|
333 |
+
if self.full:
|
334 |
+
realoutfile = outfile
|
335 |
+
outfile = StringIO()
|
336 |
+
|
337 |
+
outfile.write('\\begin{' + self.envname + '}[commandchars=\\\\\\{\\}')
|
338 |
+
if self.linenos:
|
339 |
+
start, step = self.linenostart, self.linenostep
|
340 |
+
outfile.write(',numbers=left' +
|
341 |
+
(start and ',firstnumber=%d' % start or '') +
|
342 |
+
(step and ',stepnumber=%d' % step or ''))
|
343 |
+
if self.mathescape or self.texcomments or self.escapeinside:
|
344 |
+
outfile.write(',codes={\\catcode`\\$=3\\catcode`\\^=7'
|
345 |
+
'\\catcode`\\_=8\\relax}')
|
346 |
+
if self.verboptions:
|
347 |
+
outfile.write(',' + self.verboptions)
|
348 |
+
outfile.write(']\n')
|
349 |
+
|
350 |
+
for ttype, value in tokensource:
|
351 |
+
if ttype in Token.Comment:
|
352 |
+
if self.texcomments:
|
353 |
+
# Try to guess comment starting lexeme and escape it ...
|
354 |
+
start = value[0:1]
|
355 |
+
for i in range(1, len(value)):
|
356 |
+
if start[0] != value[i]:
|
357 |
+
break
|
358 |
+
start += value[i]
|
359 |
+
|
360 |
+
value = value[len(start):]
|
361 |
+
start = escape_tex(start, cp)
|
362 |
+
|
363 |
+
# ... but do not escape inside comment.
|
364 |
+
value = start + value
|
365 |
+
elif self.mathescape:
|
366 |
+
# Only escape parts not inside a math environment.
|
367 |
+
parts = value.split('$')
|
368 |
+
in_math = False
|
369 |
+
for i, part in enumerate(parts):
|
370 |
+
if not in_math:
|
371 |
+
parts[i] = escape_tex(part, cp)
|
372 |
+
in_math = not in_math
|
373 |
+
value = '$'.join(parts)
|
374 |
+
elif self.escapeinside:
|
375 |
+
text = value
|
376 |
+
value = ''
|
377 |
+
while text:
|
378 |
+
a, sep1, text = text.partition(self.left)
|
379 |
+
if sep1:
|
380 |
+
b, sep2, text = text.partition(self.right)
|
381 |
+
if sep2:
|
382 |
+
value += escape_tex(a, cp) + b
|
383 |
+
else:
|
384 |
+
value += escape_tex(a + sep1 + b, cp)
|
385 |
+
else:
|
386 |
+
value += escape_tex(a, cp)
|
387 |
+
else:
|
388 |
+
value = escape_tex(value, cp)
|
389 |
+
elif ttype not in Token.Escape:
|
390 |
+
value = escape_tex(value, cp)
|
391 |
+
styles = []
|
392 |
+
while ttype is not Token:
|
393 |
+
try:
|
394 |
+
styles.append(t2n[ttype])
|
395 |
+
except KeyError:
|
396 |
+
# not in current style
|
397 |
+
styles.append(_get_ttype_name(ttype))
|
398 |
+
ttype = ttype.parent
|
399 |
+
styleval = '+'.join(reversed(styles))
|
400 |
+
if styleval:
|
401 |
+
spl = value.split('\n')
|
402 |
+
for line in spl[:-1]:
|
403 |
+
if line:
|
404 |
+
outfile.write("\\%s{%s}{%s}" % (cp, styleval, line))
|
405 |
+
outfile.write('\n')
|
406 |
+
if spl[-1]:
|
407 |
+
outfile.write("\\%s{%s}{%s}" % (cp, styleval, spl[-1]))
|
408 |
+
else:
|
409 |
+
outfile.write(value)
|
410 |
+
|
411 |
+
outfile.write('\\end{' + self.envname + '}\n')
|
412 |
+
|
413 |
+
if self.full:
|
414 |
+
encoding = self.encoding or 'utf8'
|
415 |
+
# map known existings encodings from LaTeX distribution
|
416 |
+
encoding = {
|
417 |
+
'utf_8': 'utf8',
|
418 |
+
'latin_1': 'latin1',
|
419 |
+
'iso_8859_1': 'latin1',
|
420 |
+
}.get(encoding.replace('-', '_'), encoding)
|
421 |
+
realoutfile.write(DOC_TEMPLATE %
|
422 |
+
dict(docclass = self.docclass,
|
423 |
+
preamble = self.preamble,
|
424 |
+
title = self.title,
|
425 |
+
encoding = encoding,
|
426 |
+
styledefs = self.get_style_defs(),
|
427 |
+
code = outfile.getvalue()))
|
428 |
+
|
429 |
+
|
430 |
+
class LatexEmbeddedLexer(Lexer):
|
431 |
+
"""
|
432 |
+
This lexer takes one lexer as argument, the lexer for the language
|
433 |
+
being formatted, and the left and right delimiters for escaped text.
|
434 |
+
|
435 |
+
First everything is scanned using the language lexer to obtain
|
436 |
+
strings and comments. All other consecutive tokens are merged and
|
437 |
+
the resulting text is scanned for escaped segments, which are given
|
438 |
+
the Token.Escape type. Finally text that is not escaped is scanned
|
439 |
+
again with the language lexer.
|
440 |
+
"""
|
441 |
+
def __init__(self, left, right, lang, **options):
|
442 |
+
self.left = left
|
443 |
+
self.right = right
|
444 |
+
self.lang = lang
|
445 |
+
Lexer.__init__(self, **options)
|
446 |
+
|
447 |
+
def get_tokens_unprocessed(self, text):
|
448 |
+
# find and remove all the escape tokens (replace with an empty string)
|
449 |
+
# this is very similar to DelegatingLexer.get_tokens_unprocessed.
|
450 |
+
buffered = ''
|
451 |
+
insertions = []
|
452 |
+
insertion_buf = []
|
453 |
+
for i, t, v in self._find_safe_escape_tokens(text):
|
454 |
+
if t is None:
|
455 |
+
if insertion_buf:
|
456 |
+
insertions.append((len(buffered), insertion_buf))
|
457 |
+
insertion_buf = []
|
458 |
+
buffered += v
|
459 |
+
else:
|
460 |
+
insertion_buf.append((i, t, v))
|
461 |
+
if insertion_buf:
|
462 |
+
insertions.append((len(buffered), insertion_buf))
|
463 |
+
return do_insertions(insertions,
|
464 |
+
self.lang.get_tokens_unprocessed(buffered))
|
465 |
+
|
466 |
+
def _find_safe_escape_tokens(self, text):
|
467 |
+
""" find escape tokens that are not in strings or comments """
|
468 |
+
for i, t, v in self._filter_to(
|
469 |
+
self.lang.get_tokens_unprocessed(text),
|
470 |
+
lambda t: t in Token.Comment or t in Token.String
|
471 |
+
):
|
472 |
+
if t is None:
|
473 |
+
for i2, t2, v2 in self._find_escape_tokens(v):
|
474 |
+
yield i + i2, t2, v2
|
475 |
+
else:
|
476 |
+
yield i, None, v
|
477 |
+
|
478 |
+
def _filter_to(self, it, pred):
|
479 |
+
""" Keep only the tokens that match `pred`, merge the others together """
|
480 |
+
buf = ''
|
481 |
+
idx = 0
|
482 |
+
for i, t, v in it:
|
483 |
+
if pred(t):
|
484 |
+
if buf:
|
485 |
+
yield idx, None, buf
|
486 |
+
buf = ''
|
487 |
+
yield i, t, v
|
488 |
+
else:
|
489 |
+
if not buf:
|
490 |
+
idx = i
|
491 |
+
buf += v
|
492 |
+
if buf:
|
493 |
+
yield idx, None, buf
|
494 |
+
|
495 |
+
def _find_escape_tokens(self, text):
|
496 |
+
""" Find escape tokens within text, give token=None otherwise """
|
497 |
+
index = 0
|
498 |
+
while text:
|
499 |
+
a, sep1, text = text.partition(self.left)
|
500 |
+
if a:
|
501 |
+
yield index, None, a
|
502 |
+
index += len(a)
|
503 |
+
if sep1:
|
504 |
+
b, sep2, text = text.partition(self.right)
|
505 |
+
if sep2:
|
506 |
+
yield index + len(sep1), Token.Escape, b
|
507 |
+
index += len(sep1) + len(b) + len(sep2)
|
508 |
+
else:
|
509 |
+
yield index, Token.Error, sep1
|
510 |
+
index += len(sep1)
|
511 |
+
text = b
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/other.py
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.other
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Other formatters: NullFormatter, RawTokenFormatter.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor.pygments.formatter import Formatter
|
12 |
+
from pip._vendor.pygments.util import get_choice_opt
|
13 |
+
from pip._vendor.pygments.token import Token
|
14 |
+
from pip._vendor.pygments.console import colorize
|
15 |
+
|
16 |
+
__all__ = ['NullFormatter', 'RawTokenFormatter', 'TestcaseFormatter']
|
17 |
+
|
18 |
+
|
19 |
+
class NullFormatter(Formatter):
|
20 |
+
"""
|
21 |
+
Output the text unchanged without any formatting.
|
22 |
+
"""
|
23 |
+
name = 'Text only'
|
24 |
+
aliases = ['text', 'null']
|
25 |
+
filenames = ['*.txt']
|
26 |
+
|
27 |
+
def format(self, tokensource, outfile):
|
28 |
+
enc = self.encoding
|
29 |
+
for ttype, value in tokensource:
|
30 |
+
if enc:
|
31 |
+
outfile.write(value.encode(enc))
|
32 |
+
else:
|
33 |
+
outfile.write(value)
|
34 |
+
|
35 |
+
|
36 |
+
class RawTokenFormatter(Formatter):
|
37 |
+
r"""
|
38 |
+
Format tokens as a raw representation for storing token streams.
|
39 |
+
|
40 |
+
The format is ``tokentype<TAB>repr(tokenstring)\n``. The output can later
|
41 |
+
be converted to a token stream with the `RawTokenLexer`, described in the
|
42 |
+
:doc:`lexer list <lexers>`.
|
43 |
+
|
44 |
+
Only two options are accepted:
|
45 |
+
|
46 |
+
`compress`
|
47 |
+
If set to ``'gz'`` or ``'bz2'``, compress the output with the given
|
48 |
+
compression algorithm after encoding (default: ``''``).
|
49 |
+
`error_color`
|
50 |
+
If set to a color name, highlight error tokens using that color. If
|
51 |
+
set but with no value, defaults to ``'red'``.
|
52 |
+
|
53 |
+
.. versionadded:: 0.11
|
54 |
+
|
55 |
+
"""
|
56 |
+
name = 'Raw tokens'
|
57 |
+
aliases = ['raw', 'tokens']
|
58 |
+
filenames = ['*.raw']
|
59 |
+
|
60 |
+
unicodeoutput = False
|
61 |
+
|
62 |
+
def __init__(self, **options):
|
63 |
+
Formatter.__init__(self, **options)
|
64 |
+
# We ignore self.encoding if it is set, since it gets set for lexer
|
65 |
+
# and formatter if given with -Oencoding on the command line.
|
66 |
+
# The RawTokenFormatter outputs only ASCII. Override here.
|
67 |
+
self.encoding = 'ascii' # let pygments.format() do the right thing
|
68 |
+
self.compress = get_choice_opt(options, 'compress',
|
69 |
+
['', 'none', 'gz', 'bz2'], '')
|
70 |
+
self.error_color = options.get('error_color', None)
|
71 |
+
if self.error_color is True:
|
72 |
+
self.error_color = 'red'
|
73 |
+
if self.error_color is not None:
|
74 |
+
try:
|
75 |
+
colorize(self.error_color, '')
|
76 |
+
except KeyError:
|
77 |
+
raise ValueError("Invalid color %r specified" %
|
78 |
+
self.error_color)
|
79 |
+
|
80 |
+
def format(self, tokensource, outfile):
|
81 |
+
try:
|
82 |
+
outfile.write(b'')
|
83 |
+
except TypeError:
|
84 |
+
raise TypeError('The raw tokens formatter needs a binary '
|
85 |
+
'output file')
|
86 |
+
if self.compress == 'gz':
|
87 |
+
import gzip
|
88 |
+
outfile = gzip.GzipFile('', 'wb', 9, outfile)
|
89 |
+
|
90 |
+
write = outfile.write
|
91 |
+
flush = outfile.close
|
92 |
+
elif self.compress == 'bz2':
|
93 |
+
import bz2
|
94 |
+
compressor = bz2.BZ2Compressor(9)
|
95 |
+
|
96 |
+
def write(text):
|
97 |
+
outfile.write(compressor.compress(text))
|
98 |
+
|
99 |
+
def flush():
|
100 |
+
outfile.write(compressor.flush())
|
101 |
+
outfile.flush()
|
102 |
+
else:
|
103 |
+
write = outfile.write
|
104 |
+
flush = outfile.flush
|
105 |
+
|
106 |
+
if self.error_color:
|
107 |
+
for ttype, value in tokensource:
|
108 |
+
line = b"%r\t%r\n" % (ttype, value)
|
109 |
+
if ttype is Token.Error:
|
110 |
+
write(colorize(self.error_color, line))
|
111 |
+
else:
|
112 |
+
write(line)
|
113 |
+
else:
|
114 |
+
for ttype, value in tokensource:
|
115 |
+
write(b"%r\t%r\n" % (ttype, value))
|
116 |
+
flush()
|
117 |
+
|
118 |
+
|
119 |
+
TESTCASE_BEFORE = '''\
|
120 |
+
def testNeedsName(lexer):
|
121 |
+
fragment = %r
|
122 |
+
tokens = [
|
123 |
+
'''
|
124 |
+
TESTCASE_AFTER = '''\
|
125 |
+
]
|
126 |
+
assert list(lexer.get_tokens(fragment)) == tokens
|
127 |
+
'''
|
128 |
+
|
129 |
+
|
130 |
+
class TestcaseFormatter(Formatter):
|
131 |
+
"""
|
132 |
+
Format tokens as appropriate for a new testcase.
|
133 |
+
|
134 |
+
.. versionadded:: 2.0
|
135 |
+
"""
|
136 |
+
name = 'Testcase'
|
137 |
+
aliases = ['testcase']
|
138 |
+
|
139 |
+
def __init__(self, **options):
|
140 |
+
Formatter.__init__(self, **options)
|
141 |
+
if self.encoding is not None and self.encoding != 'utf-8':
|
142 |
+
raise ValueError("Only None and utf-8 are allowed encodings.")
|
143 |
+
|
144 |
+
def format(self, tokensource, outfile):
|
145 |
+
indentation = ' ' * 12
|
146 |
+
rawbuf = []
|
147 |
+
outbuf = []
|
148 |
+
for ttype, value in tokensource:
|
149 |
+
rawbuf.append(value)
|
150 |
+
outbuf.append('%s(%s, %r),\n' % (indentation, ttype, value))
|
151 |
+
|
152 |
+
before = TESTCASE_BEFORE % (''.join(rawbuf),)
|
153 |
+
during = ''.join(outbuf)
|
154 |
+
after = TESTCASE_AFTER
|
155 |
+
if self.encoding is None:
|
156 |
+
outfile.write(before + during + after)
|
157 |
+
else:
|
158 |
+
outfile.write(before.encode('utf-8'))
|
159 |
+
outfile.write(during.encode('utf-8'))
|
160 |
+
outfile.write(after.encode('utf-8'))
|
161 |
+
outfile.flush()
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/pangomarkup.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.pangomarkup
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for Pango markup output.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor.pygments.formatter import Formatter
|
12 |
+
|
13 |
+
|
14 |
+
__all__ = ['PangoMarkupFormatter']
|
15 |
+
|
16 |
+
|
17 |
+
_escape_table = {
|
18 |
+
ord('&'): '&',
|
19 |
+
ord('<'): '<',
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
def escape_special_chars(text, table=_escape_table):
|
24 |
+
"""Escape & and < for Pango Markup."""
|
25 |
+
return text.translate(table)
|
26 |
+
|
27 |
+
|
28 |
+
class PangoMarkupFormatter(Formatter):
|
29 |
+
"""
|
30 |
+
Format tokens as Pango Markup code. It can then be rendered to an SVG.
|
31 |
+
|
32 |
+
.. versionadded:: 2.9
|
33 |
+
"""
|
34 |
+
|
35 |
+
name = 'Pango Markup'
|
36 |
+
aliases = ['pango', 'pangomarkup']
|
37 |
+
filenames = []
|
38 |
+
|
39 |
+
def __init__(self, **options):
|
40 |
+
Formatter.__init__(self, **options)
|
41 |
+
|
42 |
+
self.styles = {}
|
43 |
+
|
44 |
+
for token, style in self.style:
|
45 |
+
start = ''
|
46 |
+
end = ''
|
47 |
+
if style['color']:
|
48 |
+
start += '<span fgcolor="#%s">' % style['color']
|
49 |
+
end = '</span>' + end
|
50 |
+
if style['bold']:
|
51 |
+
start += '<b>'
|
52 |
+
end = '</b>' + end
|
53 |
+
if style['italic']:
|
54 |
+
start += '<i>'
|
55 |
+
end = '</i>' + end
|
56 |
+
if style['underline']:
|
57 |
+
start += '<u>'
|
58 |
+
end = '</u>' + end
|
59 |
+
self.styles[token] = (start, end)
|
60 |
+
|
61 |
+
def format_unencoded(self, tokensource, outfile):
|
62 |
+
lastval = ''
|
63 |
+
lasttype = None
|
64 |
+
|
65 |
+
outfile.write('<tt>')
|
66 |
+
|
67 |
+
for ttype, value in tokensource:
|
68 |
+
while ttype not in self.styles:
|
69 |
+
ttype = ttype.parent
|
70 |
+
if ttype == lasttype:
|
71 |
+
lastval += escape_special_chars(value)
|
72 |
+
else:
|
73 |
+
if lastval:
|
74 |
+
stylebegin, styleend = self.styles[lasttype]
|
75 |
+
outfile.write(stylebegin + lastval + styleend)
|
76 |
+
lastval = escape_special_chars(value)
|
77 |
+
lasttype = ttype
|
78 |
+
|
79 |
+
if lastval:
|
80 |
+
stylebegin, styleend = self.styles[lasttype]
|
81 |
+
outfile.write(stylebegin + lastval + styleend)
|
82 |
+
|
83 |
+
outfile.write('</tt>')
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/rtf.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.rtf
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
A formatter that generates RTF files.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor.pygments.formatter import Formatter
|
12 |
+
from pip._vendor.pygments.util import get_int_opt, surrogatepair
|
13 |
+
|
14 |
+
|
15 |
+
__all__ = ['RtfFormatter']
|
16 |
+
|
17 |
+
|
18 |
+
class RtfFormatter(Formatter):
|
19 |
+
"""
|
20 |
+
Format tokens as RTF markup. This formatter automatically outputs full RTF
|
21 |
+
documents with color information and other useful stuff. Perfect for Copy and
|
22 |
+
Paste into Microsoft(R) Word(R) documents.
|
23 |
+
|
24 |
+
Please note that ``encoding`` and ``outencoding`` options are ignored.
|
25 |
+
The RTF format is ASCII natively, but handles unicode characters correctly
|
26 |
+
thanks to escape sequences.
|
27 |
+
|
28 |
+
.. versionadded:: 0.6
|
29 |
+
|
30 |
+
Additional options accepted:
|
31 |
+
|
32 |
+
`style`
|
33 |
+
The style to use, can be a string or a Style subclass (default:
|
34 |
+
``'default'``).
|
35 |
+
|
36 |
+
`fontface`
|
37 |
+
The used font family, for example ``Bitstream Vera Sans``. Defaults to
|
38 |
+
some generic font which is supposed to have fixed width.
|
39 |
+
|
40 |
+
`fontsize`
|
41 |
+
Size of the font used. Size is specified in half points. The
|
42 |
+
default is 24 half-points, giving a size 12 font.
|
43 |
+
|
44 |
+
.. versionadded:: 2.0
|
45 |
+
"""
|
46 |
+
name = 'RTF'
|
47 |
+
aliases = ['rtf']
|
48 |
+
filenames = ['*.rtf']
|
49 |
+
|
50 |
+
def __init__(self, **options):
|
51 |
+
r"""
|
52 |
+
Additional options accepted:
|
53 |
+
|
54 |
+
``fontface``
|
55 |
+
Name of the font used. Could for example be ``'Courier New'``
|
56 |
+
to further specify the default which is ``'\fmodern'``. The RTF
|
57 |
+
specification claims that ``\fmodern`` are "Fixed-pitch serif
|
58 |
+
and sans serif fonts". Hope every RTF implementation thinks
|
59 |
+
the same about modern...
|
60 |
+
|
61 |
+
"""
|
62 |
+
Formatter.__init__(self, **options)
|
63 |
+
self.fontface = options.get('fontface') or ''
|
64 |
+
self.fontsize = get_int_opt(options, 'fontsize', 0)
|
65 |
+
|
66 |
+
def _escape(self, text):
|
67 |
+
return text.replace('\\', '\\\\') \
|
68 |
+
.replace('{', '\\{') \
|
69 |
+
.replace('}', '\\}')
|
70 |
+
|
71 |
+
def _escape_text(self, text):
|
72 |
+
# empty strings, should give a small performance improvement
|
73 |
+
if not text:
|
74 |
+
return ''
|
75 |
+
|
76 |
+
# escape text
|
77 |
+
text = self._escape(text)
|
78 |
+
|
79 |
+
buf = []
|
80 |
+
for c in text:
|
81 |
+
cn = ord(c)
|
82 |
+
if cn < (2**7):
|
83 |
+
# ASCII character
|
84 |
+
buf.append(str(c))
|
85 |
+
elif (2**7) <= cn < (2**16):
|
86 |
+
# single unicode escape sequence
|
87 |
+
buf.append('{\\u%d}' % cn)
|
88 |
+
elif (2**16) <= cn:
|
89 |
+
# RTF limits unicode to 16 bits.
|
90 |
+
# Force surrogate pairs
|
91 |
+
buf.append('{\\u%d}{\\u%d}' % surrogatepair(cn))
|
92 |
+
|
93 |
+
return ''.join(buf).replace('\n', '\\par\n')
|
94 |
+
|
95 |
+
def format_unencoded(self, tokensource, outfile):
|
96 |
+
# rtf 1.8 header
|
97 |
+
outfile.write('{\\rtf1\\ansi\\uc0\\deff0'
|
98 |
+
'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
|
99 |
+
'{\\colortbl;' % (self.fontface and
|
100 |
+
' ' + self._escape(self.fontface) or
|
101 |
+
''))
|
102 |
+
|
103 |
+
# convert colors and save them in a mapping to access them later.
|
104 |
+
color_mapping = {}
|
105 |
+
offset = 1
|
106 |
+
for _, style in self.style:
|
107 |
+
for color in style['color'], style['bgcolor'], style['border']:
|
108 |
+
if color and color not in color_mapping:
|
109 |
+
color_mapping[color] = offset
|
110 |
+
outfile.write('\\red%d\\green%d\\blue%d;' % (
|
111 |
+
int(color[0:2], 16),
|
112 |
+
int(color[2:4], 16),
|
113 |
+
int(color[4:6], 16)
|
114 |
+
))
|
115 |
+
offset += 1
|
116 |
+
outfile.write('}\\f0 ')
|
117 |
+
if self.fontsize:
|
118 |
+
outfile.write('\\fs%d' % self.fontsize)
|
119 |
+
|
120 |
+
# highlight stream
|
121 |
+
for ttype, value in tokensource:
|
122 |
+
while not self.style.styles_token(ttype) and ttype.parent:
|
123 |
+
ttype = ttype.parent
|
124 |
+
style = self.style.style_for_token(ttype)
|
125 |
+
buf = []
|
126 |
+
if style['bgcolor']:
|
127 |
+
buf.append('\\cb%d' % color_mapping[style['bgcolor']])
|
128 |
+
if style['color']:
|
129 |
+
buf.append('\\cf%d' % color_mapping[style['color']])
|
130 |
+
if style['bold']:
|
131 |
+
buf.append('\\b')
|
132 |
+
if style['italic']:
|
133 |
+
buf.append('\\i')
|
134 |
+
if style['underline']:
|
135 |
+
buf.append('\\ul')
|
136 |
+
if style['border']:
|
137 |
+
buf.append('\\chbrdr\\chcfpat%d' %
|
138 |
+
color_mapping[style['border']])
|
139 |
+
start = ''.join(buf)
|
140 |
+
if start:
|
141 |
+
outfile.write('{%s ' % start)
|
142 |
+
outfile.write(self._escape_text(value))
|
143 |
+
if start:
|
144 |
+
outfile.write('}')
|
145 |
+
|
146 |
+
outfile.write('}')
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/svg.py
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.svg
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for SVG output.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor.pygments.formatter import Formatter
|
12 |
+
from pip._vendor.pygments.token import Comment
|
13 |
+
from pip._vendor.pygments.util import get_bool_opt, get_int_opt
|
14 |
+
|
15 |
+
__all__ = ['SvgFormatter']
|
16 |
+
|
17 |
+
|
18 |
+
def escape_html(text):
|
19 |
+
"""Escape &, <, > as well as single and double quotes for HTML."""
|
20 |
+
return text.replace('&', '&'). \
|
21 |
+
replace('<', '<'). \
|
22 |
+
replace('>', '>'). \
|
23 |
+
replace('"', '"'). \
|
24 |
+
replace("'", ''')
|
25 |
+
|
26 |
+
|
27 |
+
class2style = {}
|
28 |
+
|
29 |
+
class SvgFormatter(Formatter):
|
30 |
+
"""
|
31 |
+
Format tokens as an SVG graphics file. This formatter is still experimental.
|
32 |
+
Each line of code is a ``<text>`` element with explicit ``x`` and ``y``
|
33 |
+
coordinates containing ``<tspan>`` elements with the individual token styles.
|
34 |
+
|
35 |
+
By default, this formatter outputs a full SVG document including doctype
|
36 |
+
declaration and the ``<svg>`` root element.
|
37 |
+
|
38 |
+
.. versionadded:: 0.9
|
39 |
+
|
40 |
+
Additional options accepted:
|
41 |
+
|
42 |
+
`nowrap`
|
43 |
+
Don't wrap the SVG ``<text>`` elements in ``<svg><g>`` elements and
|
44 |
+
don't add a XML declaration and a doctype. If true, the `fontfamily`
|
45 |
+
and `fontsize` options are ignored. Defaults to ``False``.
|
46 |
+
|
47 |
+
`fontfamily`
|
48 |
+
The value to give the wrapping ``<g>`` element's ``font-family``
|
49 |
+
attribute, defaults to ``"monospace"``.
|
50 |
+
|
51 |
+
`fontsize`
|
52 |
+
The value to give the wrapping ``<g>`` element's ``font-size``
|
53 |
+
attribute, defaults to ``"14px"``.
|
54 |
+
|
55 |
+
`linenos`
|
56 |
+
If ``True``, add line numbers (default: ``False``).
|
57 |
+
|
58 |
+
`linenostart`
|
59 |
+
The line number for the first line (default: ``1``).
|
60 |
+
|
61 |
+
`linenostep`
|
62 |
+
If set to a number n > 1, only every nth line number is printed.
|
63 |
+
|
64 |
+
`linenowidth`
|
65 |
+
Maximum width devoted to line numbers (default: ``3*ystep``, sufficient
|
66 |
+
for up to 4-digit line numbers. Increase width for longer code blocks).
|
67 |
+
|
68 |
+
`xoffset`
|
69 |
+
Starting offset in X direction, defaults to ``0``.
|
70 |
+
|
71 |
+
`yoffset`
|
72 |
+
Starting offset in Y direction, defaults to the font size if it is given
|
73 |
+
in pixels, or ``20`` else. (This is necessary since text coordinates
|
74 |
+
refer to the text baseline, not the top edge.)
|
75 |
+
|
76 |
+
`ystep`
|
77 |
+
Offset to add to the Y coordinate for each subsequent line. This should
|
78 |
+
roughly be the text size plus 5. It defaults to that value if the text
|
79 |
+
size is given in pixels, or ``25`` else.
|
80 |
+
|
81 |
+
`spacehack`
|
82 |
+
Convert spaces in the source to `` ``, which are non-breaking
|
83 |
+
spaces. SVG provides the ``xml:space`` attribute to control how
|
84 |
+
whitespace inside tags is handled, in theory, the ``preserve`` value
|
85 |
+
could be used to keep all whitespace as-is. However, many current SVG
|
86 |
+
viewers don't obey that rule, so this option is provided as a workaround
|
87 |
+
and defaults to ``True``.
|
88 |
+
"""
|
89 |
+
name = 'SVG'
|
90 |
+
aliases = ['svg']
|
91 |
+
filenames = ['*.svg']
|
92 |
+
|
93 |
+
def __init__(self, **options):
|
94 |
+
Formatter.__init__(self, **options)
|
95 |
+
self.nowrap = get_bool_opt(options, 'nowrap', False)
|
96 |
+
self.fontfamily = options.get('fontfamily', 'monospace')
|
97 |
+
self.fontsize = options.get('fontsize', '14px')
|
98 |
+
self.xoffset = get_int_opt(options, 'xoffset', 0)
|
99 |
+
fs = self.fontsize.strip()
|
100 |
+
if fs.endswith('px'): fs = fs[:-2].strip()
|
101 |
+
try:
|
102 |
+
int_fs = int(fs)
|
103 |
+
except:
|
104 |
+
int_fs = 20
|
105 |
+
self.yoffset = get_int_opt(options, 'yoffset', int_fs)
|
106 |
+
self.ystep = get_int_opt(options, 'ystep', int_fs + 5)
|
107 |
+
self.spacehack = get_bool_opt(options, 'spacehack', True)
|
108 |
+
self.linenos = get_bool_opt(options,'linenos',False)
|
109 |
+
self.linenostart = get_int_opt(options,'linenostart',1)
|
110 |
+
self.linenostep = get_int_opt(options,'linenostep',1)
|
111 |
+
self.linenowidth = get_int_opt(options,'linenowidth', 3*self.ystep)
|
112 |
+
self._stylecache = {}
|
113 |
+
|
114 |
+
def format_unencoded(self, tokensource, outfile):
|
115 |
+
"""
|
116 |
+
Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
|
117 |
+
tuples and write it into ``outfile``.
|
118 |
+
|
119 |
+
For our implementation we put all lines in their own 'line group'.
|
120 |
+
"""
|
121 |
+
x = self.xoffset
|
122 |
+
y = self.yoffset
|
123 |
+
if not self.nowrap:
|
124 |
+
if self.encoding:
|
125 |
+
outfile.write('<?xml version="1.0" encoding="%s"?>\n' %
|
126 |
+
self.encoding)
|
127 |
+
else:
|
128 |
+
outfile.write('<?xml version="1.0"?>\n')
|
129 |
+
outfile.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" '
|
130 |
+
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/'
|
131 |
+
'svg10.dtd">\n')
|
132 |
+
outfile.write('<svg xmlns="http://www.w3.org/2000/svg">\n')
|
133 |
+
outfile.write('<g font-family="%s" font-size="%s">\n' %
|
134 |
+
(self.fontfamily, self.fontsize))
|
135 |
+
|
136 |
+
counter = self.linenostart
|
137 |
+
counter_step = self.linenostep
|
138 |
+
counter_style = self._get_style(Comment)
|
139 |
+
line_x = x
|
140 |
+
|
141 |
+
if self.linenos:
|
142 |
+
if counter % counter_step == 0:
|
143 |
+
outfile.write('<text x="%s" y="%s" %s text-anchor="end">%s</text>' %
|
144 |
+
(x+self.linenowidth,y,counter_style,counter))
|
145 |
+
line_x += self.linenowidth + self.ystep
|
146 |
+
counter += 1
|
147 |
+
|
148 |
+
outfile.write('<text x="%s" y="%s" xml:space="preserve">' % (line_x, y))
|
149 |
+
for ttype, value in tokensource:
|
150 |
+
style = self._get_style(ttype)
|
151 |
+
tspan = style and '<tspan' + style + '>' or ''
|
152 |
+
tspanend = tspan and '</tspan>' or ''
|
153 |
+
value = escape_html(value)
|
154 |
+
if self.spacehack:
|
155 |
+
value = value.expandtabs().replace(' ', ' ')
|
156 |
+
parts = value.split('\n')
|
157 |
+
for part in parts[:-1]:
|
158 |
+
outfile.write(tspan + part + tspanend)
|
159 |
+
y += self.ystep
|
160 |
+
outfile.write('</text>\n')
|
161 |
+
if self.linenos and counter % counter_step == 0:
|
162 |
+
outfile.write('<text x="%s" y="%s" text-anchor="end" %s>%s</text>' %
|
163 |
+
(x+self.linenowidth,y,counter_style,counter))
|
164 |
+
|
165 |
+
counter += 1
|
166 |
+
outfile.write('<text x="%s" y="%s" ' 'xml:space="preserve">' % (line_x,y))
|
167 |
+
outfile.write(tspan + parts[-1] + tspanend)
|
168 |
+
outfile.write('</text>')
|
169 |
+
|
170 |
+
if not self.nowrap:
|
171 |
+
outfile.write('</g></svg>\n')
|
172 |
+
|
173 |
+
def _get_style(self, tokentype):
|
174 |
+
if tokentype in self._stylecache:
|
175 |
+
return self._stylecache[tokentype]
|
176 |
+
otokentype = tokentype
|
177 |
+
while not self.style.styles_token(tokentype):
|
178 |
+
tokentype = tokentype.parent
|
179 |
+
value = self.style.style_for_token(tokentype)
|
180 |
+
result = ''
|
181 |
+
if value['color']:
|
182 |
+
result = ' fill="#' + value['color'] + '"'
|
183 |
+
if value['bold']:
|
184 |
+
result += ' font-weight="bold"'
|
185 |
+
if value['italic']:
|
186 |
+
result += ' font-style="italic"'
|
187 |
+
self._stylecache[otokentype] = result
|
188 |
+
return result
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/terminal.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.terminal
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for terminal output with ANSI sequences.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor.pygments.formatter import Formatter
|
12 |
+
from pip._vendor.pygments.token import Keyword, Name, Comment, String, Error, \
|
13 |
+
Number, Operator, Generic, Token, Whitespace
|
14 |
+
from pip._vendor.pygments.console import ansiformat
|
15 |
+
from pip._vendor.pygments.util import get_choice_opt
|
16 |
+
|
17 |
+
|
18 |
+
__all__ = ['TerminalFormatter']
|
19 |
+
|
20 |
+
|
21 |
+
#: Map token types to a tuple of color values for light and dark
|
22 |
+
#: backgrounds.
|
23 |
+
TERMINAL_COLORS = {
|
24 |
+
Token: ('', ''),
|
25 |
+
|
26 |
+
Whitespace: ('gray', 'brightblack'),
|
27 |
+
Comment: ('gray', 'brightblack'),
|
28 |
+
Comment.Preproc: ('cyan', 'brightcyan'),
|
29 |
+
Keyword: ('blue', 'brightblue'),
|
30 |
+
Keyword.Type: ('cyan', 'brightcyan'),
|
31 |
+
Operator.Word: ('magenta', 'brightmagenta'),
|
32 |
+
Name.Builtin: ('cyan', 'brightcyan'),
|
33 |
+
Name.Function: ('green', 'brightgreen'),
|
34 |
+
Name.Namespace: ('_cyan_', '_brightcyan_'),
|
35 |
+
Name.Class: ('_green_', '_brightgreen_'),
|
36 |
+
Name.Exception: ('cyan', 'brightcyan'),
|
37 |
+
Name.Decorator: ('brightblack', 'gray'),
|
38 |
+
Name.Variable: ('red', 'brightred'),
|
39 |
+
Name.Constant: ('red', 'brightred'),
|
40 |
+
Name.Attribute: ('cyan', 'brightcyan'),
|
41 |
+
Name.Tag: ('brightblue', 'brightblue'),
|
42 |
+
String: ('yellow', 'yellow'),
|
43 |
+
Number: ('blue', 'brightblue'),
|
44 |
+
|
45 |
+
Generic.Deleted: ('brightred', 'brightred'),
|
46 |
+
Generic.Inserted: ('green', 'brightgreen'),
|
47 |
+
Generic.Heading: ('**', '**'),
|
48 |
+
Generic.Subheading: ('*magenta*', '*brightmagenta*'),
|
49 |
+
Generic.Prompt: ('**', '**'),
|
50 |
+
Generic.Error: ('brightred', 'brightred'),
|
51 |
+
|
52 |
+
Error: ('_brightred_', '_brightred_'),
|
53 |
+
}
|
54 |
+
|
55 |
+
|
56 |
+
class TerminalFormatter(Formatter):
|
57 |
+
r"""
|
58 |
+
Format tokens with ANSI color sequences, for output in a text console.
|
59 |
+
Color sequences are terminated at newlines, so that paging the output
|
60 |
+
works correctly.
|
61 |
+
|
62 |
+
The `get_style_defs()` method doesn't do anything special since there is
|
63 |
+
no support for common styles.
|
64 |
+
|
65 |
+
Options accepted:
|
66 |
+
|
67 |
+
`bg`
|
68 |
+
Set to ``"light"`` or ``"dark"`` depending on the terminal's background
|
69 |
+
(default: ``"light"``).
|
70 |
+
|
71 |
+
`colorscheme`
|
72 |
+
A dictionary mapping token types to (lightbg, darkbg) color names or
|
73 |
+
``None`` (default: ``None`` = use builtin colorscheme).
|
74 |
+
|
75 |
+
`linenos`
|
76 |
+
Set to ``True`` to have line numbers on the terminal output as well
|
77 |
+
(default: ``False`` = no line numbers).
|
78 |
+
"""
|
79 |
+
name = 'Terminal'
|
80 |
+
aliases = ['terminal', 'console']
|
81 |
+
filenames = []
|
82 |
+
|
83 |
+
def __init__(self, **options):
|
84 |
+
Formatter.__init__(self, **options)
|
85 |
+
self.darkbg = get_choice_opt(options, 'bg',
|
86 |
+
['light', 'dark'], 'light') == 'dark'
|
87 |
+
self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS
|
88 |
+
self.linenos = options.get('linenos', False)
|
89 |
+
self._lineno = 0
|
90 |
+
|
91 |
+
def format(self, tokensource, outfile):
|
92 |
+
return Formatter.format(self, tokensource, outfile)
|
93 |
+
|
94 |
+
def _write_lineno(self, outfile):
|
95 |
+
self._lineno += 1
|
96 |
+
outfile.write("%s%04d: " % (self._lineno != 1 and '\n' or '', self._lineno))
|
97 |
+
|
98 |
+
def _get_color(self, ttype):
|
99 |
+
# self.colorscheme is a dict containing usually generic types, so we
|
100 |
+
# have to walk the tree of dots. The base Token type must be a key,
|
101 |
+
# even if it's empty string, as in the default above.
|
102 |
+
colors = self.colorscheme.get(ttype)
|
103 |
+
while colors is None:
|
104 |
+
ttype = ttype.parent
|
105 |
+
colors = self.colorscheme.get(ttype)
|
106 |
+
return colors[self.darkbg]
|
107 |
+
|
108 |
+
def format_unencoded(self, tokensource, outfile):
|
109 |
+
if self.linenos:
|
110 |
+
self._write_lineno(outfile)
|
111 |
+
|
112 |
+
for ttype, value in tokensource:
|
113 |
+
color = self._get_color(ttype)
|
114 |
+
|
115 |
+
for line in value.splitlines(True):
|
116 |
+
if color:
|
117 |
+
outfile.write(ansiformat(color, line.rstrip('\n')))
|
118 |
+
else:
|
119 |
+
outfile.write(line.rstrip('\n'))
|
120 |
+
if line.endswith('\n'):
|
121 |
+
if self.linenos:
|
122 |
+
self._write_lineno(outfile)
|
123 |
+
else:
|
124 |
+
outfile.write('\n')
|
125 |
+
|
126 |
+
if self.linenos:
|
127 |
+
outfile.write("\n")
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/terminal256.py
ADDED
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.formatters.terminal256
|
3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Formatter for 256-color terminal output with ANSI sequences.
|
6 |
+
|
7 |
+
RGB-to-XTERM color conversion routines adapted from xterm256-conv
|
8 |
+
tool (http://frexx.de/xterm-256-notes/data/xterm256-conv2.tar.bz2)
|
9 |
+
by Wolfgang Frisch.
|
10 |
+
|
11 |
+
Formatter version 1.
|
12 |
+
|
13 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
14 |
+
:license: BSD, see LICENSE for details.
|
15 |
+
"""
|
16 |
+
|
17 |
+
# TODO:
|
18 |
+
# - Options to map style's bold/underline/italic/border attributes
|
19 |
+
# to some ANSI attrbutes (something like 'italic=underline')
|
20 |
+
# - An option to output "style RGB to xterm RGB/index" conversion table
|
21 |
+
# - An option to indicate that we are running in "reverse background"
|
22 |
+
# xterm. This means that default colors are white-on-black, not
|
23 |
+
# black-on-while, so colors like "white background" need to be converted
|
24 |
+
# to "white background, black foreground", etc...
|
25 |
+
|
26 |
+
from pip._vendor.pygments.formatter import Formatter
|
27 |
+
from pip._vendor.pygments.console import codes
|
28 |
+
from pip._vendor.pygments.style import ansicolors
|
29 |
+
|
30 |
+
|
31 |
+
__all__ = ['Terminal256Formatter', 'TerminalTrueColorFormatter']
|
32 |
+
|
33 |
+
|
34 |
+
class EscapeSequence:
|
35 |
+
def __init__(self, fg=None, bg=None, bold=False, underline=False, italic=False):
|
36 |
+
self.fg = fg
|
37 |
+
self.bg = bg
|
38 |
+
self.bold = bold
|
39 |
+
self.underline = underline
|
40 |
+
self.italic = italic
|
41 |
+
|
42 |
+
def escape(self, attrs):
|
43 |
+
if len(attrs):
|
44 |
+
return "\x1b[" + ";".join(attrs) + "m"
|
45 |
+
return ""
|
46 |
+
|
47 |
+
def color_string(self):
|
48 |
+
attrs = []
|
49 |
+
if self.fg is not None:
|
50 |
+
if self.fg in ansicolors:
|
51 |
+
esc = codes[self.fg.replace('ansi','')]
|
52 |
+
if ';01m' in esc:
|
53 |
+
self.bold = True
|
54 |
+
# extract fg color code.
|
55 |
+
attrs.append(esc[2:4])
|
56 |
+
else:
|
57 |
+
attrs.extend(("38", "5", "%i" % self.fg))
|
58 |
+
if self.bg is not None:
|
59 |
+
if self.bg in ansicolors:
|
60 |
+
esc = codes[self.bg.replace('ansi','')]
|
61 |
+
# extract fg color code, add 10 for bg.
|
62 |
+
attrs.append(str(int(esc[2:4])+10))
|
63 |
+
else:
|
64 |
+
attrs.extend(("48", "5", "%i" % self.bg))
|
65 |
+
if self.bold:
|
66 |
+
attrs.append("01")
|
67 |
+
if self.underline:
|
68 |
+
attrs.append("04")
|
69 |
+
if self.italic:
|
70 |
+
attrs.append("03")
|
71 |
+
return self.escape(attrs)
|
72 |
+
|
73 |
+
def true_color_string(self):
|
74 |
+
attrs = []
|
75 |
+
if self.fg:
|
76 |
+
attrs.extend(("38", "2", str(self.fg[0]), str(self.fg[1]), str(self.fg[2])))
|
77 |
+
if self.bg:
|
78 |
+
attrs.extend(("48", "2", str(self.bg[0]), str(self.bg[1]), str(self.bg[2])))
|
79 |
+
if self.bold:
|
80 |
+
attrs.append("01")
|
81 |
+
if self.underline:
|
82 |
+
attrs.append("04")
|
83 |
+
if self.italic:
|
84 |
+
attrs.append("03")
|
85 |
+
return self.escape(attrs)
|
86 |
+
|
87 |
+
def reset_string(self):
|
88 |
+
attrs = []
|
89 |
+
if self.fg is not None:
|
90 |
+
attrs.append("39")
|
91 |
+
if self.bg is not None:
|
92 |
+
attrs.append("49")
|
93 |
+
if self.bold or self.underline or self.italic:
|
94 |
+
attrs.append("00")
|
95 |
+
return self.escape(attrs)
|
96 |
+
|
97 |
+
|
98 |
+
class Terminal256Formatter(Formatter):
|
99 |
+
"""
|
100 |
+
Format tokens with ANSI color sequences, for output in a 256-color
|
101 |
+
terminal or console. Like in `TerminalFormatter` color sequences
|
102 |
+
are terminated at newlines, so that paging the output works correctly.
|
103 |
+
|
104 |
+
The formatter takes colors from a style defined by the `style` option
|
105 |
+
and converts them to nearest ANSI 256-color escape sequences. Bold and
|
106 |
+
underline attributes from the style are preserved (and displayed).
|
107 |
+
|
108 |
+
.. versionadded:: 0.9
|
109 |
+
|
110 |
+
.. versionchanged:: 2.2
|
111 |
+
If the used style defines foreground colors in the form ``#ansi*``, then
|
112 |
+
`Terminal256Formatter` will map these to non extended foreground color.
|
113 |
+
See :ref:`AnsiTerminalStyle` for more information.
|
114 |
+
|
115 |
+
.. versionchanged:: 2.4
|
116 |
+
The ANSI color names have been updated with names that are easier to
|
117 |
+
understand and align with colornames of other projects and terminals.
|
118 |
+
See :ref:`this table <new-ansi-color-names>` for more information.
|
119 |
+
|
120 |
+
|
121 |
+
Options accepted:
|
122 |
+
|
123 |
+
`style`
|
124 |
+
The style to use, can be a string or a Style subclass (default:
|
125 |
+
``'default'``).
|
126 |
+
|
127 |
+
`linenos`
|
128 |
+
Set to ``True`` to have line numbers on the terminal output as well
|
129 |
+
(default: ``False`` = no line numbers).
|
130 |
+
"""
|
131 |
+
name = 'Terminal256'
|
132 |
+
aliases = ['terminal256', 'console256', '256']
|
133 |
+
filenames = []
|
134 |
+
|
135 |
+
def __init__(self, **options):
|
136 |
+
Formatter.__init__(self, **options)
|
137 |
+
|
138 |
+
self.xterm_colors = []
|
139 |
+
self.best_match = {}
|
140 |
+
self.style_string = {}
|
141 |
+
|
142 |
+
self.usebold = 'nobold' not in options
|
143 |
+
self.useunderline = 'nounderline' not in options
|
144 |
+
self.useitalic = 'noitalic' not in options
|
145 |
+
|
146 |
+
self._build_color_table() # build an RGB-to-256 color conversion table
|
147 |
+
self._setup_styles() # convert selected style's colors to term. colors
|
148 |
+
|
149 |
+
self.linenos = options.get('linenos', False)
|
150 |
+
self._lineno = 0
|
151 |
+
|
152 |
+
def _build_color_table(self):
|
153 |
+
# colors 0..15: 16 basic colors
|
154 |
+
|
155 |
+
self.xterm_colors.append((0x00, 0x00, 0x00)) # 0
|
156 |
+
self.xterm_colors.append((0xcd, 0x00, 0x00)) # 1
|
157 |
+
self.xterm_colors.append((0x00, 0xcd, 0x00)) # 2
|
158 |
+
self.xterm_colors.append((0xcd, 0xcd, 0x00)) # 3
|
159 |
+
self.xterm_colors.append((0x00, 0x00, 0xee)) # 4
|
160 |
+
self.xterm_colors.append((0xcd, 0x00, 0xcd)) # 5
|
161 |
+
self.xterm_colors.append((0x00, 0xcd, 0xcd)) # 6
|
162 |
+
self.xterm_colors.append((0xe5, 0xe5, 0xe5)) # 7
|
163 |
+
self.xterm_colors.append((0x7f, 0x7f, 0x7f)) # 8
|
164 |
+
self.xterm_colors.append((0xff, 0x00, 0x00)) # 9
|
165 |
+
self.xterm_colors.append((0x00, 0xff, 0x00)) # 10
|
166 |
+
self.xterm_colors.append((0xff, 0xff, 0x00)) # 11
|
167 |
+
self.xterm_colors.append((0x5c, 0x5c, 0xff)) # 12
|
168 |
+
self.xterm_colors.append((0xff, 0x00, 0xff)) # 13
|
169 |
+
self.xterm_colors.append((0x00, 0xff, 0xff)) # 14
|
170 |
+
self.xterm_colors.append((0xff, 0xff, 0xff)) # 15
|
171 |
+
|
172 |
+
# colors 16..232: the 6x6x6 color cube
|
173 |
+
|
174 |
+
valuerange = (0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff)
|
175 |
+
|
176 |
+
for i in range(217):
|
177 |
+
r = valuerange[(i // 36) % 6]
|
178 |
+
g = valuerange[(i // 6) % 6]
|
179 |
+
b = valuerange[i % 6]
|
180 |
+
self.xterm_colors.append((r, g, b))
|
181 |
+
|
182 |
+
# colors 233..253: grayscale
|
183 |
+
|
184 |
+
for i in range(1, 22):
|
185 |
+
v = 8 + i * 10
|
186 |
+
self.xterm_colors.append((v, v, v))
|
187 |
+
|
188 |
+
def _closest_color(self, r, g, b):
|
189 |
+
distance = 257*257*3 # "infinity" (>distance from #000000 to #ffffff)
|
190 |
+
match = 0
|
191 |
+
|
192 |
+
for i in range(0, 254):
|
193 |
+
values = self.xterm_colors[i]
|
194 |
+
|
195 |
+
rd = r - values[0]
|
196 |
+
gd = g - values[1]
|
197 |
+
bd = b - values[2]
|
198 |
+
d = rd*rd + gd*gd + bd*bd
|
199 |
+
|
200 |
+
if d < distance:
|
201 |
+
match = i
|
202 |
+
distance = d
|
203 |
+
return match
|
204 |
+
|
205 |
+
def _color_index(self, color):
|
206 |
+
index = self.best_match.get(color, None)
|
207 |
+
if color in ansicolors:
|
208 |
+
# strip the `ansi/#ansi` part and look up code
|
209 |
+
index = color
|
210 |
+
self.best_match[color] = index
|
211 |
+
if index is None:
|
212 |
+
try:
|
213 |
+
rgb = int(str(color), 16)
|
214 |
+
except ValueError:
|
215 |
+
rgb = 0
|
216 |
+
|
217 |
+
r = (rgb >> 16) & 0xff
|
218 |
+
g = (rgb >> 8) & 0xff
|
219 |
+
b = rgb & 0xff
|
220 |
+
index = self._closest_color(r, g, b)
|
221 |
+
self.best_match[color] = index
|
222 |
+
return index
|
223 |
+
|
224 |
+
def _setup_styles(self):
|
225 |
+
for ttype, ndef in self.style:
|
226 |
+
escape = EscapeSequence()
|
227 |
+
# get foreground from ansicolor if set
|
228 |
+
if ndef['ansicolor']:
|
229 |
+
escape.fg = self._color_index(ndef['ansicolor'])
|
230 |
+
elif ndef['color']:
|
231 |
+
escape.fg = self._color_index(ndef['color'])
|
232 |
+
if ndef['bgansicolor']:
|
233 |
+
escape.bg = self._color_index(ndef['bgansicolor'])
|
234 |
+
elif ndef['bgcolor']:
|
235 |
+
escape.bg = self._color_index(ndef['bgcolor'])
|
236 |
+
if self.usebold and ndef['bold']:
|
237 |
+
escape.bold = True
|
238 |
+
if self.useunderline and ndef['underline']:
|
239 |
+
escape.underline = True
|
240 |
+
if self.useitalic and ndef['italic']:
|
241 |
+
escape.italic = True
|
242 |
+
self.style_string[str(ttype)] = (escape.color_string(),
|
243 |
+
escape.reset_string())
|
244 |
+
|
245 |
+
def _write_lineno(self, outfile):
|
246 |
+
self._lineno += 1
|
247 |
+
outfile.write("%s%04d: " % (self._lineno != 1 and '\n' or '', self._lineno))
|
248 |
+
|
249 |
+
def format(self, tokensource, outfile):
|
250 |
+
return Formatter.format(self, tokensource, outfile)
|
251 |
+
|
252 |
+
def format_unencoded(self, tokensource, outfile):
|
253 |
+
if self.linenos:
|
254 |
+
self._write_lineno(outfile)
|
255 |
+
|
256 |
+
for ttype, value in tokensource:
|
257 |
+
not_found = True
|
258 |
+
while ttype and not_found:
|
259 |
+
try:
|
260 |
+
# outfile.write( "<" + str(ttype) + ">" )
|
261 |
+
on, off = self.style_string[str(ttype)]
|
262 |
+
|
263 |
+
# Like TerminalFormatter, add "reset colors" escape sequence
|
264 |
+
# on newline.
|
265 |
+
spl = value.split('\n')
|
266 |
+
for line in spl[:-1]:
|
267 |
+
if line:
|
268 |
+
outfile.write(on + line + off)
|
269 |
+
if self.linenos:
|
270 |
+
self._write_lineno(outfile)
|
271 |
+
else:
|
272 |
+
outfile.write('\n')
|
273 |
+
|
274 |
+
if spl[-1]:
|
275 |
+
outfile.write(on + spl[-1] + off)
|
276 |
+
|
277 |
+
not_found = False
|
278 |
+
# outfile.write( '#' + str(ttype) + '#' )
|
279 |
+
|
280 |
+
except KeyError:
|
281 |
+
# ottype = ttype
|
282 |
+
ttype = ttype.parent
|
283 |
+
# outfile.write( '!' + str(ottype) + '->' + str(ttype) + '!' )
|
284 |
+
|
285 |
+
if not_found:
|
286 |
+
outfile.write(value)
|
287 |
+
|
288 |
+
if self.linenos:
|
289 |
+
outfile.write("\n")
|
290 |
+
|
291 |
+
|
292 |
+
|
293 |
+
class TerminalTrueColorFormatter(Terminal256Formatter):
|
294 |
+
r"""
|
295 |
+
Format tokens with ANSI color sequences, for output in a true-color
|
296 |
+
terminal or console. Like in `TerminalFormatter` color sequences
|
297 |
+
are terminated at newlines, so that paging the output works correctly.
|
298 |
+
|
299 |
+
.. versionadded:: 2.1
|
300 |
+
|
301 |
+
Options accepted:
|
302 |
+
|
303 |
+
`style`
|
304 |
+
The style to use, can be a string or a Style subclass (default:
|
305 |
+
``'default'``).
|
306 |
+
"""
|
307 |
+
name = 'TerminalTrueColor'
|
308 |
+
aliases = ['terminal16m', 'console16m', '16m']
|
309 |
+
filenames = []
|
310 |
+
|
311 |
+
def _build_color_table(self):
|
312 |
+
pass
|
313 |
+
|
314 |
+
def _color_tuple(self, color):
|
315 |
+
try:
|
316 |
+
rgb = int(str(color), 16)
|
317 |
+
except ValueError:
|
318 |
+
return None
|
319 |
+
r = (rgb >> 16) & 0xff
|
320 |
+
g = (rgb >> 8) & 0xff
|
321 |
+
b = rgb & 0xff
|
322 |
+
return (r, g, b)
|
323 |
+
|
324 |
+
def _setup_styles(self):
|
325 |
+
for ttype, ndef in self.style:
|
326 |
+
escape = EscapeSequence()
|
327 |
+
if ndef['color']:
|
328 |
+
escape.fg = self._color_tuple(ndef['color'])
|
329 |
+
if ndef['bgcolor']:
|
330 |
+
escape.bg = self._color_tuple(ndef['bgcolor'])
|
331 |
+
if self.usebold and ndef['bold']:
|
332 |
+
escape.bold = True
|
333 |
+
if self.useunderline and ndef['underline']:
|
334 |
+
escape.underline = True
|
335 |
+
if self.useitalic and ndef['italic']:
|
336 |
+
escape.italic = True
|
337 |
+
self.style_string[str(ttype)] = (escape.true_color_string(),
|
338 |
+
escape.reset_string())
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/styles/__init__.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
pygments.styles
|
3 |
+
~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Contains built-in styles.
|
6 |
+
|
7 |
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
|
8 |
+
:license: BSD, see LICENSE for details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor.pygments.plugin import find_plugin_styles
|
12 |
+
from pip._vendor.pygments.util import ClassNotFound
|
13 |
+
|
14 |
+
|
15 |
+
#: Maps style names to 'submodule::classname'.
|
16 |
+
STYLE_MAP = {
|
17 |
+
'default': 'default::DefaultStyle',
|
18 |
+
'emacs': 'emacs::EmacsStyle',
|
19 |
+
'friendly': 'friendly::FriendlyStyle',
|
20 |
+
'friendly_grayscale': 'friendly_grayscale::FriendlyGrayscaleStyle',
|
21 |
+
'colorful': 'colorful::ColorfulStyle',
|
22 |
+
'autumn': 'autumn::AutumnStyle',
|
23 |
+
'murphy': 'murphy::MurphyStyle',
|
24 |
+
'manni': 'manni::ManniStyle',
|
25 |
+
'material': 'material::MaterialStyle',
|
26 |
+
'monokai': 'monokai::MonokaiStyle',
|
27 |
+
'perldoc': 'perldoc::PerldocStyle',
|
28 |
+
'pastie': 'pastie::PastieStyle',
|
29 |
+
'borland': 'borland::BorlandStyle',
|
30 |
+
'trac': 'trac::TracStyle',
|
31 |
+
'native': 'native::NativeStyle',
|
32 |
+
'fruity': 'fruity::FruityStyle',
|
33 |
+
'bw': 'bw::BlackWhiteStyle',
|
34 |
+
'vim': 'vim::VimStyle',
|
35 |
+
'vs': 'vs::VisualStudioStyle',
|
36 |
+
'tango': 'tango::TangoStyle',
|
37 |
+
'rrt': 'rrt::RrtStyle',
|
38 |
+
'xcode': 'xcode::XcodeStyle',
|
39 |
+
'igor': 'igor::IgorStyle',
|
40 |
+
'paraiso-light': 'paraiso_light::ParaisoLightStyle',
|
41 |
+
'paraiso-dark': 'paraiso_dark::ParaisoDarkStyle',
|
42 |
+
'lovelace': 'lovelace::LovelaceStyle',
|
43 |
+
'algol': 'algol::AlgolStyle',
|
44 |
+
'algol_nu': 'algol_nu::Algol_NuStyle',
|
45 |
+
'arduino': 'arduino::ArduinoStyle',
|
46 |
+
'rainbow_dash': 'rainbow_dash::RainbowDashStyle',
|
47 |
+
'abap': 'abap::AbapStyle',
|
48 |
+
'solarized-dark': 'solarized::SolarizedDarkStyle',
|
49 |
+
'solarized-light': 'solarized::SolarizedLightStyle',
|
50 |
+
'sas': 'sas::SasStyle',
|
51 |
+
'stata': 'stata_light::StataLightStyle',
|
52 |
+
'stata-light': 'stata_light::StataLightStyle',
|
53 |
+
'stata-dark': 'stata_dark::StataDarkStyle',
|
54 |
+
'inkpot': 'inkpot::InkPotStyle',
|
55 |
+
'zenburn': 'zenburn::ZenburnStyle',
|
56 |
+
'gruvbox-dark': 'gruvbox::GruvboxDarkStyle',
|
57 |
+
'gruvbox-light': 'gruvbox::GruvboxLightStyle',
|
58 |
+
'dracula': 'dracula::DraculaStyle',
|
59 |
+
'one-dark': 'onedark::OneDarkStyle',
|
60 |
+
'lilypond' : 'lilypond::LilyPondStyle',
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
def get_style_by_name(name):
|
65 |
+
if name in STYLE_MAP:
|
66 |
+
mod, cls = STYLE_MAP[name].split('::')
|
67 |
+
builtin = "yes"
|
68 |
+
else:
|
69 |
+
for found_name, style in find_plugin_styles():
|
70 |
+
if name == found_name:
|
71 |
+
return style
|
72 |
+
# perhaps it got dropped into our styles package
|
73 |
+
builtin = ""
|
74 |
+
mod = name
|
75 |
+
cls = name.title() + "Style"
|
76 |
+
|
77 |
+
try:
|
78 |
+
mod = __import__('pygments.styles.' + mod, None, None, [cls])
|
79 |
+
except ImportError:
|
80 |
+
raise ClassNotFound("Could not find style module %r" % mod +
|
81 |
+
(builtin and ", though it should be builtin") + ".")
|
82 |
+
try:
|
83 |
+
return getattr(mod, cls)
|
84 |
+
except AttributeError:
|
85 |
+
raise ClassNotFound("Could not find style class %r in style module." % cls)
|
86 |
+
|
87 |
+
|
88 |
+
def get_all_styles():
|
89 |
+
"""Return a generator for all styles by name,
|
90 |
+
both builtin and plugin."""
|
91 |
+
yield from STYLE_MAP
|
92 |
+
for name, _ in find_plugin_styles():
|
93 |
+
yield name
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/pygments/styles/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (3.22 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/__init__.py
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Rich text and beautiful formatting in the terminal."""
|
2 |
+
|
3 |
+
import os
|
4 |
+
from typing import Callable, IO, TYPE_CHECKING, Any, Optional
|
5 |
+
|
6 |
+
from ._extension import load_ipython_extension
|
7 |
+
|
8 |
+
__all__ = ["get_console", "reconfigure", "print", "inspect"]
|
9 |
+
|
10 |
+
if TYPE_CHECKING:
|
11 |
+
from .console import Console
|
12 |
+
|
13 |
+
# Global console used by alternative print
|
14 |
+
_console: Optional["Console"] = None
|
15 |
+
|
16 |
+
_IMPORT_CWD = os.path.abspath(os.getcwd())
|
17 |
+
|
18 |
+
|
19 |
+
def get_console() -> "Console":
|
20 |
+
"""Get a global :class:`~rich.console.Console` instance. This function is used when Rich requires a Console,
|
21 |
+
and hasn't been explicitly given one.
|
22 |
+
|
23 |
+
Returns:
|
24 |
+
Console: A console instance.
|
25 |
+
"""
|
26 |
+
global _console
|
27 |
+
if _console is None:
|
28 |
+
from .console import Console
|
29 |
+
|
30 |
+
_console = Console()
|
31 |
+
|
32 |
+
return _console
|
33 |
+
|
34 |
+
|
35 |
+
def reconfigure(*args: Any, **kwargs: Any) -> None:
|
36 |
+
"""Reconfigures the global console by replacing it with another.
|
37 |
+
|
38 |
+
Args:
|
39 |
+
console (Console): Replacement console instance.
|
40 |
+
"""
|
41 |
+
from pip._vendor.rich.console import Console
|
42 |
+
|
43 |
+
new_console = Console(*args, **kwargs)
|
44 |
+
_console = get_console()
|
45 |
+
_console.__dict__ = new_console.__dict__
|
46 |
+
|
47 |
+
|
48 |
+
def print(
|
49 |
+
*objects: Any,
|
50 |
+
sep: str = " ",
|
51 |
+
end: str = "\n",
|
52 |
+
file: Optional[IO[str]] = None,
|
53 |
+
flush: bool = False,
|
54 |
+
) -> None:
|
55 |
+
r"""Print object(s) supplied via positional arguments.
|
56 |
+
This function has an identical signature to the built-in print.
|
57 |
+
For more advanced features, see the :class:`~rich.console.Console` class.
|
58 |
+
|
59 |
+
Args:
|
60 |
+
sep (str, optional): Separator between printed objects. Defaults to " ".
|
61 |
+
end (str, optional): Character to write at end of output. Defaults to "\\n".
|
62 |
+
file (IO[str], optional): File to write to, or None for stdout. Defaults to None.
|
63 |
+
flush (bool, optional): Has no effect as Rich always flushes output. Defaults to False.
|
64 |
+
|
65 |
+
"""
|
66 |
+
from .console import Console
|
67 |
+
|
68 |
+
write_console = get_console() if file is None else Console(file=file)
|
69 |
+
return write_console.print(*objects, sep=sep, end=end)
|
70 |
+
|
71 |
+
|
72 |
+
def print_json(
|
73 |
+
json: Optional[str] = None,
|
74 |
+
*,
|
75 |
+
data: Any = None,
|
76 |
+
indent: int = 2,
|
77 |
+
highlight: bool = True,
|
78 |
+
skip_keys: bool = False,
|
79 |
+
ensure_ascii: bool = True,
|
80 |
+
check_circular: bool = True,
|
81 |
+
allow_nan: bool = True,
|
82 |
+
default: Optional[Callable[[Any], Any]] = None,
|
83 |
+
sort_keys: bool = False,
|
84 |
+
) -> None:
|
85 |
+
"""Pretty prints JSON. Output will be valid JSON.
|
86 |
+
|
87 |
+
Args:
|
88 |
+
json (str): A string containing JSON.
|
89 |
+
data (Any): If json is not supplied, then encode this data.
|
90 |
+
indent (int, optional): Number of spaces to indent. Defaults to 2.
|
91 |
+
highlight (bool, optional): Enable highlighting of output: Defaults to True.
|
92 |
+
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
|
93 |
+
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
|
94 |
+
check_circular (bool, optional): Check for circular references. Defaults to True.
|
95 |
+
allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
|
96 |
+
default (Callable, optional): A callable that converts values that can not be encoded
|
97 |
+
in to something that can be JSON encoded. Defaults to None.
|
98 |
+
sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
|
99 |
+
"""
|
100 |
+
|
101 |
+
get_console().print_json(
|
102 |
+
json,
|
103 |
+
data=data,
|
104 |
+
indent=indent,
|
105 |
+
highlight=highlight,
|
106 |
+
skip_keys=skip_keys,
|
107 |
+
ensure_ascii=ensure_ascii,
|
108 |
+
check_circular=check_circular,
|
109 |
+
allow_nan=allow_nan,
|
110 |
+
default=default,
|
111 |
+
sort_keys=sort_keys,
|
112 |
+
)
|
113 |
+
|
114 |
+
|
115 |
+
def inspect(
|
116 |
+
obj: Any,
|
117 |
+
*,
|
118 |
+
console: Optional["Console"] = None,
|
119 |
+
title: Optional[str] = None,
|
120 |
+
help: bool = False,
|
121 |
+
methods: bool = False,
|
122 |
+
docs: bool = True,
|
123 |
+
private: bool = False,
|
124 |
+
dunder: bool = False,
|
125 |
+
sort: bool = True,
|
126 |
+
all: bool = False,
|
127 |
+
value: bool = True,
|
128 |
+
) -> None:
|
129 |
+
"""Inspect any Python object.
|
130 |
+
|
131 |
+
* inspect(<OBJECT>) to see summarized info.
|
132 |
+
* inspect(<OBJECT>, methods=True) to see methods.
|
133 |
+
* inspect(<OBJECT>, help=True) to see full (non-abbreviated) help.
|
134 |
+
* inspect(<OBJECT>, private=True) to see private attributes (single underscore).
|
135 |
+
* inspect(<OBJECT>, dunder=True) to see attributes beginning with double underscore.
|
136 |
+
* inspect(<OBJECT>, all=True) to see all attributes.
|
137 |
+
|
138 |
+
Args:
|
139 |
+
obj (Any): An object to inspect.
|
140 |
+
title (str, optional): Title to display over inspect result, or None use type. Defaults to None.
|
141 |
+
help (bool, optional): Show full help text rather than just first paragraph. Defaults to False.
|
142 |
+
methods (bool, optional): Enable inspection of callables. Defaults to False.
|
143 |
+
docs (bool, optional): Also render doc strings. Defaults to True.
|
144 |
+
private (bool, optional): Show private attributes (beginning with underscore). Defaults to False.
|
145 |
+
dunder (bool, optional): Show attributes starting with double underscore. Defaults to False.
|
146 |
+
sort (bool, optional): Sort attributes alphabetically. Defaults to True.
|
147 |
+
all (bool, optional): Show all attributes. Defaults to False.
|
148 |
+
value (bool, optional): Pretty print value. Defaults to True.
|
149 |
+
"""
|
150 |
+
_console = console or get_console()
|
151 |
+
from pip._vendor.rich._inspect import Inspect
|
152 |
+
|
153 |
+
# Special case for inspect(inspect)
|
154 |
+
is_inspect = obj is inspect
|
155 |
+
|
156 |
+
_inspect = Inspect(
|
157 |
+
obj,
|
158 |
+
title=title,
|
159 |
+
help=is_inspect or help,
|
160 |
+
methods=is_inspect or methods,
|
161 |
+
docs=is_inspect or docs,
|
162 |
+
private=private,
|
163 |
+
dunder=dunder,
|
164 |
+
sort=sort,
|
165 |
+
all=all,
|
166 |
+
value=value,
|
167 |
+
)
|
168 |
+
_console.print(_inspect)
|
169 |
+
|
170 |
+
|
171 |
+
if __name__ == "__main__": # pragma: no cover
|
172 |
+
print("Hello, **World**")
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/__main__.py
ADDED
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import colorsys
|
2 |
+
import io
|
3 |
+
from time import process_time
|
4 |
+
|
5 |
+
from pip._vendor.rich import box
|
6 |
+
from pip._vendor.rich.color import Color
|
7 |
+
from pip._vendor.rich.console import Console, ConsoleOptions, Group, RenderableType, RenderResult
|
8 |
+
from pip._vendor.rich.markdown import Markdown
|
9 |
+
from pip._vendor.rich.measure import Measurement
|
10 |
+
from pip._vendor.rich.pretty import Pretty
|
11 |
+
from pip._vendor.rich.segment import Segment
|
12 |
+
from pip._vendor.rich.style import Style
|
13 |
+
from pip._vendor.rich.syntax import Syntax
|
14 |
+
from pip._vendor.rich.table import Table
|
15 |
+
from pip._vendor.rich.text import Text
|
16 |
+
|
17 |
+
|
18 |
+
class ColorBox:
|
19 |
+
def __rich_console__(
|
20 |
+
self, console: Console, options: ConsoleOptions
|
21 |
+
) -> RenderResult:
|
22 |
+
for y in range(0, 5):
|
23 |
+
for x in range(options.max_width):
|
24 |
+
h = x / options.max_width
|
25 |
+
l = 0.1 + ((y / 5) * 0.7)
|
26 |
+
r1, g1, b1 = colorsys.hls_to_rgb(h, l, 1.0)
|
27 |
+
r2, g2, b2 = colorsys.hls_to_rgb(h, l + 0.7 / 10, 1.0)
|
28 |
+
bgcolor = Color.from_rgb(r1 * 255, g1 * 255, b1 * 255)
|
29 |
+
color = Color.from_rgb(r2 * 255, g2 * 255, b2 * 255)
|
30 |
+
yield Segment("▄", Style(color=color, bgcolor=bgcolor))
|
31 |
+
yield Segment.line()
|
32 |
+
|
33 |
+
def __rich_measure__(
|
34 |
+
self, console: "Console", options: ConsoleOptions
|
35 |
+
) -> Measurement:
|
36 |
+
return Measurement(1, options.max_width)
|
37 |
+
|
38 |
+
|
39 |
+
def make_test_card() -> Table:
|
40 |
+
"""Get a renderable that demonstrates a number of features."""
|
41 |
+
table = Table.grid(padding=1, pad_edge=True)
|
42 |
+
table.title = "Rich features"
|
43 |
+
table.add_column("Feature", no_wrap=True, justify="center", style="bold red")
|
44 |
+
table.add_column("Demonstration")
|
45 |
+
|
46 |
+
color_table = Table(
|
47 |
+
box=None,
|
48 |
+
expand=False,
|
49 |
+
show_header=False,
|
50 |
+
show_edge=False,
|
51 |
+
pad_edge=False,
|
52 |
+
)
|
53 |
+
color_table.add_row(
|
54 |
+
# "[bold yellow]256[/] colors or [bold green]16.7 million[/] colors [blue](if supported by your terminal)[/].",
|
55 |
+
(
|
56 |
+
"✓ [bold green]4-bit color[/]\n"
|
57 |
+
"✓ [bold blue]8-bit color[/]\n"
|
58 |
+
"✓ [bold magenta]Truecolor (16.7 million)[/]\n"
|
59 |
+
"✓ [bold yellow]Dumb terminals[/]\n"
|
60 |
+
"✓ [bold cyan]Automatic color conversion"
|
61 |
+
),
|
62 |
+
ColorBox(),
|
63 |
+
)
|
64 |
+
|
65 |
+
table.add_row("Colors", color_table)
|
66 |
+
|
67 |
+
table.add_row(
|
68 |
+
"Styles",
|
69 |
+
"All ansi styles: [bold]bold[/], [dim]dim[/], [italic]italic[/italic], [underline]underline[/], [strike]strikethrough[/], [reverse]reverse[/], and even [blink]blink[/].",
|
70 |
+
)
|
71 |
+
|
72 |
+
lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in metus sed sapien ultricies pretium a at justo. Maecenas luctus velit et auctor maximus."
|
73 |
+
lorem_table = Table.grid(padding=1, collapse_padding=True)
|
74 |
+
lorem_table.pad_edge = False
|
75 |
+
lorem_table.add_row(
|
76 |
+
Text(lorem, justify="left", style="green"),
|
77 |
+
Text(lorem, justify="center", style="yellow"),
|
78 |
+
Text(lorem, justify="right", style="blue"),
|
79 |
+
Text(lorem, justify="full", style="red"),
|
80 |
+
)
|
81 |
+
table.add_row(
|
82 |
+
"Text",
|
83 |
+
Group(
|
84 |
+
Text.from_markup(
|
85 |
+
"""Word wrap text. Justify [green]left[/], [yellow]center[/], [blue]right[/] or [red]full[/].\n"""
|
86 |
+
),
|
87 |
+
lorem_table,
|
88 |
+
),
|
89 |
+
)
|
90 |
+
|
91 |
+
def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Table:
|
92 |
+
table = Table(show_header=False, pad_edge=False, box=None, expand=True)
|
93 |
+
table.add_column("1", ratio=1)
|
94 |
+
table.add_column("2", ratio=1)
|
95 |
+
table.add_row(renderable1, renderable2)
|
96 |
+
return table
|
97 |
+
|
98 |
+
table.add_row(
|
99 |
+
"Asian\nlanguage\nsupport",
|
100 |
+
":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다",
|
101 |
+
)
|
102 |
+
|
103 |
+
markup_example = (
|
104 |
+
"[bold magenta]Rich[/] supports a simple [i]bbcode[/i]-like [b]markup[/b] for [yellow]color[/], [underline]style[/], and emoji! "
|
105 |
+
":+1: :apple: :ant: :bear: :baguette_bread: :bus: "
|
106 |
+
)
|
107 |
+
table.add_row("Markup", markup_example)
|
108 |
+
|
109 |
+
example_table = Table(
|
110 |
+
show_edge=False,
|
111 |
+
show_header=True,
|
112 |
+
expand=False,
|
113 |
+
row_styles=["none", "dim"],
|
114 |
+
box=box.SIMPLE,
|
115 |
+
)
|
116 |
+
example_table.add_column("[green]Date", style="green", no_wrap=True)
|
117 |
+
example_table.add_column("[blue]Title", style="blue")
|
118 |
+
example_table.add_column(
|
119 |
+
"[cyan]Production Budget",
|
120 |
+
style="cyan",
|
121 |
+
justify="right",
|
122 |
+
no_wrap=True,
|
123 |
+
)
|
124 |
+
example_table.add_column(
|
125 |
+
"[magenta]Box Office",
|
126 |
+
style="magenta",
|
127 |
+
justify="right",
|
128 |
+
no_wrap=True,
|
129 |
+
)
|
130 |
+
example_table.add_row(
|
131 |
+
"Dec 20, 2019",
|
132 |
+
"Star Wars: The Rise of Skywalker",
|
133 |
+
"$275,000,000",
|
134 |
+
"$375,126,118",
|
135 |
+
)
|
136 |
+
example_table.add_row(
|
137 |
+
"May 25, 2018",
|
138 |
+
"[b]Solo[/]: A Star Wars Story",
|
139 |
+
"$275,000,000",
|
140 |
+
"$393,151,347",
|
141 |
+
)
|
142 |
+
example_table.add_row(
|
143 |
+
"Dec 15, 2017",
|
144 |
+
"Star Wars Ep. VIII: The Last Jedi",
|
145 |
+
"$262,000,000",
|
146 |
+
"[bold]$1,332,539,889[/bold]",
|
147 |
+
)
|
148 |
+
example_table.add_row(
|
149 |
+
"May 19, 1999",
|
150 |
+
"Star Wars Ep. [b]I[/b]: [i]The phantom Menace",
|
151 |
+
"$115,000,000",
|
152 |
+
"$1,027,044,677",
|
153 |
+
)
|
154 |
+
|
155 |
+
table.add_row("Tables", example_table)
|
156 |
+
|
157 |
+
code = '''\
|
158 |
+
def iter_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
|
159 |
+
"""Iterate and generate a tuple with a flag for last value."""
|
160 |
+
iter_values = iter(values)
|
161 |
+
try:
|
162 |
+
previous_value = next(iter_values)
|
163 |
+
except StopIteration:
|
164 |
+
return
|
165 |
+
for value in iter_values:
|
166 |
+
yield False, previous_value
|
167 |
+
previous_value = value
|
168 |
+
yield True, previous_value'''
|
169 |
+
|
170 |
+
pretty_data = {
|
171 |
+
"foo": [
|
172 |
+
3.1427,
|
173 |
+
(
|
174 |
+
"Paul Atreides",
|
175 |
+
"Vladimir Harkonnen",
|
176 |
+
"Thufir Hawat",
|
177 |
+
),
|
178 |
+
],
|
179 |
+
"atomic": (False, True, None),
|
180 |
+
}
|
181 |
+
table.add_row(
|
182 |
+
"Syntax\nhighlighting\n&\npretty\nprinting",
|
183 |
+
comparison(
|
184 |
+
Syntax(code, "python3", line_numbers=True, indent_guides=True),
|
185 |
+
Pretty(pretty_data, indent_guides=True),
|
186 |
+
),
|
187 |
+
)
|
188 |
+
|
189 |
+
markdown_example = """\
|
190 |
+
# Markdown
|
191 |
+
|
192 |
+
Supports much of the *markdown* __syntax__!
|
193 |
+
|
194 |
+
- Headers
|
195 |
+
- Basic formatting: **bold**, *italic*, `code`
|
196 |
+
- Block quotes
|
197 |
+
- Lists, and more...
|
198 |
+
"""
|
199 |
+
table.add_row(
|
200 |
+
"Markdown", comparison("[cyan]" + markdown_example, Markdown(markdown_example))
|
201 |
+
)
|
202 |
+
|
203 |
+
table.add_row(
|
204 |
+
"+more!",
|
205 |
+
"""Progress bars, columns, styled logging handler, tracebacks, etc...""",
|
206 |
+
)
|
207 |
+
return table
|
208 |
+
|
209 |
+
|
210 |
+
if __name__ == "__main__": # pragma: no cover
|
211 |
+
|
212 |
+
console = Console(
|
213 |
+
file=io.StringIO(),
|
214 |
+
force_terminal=True,
|
215 |
+
)
|
216 |
+
test_card = make_test_card()
|
217 |
+
|
218 |
+
# Print once to warm cache
|
219 |
+
start = process_time()
|
220 |
+
console.print(test_card)
|
221 |
+
pre_cache_taken = round((process_time() - start) * 1000.0, 1)
|
222 |
+
|
223 |
+
console.file = io.StringIO()
|
224 |
+
|
225 |
+
start = process_time()
|
226 |
+
console.print(test_card)
|
227 |
+
taken = round((process_time() - start) * 1000.0, 1)
|
228 |
+
|
229 |
+
text = console.file.getvalue()
|
230 |
+
# https://bugs.python.org/issue37871
|
231 |
+
for line in text.splitlines(True):
|
232 |
+
print(line, end="")
|
233 |
+
|
234 |
+
print(f"rendered in {pre_cache_taken}ms (cold cache)")
|
235 |
+
print(f"rendered in {taken}ms (warm cache)")
|
236 |
+
|
237 |
+
from pip._vendor.rich.panel import Panel
|
238 |
+
|
239 |
+
console = Console()
|
240 |
+
|
241 |
+
sponsor_message = Table.grid(padding=1)
|
242 |
+
sponsor_message.add_column(style="green", justify="right")
|
243 |
+
sponsor_message.add_column(no_wrap=True)
|
244 |
+
|
245 |
+
sponsor_message.add_row(
|
246 |
+
"Buy devs a :coffee:",
|
247 |
+
"[u blue link=https://ko-fi.com/textualize]https://ko-fi.com/textualize",
|
248 |
+
)
|
249 |
+
sponsor_message.add_row(
|
250 |
+
"Twitter",
|
251 |
+
"[u blue link=https://twitter.com/willmcgugan]https://twitter.com/willmcgugan",
|
252 |
+
)
|
253 |
+
sponsor_message.add_row(
|
254 |
+
"Blog", "[u blue link=https://www.willmcgugan.com]https://www.willmcgugan.com"
|
255 |
+
)
|
256 |
+
|
257 |
+
intro_message = Text.from_markup(
|
258 |
+
"""\
|
259 |
+
We hope you enjoy using Rich!
|
260 |
+
|
261 |
+
Rich is maintained with :heart: by [link=https://www.textualize.io]Textualize.io[/]
|
262 |
+
|
263 |
+
- Will McGugan"""
|
264 |
+
)
|
265 |
+
|
266 |
+
message = Table.grid(padding=2)
|
267 |
+
message.add_column()
|
268 |
+
message.add_column(no_wrap=True)
|
269 |
+
message.add_row(intro_message, sponsor_message)
|
270 |
+
|
271 |
+
console.print(
|
272 |
+
Panel.fit(
|
273 |
+
message,
|
274 |
+
box=box.ROUNDED,
|
275 |
+
padding=(1, 2),
|
276 |
+
title="[b red]Thanks for trying out Rich!",
|
277 |
+
border_style="bright_blue",
|
278 |
+
),
|
279 |
+
justify="center",
|
280 |
+
)
|
scripts/myenv/lib/python3.10/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 |
+
]
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_emoji_codes.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_lru_cache.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import OrderedDict
|
2 |
+
from typing import Dict, Generic, TypeVar
|
3 |
+
|
4 |
+
|
5 |
+
CacheKey = TypeVar("CacheKey")
|
6 |
+
CacheValue = TypeVar("CacheValue")
|
7 |
+
|
8 |
+
|
9 |
+
class LRUCache(Generic[CacheKey, CacheValue], OrderedDict): # type: ignore # https://github.com/python/mypy/issues/6904
|
10 |
+
"""
|
11 |
+
A dictionary-like container that stores a given maximum items.
|
12 |
+
|
13 |
+
If an additional item is added when the LRUCache is full, the least
|
14 |
+
recently used key is discarded to make room for the new item.
|
15 |
+
|
16 |
+
"""
|
17 |
+
|
18 |
+
def __init__(self, cache_size: int) -> None:
|
19 |
+
self.cache_size = cache_size
|
20 |
+
super(LRUCache, self).__init__()
|
21 |
+
|
22 |
+
def __setitem__(self, key: CacheKey, value: CacheValue) -> None:
|
23 |
+
"""Store a new views, potentially discarding an old value."""
|
24 |
+
if key not in self:
|
25 |
+
if len(self) >= self.cache_size:
|
26 |
+
self.popitem(last=False)
|
27 |
+
OrderedDict.__setitem__(self, key, value)
|
28 |
+
|
29 |
+
def __getitem__(self: Dict[CacheKey, CacheValue], key: CacheKey) -> CacheValue:
|
30 |
+
"""Gets the item, but also makes it most recent."""
|
31 |
+
value: CacheValue = OrderedDict.__getitem__(self, key)
|
32 |
+
OrderedDict.__delitem__(self, key)
|
33 |
+
OrderedDict.__setitem__(self, key, value)
|
34 |
+
return value
|
scripts/myenv/lib/python3.10/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))
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_spinners.py
ADDED
@@ -0,0 +1,848 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Spinners are from:
|
3 |
+
* cli-spinners:
|
4 |
+
MIT License
|
5 |
+
Copyright (c) Sindre Sorhus <[email protected]> (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 |
+
"⠆",
|
37 |
+
"⠇",
|
38 |
+
"⠋",
|
39 |
+
"⠙",
|
40 |
+
"⠸",
|
41 |
+
"⠰",
|
42 |
+
"⠠",
|
43 |
+
"⠰",
|
44 |
+
"⠸",
|
45 |
+
"⠙",
|
46 |
+
"⠋",
|
47 |
+
"⠇",
|
48 |
+
"⠆",
|
49 |
+
],
|
50 |
+
},
|
51 |
+
"dots5": {
|
52 |
+
"interval": 80,
|
53 |
+
"frames": [
|
54 |
+
"⠋",
|
55 |
+
"⠙",
|
56 |
+
"⠚",
|
57 |
+
"⠒",
|
58 |
+
"⠂",
|
59 |
+
"⠂",
|
60 |
+
"⠒",
|
61 |
+
"⠲",
|
62 |
+
"⠴",
|
63 |
+
"⠦",
|
64 |
+
"⠖",
|
65 |
+
"⠒",
|
66 |
+
"⠐",
|
67 |
+
"⠐",
|
68 |
+
"⠒",
|
69 |
+
"⠓",
|
70 |
+
"⠋",
|
71 |
+
],
|
72 |
+
},
|
73 |
+
"dots6": {
|
74 |
+
"interval": 80,
|
75 |
+
"frames": [
|
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 |
+
"dots7": {
|
103 |
+
"interval": 80,
|
104 |
+
"frames": [
|
105 |
+
"⠈",
|
106 |
+
"⠉",
|
107 |
+
"⠋",
|
108 |
+
"⠓",
|
109 |
+
"⠒",
|
110 |
+
"⠐",
|
111 |
+
"⠐",
|
112 |
+
"⠒",
|
113 |
+
"⠖",
|
114 |
+
"⠦",
|
115 |
+
"⠤",
|
116 |
+
"⠠",
|
117 |
+
"⠠",
|
118 |
+
"⠤",
|
119 |
+
"⠦",
|
120 |
+
"⠖",
|
121 |
+
"⠒",
|
122 |
+
"⠐",
|
123 |
+
"⠐",
|
124 |
+
"⠒",
|
125 |
+
"⠓",
|
126 |
+
"⠋",
|
127 |
+
"⠉",
|
128 |
+
"⠈",
|
129 |
+
],
|
130 |
+
},
|
131 |
+
"dots8": {
|
132 |
+
"interval": 80,
|
133 |
+
"frames": [
|
134 |
+
"⠁",
|
135 |
+
"⠁",
|
136 |
+
"⠉",
|
137 |
+
"⠙",
|
138 |
+
"⠚",
|
139 |
+
"⠒",
|
140 |
+
"⠂",
|
141 |
+
"⠂",
|
142 |
+
"⠒",
|
143 |
+
"⠲",
|
144 |
+
"⠴",
|
145 |
+
"⠤",
|
146 |
+
"⠄",
|
147 |
+
"⠄",
|
148 |
+
"⠤",
|
149 |
+
"⠠",
|
150 |
+
"⠠",
|
151 |
+
"⠤",
|
152 |
+
"⠦",
|
153 |
+
"⠖",
|
154 |
+
"⠒",
|
155 |
+
"⠐",
|
156 |
+
"⠐",
|
157 |
+
"⠒",
|
158 |
+
"⠓",
|
159 |
+
"⠋",
|
160 |
+
"⠉",
|
161 |
+
"⠈",
|
162 |
+
"⠈",
|
163 |
+
],
|
164 |
+
},
|
165 |
+
"dots9": {"interval": 80, "frames": ["⢹", "⢺", "⢼", "⣸", "⣇", "⡧", "⡗", "⡏"]},
|
166 |
+
"dots10": {"interval": 80, "frames": ["⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"]},
|
167 |
+
"dots11": {"interval": 100, "frames": ["⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"]},
|
168 |
+
"dots12": {
|
169 |
+
"interval": 80,
|
170 |
+
"frames": [
|
171 |
+
"⢀⠀",
|
172 |
+
"⡀⠀",
|
173 |
+
"⠄⠀",
|
174 |
+
"⢂⠀",
|
175 |
+
"⡂⠀",
|
176 |
+
"⠅⠀",
|
177 |
+
"⢃⠀",
|
178 |
+
"⡃⠀",
|
179 |
+
"⠍⠀",
|
180 |
+
"⢋⠀",
|
181 |
+
"⡋⠀",
|
182 |
+
"⠍⠁",
|
183 |
+
"⢋⠁",
|
184 |
+
"⡋⠁",
|
185 |
+
"⠍⠉",
|
186 |
+
"⠋⠉",
|
187 |
+
"⠋⠉",
|
188 |
+
"⠉⠙",
|
189 |
+
"⠉⠙",
|
190 |
+
"⠉⠩",
|
191 |
+
"⠈⢙",
|
192 |
+
"⠈⡙",
|
193 |
+
"⢈⠩",
|
194 |
+
"⡀⢙",
|
195 |
+
"⠄⡙",
|
196 |
+
"⢂⠩",
|
197 |
+
"⡂⢘",
|
198 |
+
"⠅⡘",
|
199 |
+
"⢃⠨",
|
200 |
+
"⡃⢐",
|
201 |
+
"⠍⡐",
|
202 |
+
"⢋⠠",
|
203 |
+
"⡋⢀",
|
204 |
+
"⠍⡁",
|
205 |
+
"⢋⠁",
|
206 |
+
"⡋⠁",
|
207 |
+
"⠍⠉",
|
208 |
+
"⠋⠉",
|
209 |
+
"⠋⠉",
|
210 |
+
"⠉⠙",
|
211 |
+
"⠉⠙",
|
212 |
+
"⠉⠩",
|
213 |
+
"⠈⢙",
|
214 |
+
"⠈⡙",
|
215 |
+
"⠈⠩",
|
216 |
+
"⠀⢙",
|
217 |
+
"⠀⡙",
|
218 |
+
"⠀⠩",
|
219 |
+
"⠀⢘",
|
220 |
+
"⠀⡘",
|
221 |
+
"⠀⠨",
|
222 |
+
"⠀⢐",
|
223 |
+
"⠀⡐",
|
224 |
+
"⠀⠠",
|
225 |
+
"⠀⢀",
|
226 |
+
"⠀⡀",
|
227 |
+
],
|
228 |
+
},
|
229 |
+
"dots8Bit": {
|
230 |
+
"interval": 80,
|
231 |
+
"frames": [
|
232 |
+
"⠀",
|
233 |
+
"⠁",
|
234 |
+
"⠂",
|
235 |
+
"⠃",
|
236 |
+
"⠄",
|
237 |
+
"⠅",
|
238 |
+
"⠆",
|
239 |
+
"⠇",
|
240 |
+
"⡀",
|
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 |
+
"⠷",
|
336 |
+
"⡰",
|
337 |
+
"⡱",
|
338 |
+
"⡲",
|
339 |
+
"⡳",
|
340 |
+
"⡴",
|
341 |
+
"⡵",
|
342 |
+
"⡶",
|
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 |
+
"⣇",
|
376 |
+
"⢈",
|
377 |
+
"⢉",
|
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 |
+
"⣖",
|
407 |
+
"⣗",
|
408 |
+
"⢘",
|
409 |
+
"⢙",
|
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 |
+
"⣣",
|
436 |
+
"⣤",
|
437 |
+
"⣥",
|
438 |
+
"⣦",
|
439 |
+
"⣧",
|
440 |
+
"⢨",
|
441 |
+
"⢩",
|
442 |
+
"⢪",
|
443 |
+
"⢫",
|
444 |
+
"⢬",
|
445 |
+
"⢭",
|
446 |
+
"⢮",
|
447 |
+
"⢯",
|
448 |
+
"⣨",
|
449 |
+
"⣩",
|
450 |
+
"⣪",
|
451 |
+
"⣫",
|
452 |
+
"⣬",
|
453 |
+
"⣭",
|
454 |
+
"⣮",
|
455 |
+
"⣯",
|
456 |
+
"⢰",
|
457 |
+
"⢱",
|
458 |
+
"⢲",
|
459 |
+
"⢳",
|
460 |
+
"⢴",
|
461 |
+
"⢵",
|
462 |
+
"⢶",
|
463 |
+
"⢷",
|
464 |
+
"⣰",
|
465 |
+
"⣱",
|
466 |
+
"⣲",
|
467 |
+
"⣳",
|
468 |
+
"⣴",
|
469 |
+
"⣵",
|
470 |
+
"⣶",
|
471 |
+
"⣷",
|
472 |
+
"⢸",
|
473 |
+
"⢹",
|
474 |
+
"⢺",
|
475 |
+
"⢻",
|
476 |
+
"⢼",
|
477 |
+
"⢽",
|
478 |
+
"⢾",
|
479 |
+
"⢿",
|
480 |
+
"⣸",
|
481 |
+
"⣹",
|
482 |
+
"⣺",
|
483 |
+
"⣻",
|
484 |
+
"⣼",
|
485 |
+
"⣽",
|
486 |
+
"⣾",
|
487 |
+
"⣿",
|
488 |
+
],
|
489 |
+
},
|
490 |
+
"line": {"interval": 130, "frames": ["-", "\\", "|", "/"]},
|
491 |
+
"line2": {"interval": 100, "frames": ["⠂", "-", "–", "—", "–", "-"]},
|
492 |
+
"pipe": {"interval": 100, "frames": ["┤", "┘", "┴", "└", "├", "┌", "┬", "┐"]},
|
493 |
+
"simpleDots": {"interval": 400, "frames": [". ", ".. ", "...", " "]},
|
494 |
+
"simpleDotsScrolling": {
|
495 |
+
"interval": 200,
|
496 |
+
"frames": [". ", ".. ", "...", " ..", " .", " "],
|
497 |
+
},
|
498 |
+
"star": {"interval": 70, "frames": ["✶", "✸", "✹", "✺", "✹", "✷"]},
|
499 |
+
"star2": {"interval": 80, "frames": ["+", "x", "*"]},
|
500 |
+
"flip": {
|
501 |
+
"interval": 70,
|
502 |
+
"frames": ["_", "_", "_", "-", "`", "`", "'", "´", "-", "_", "_", "_"],
|
503 |
+
},
|
504 |
+
"hamburger": {"interval": 100, "frames": ["☱", "☲", "☴"]},
|
505 |
+
"growVertical": {
|
506 |
+
"interval": 120,
|
507 |
+
"frames": ["▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"],
|
508 |
+
},
|
509 |
+
"growHorizontal": {
|
510 |
+
"interval": 120,
|
511 |
+
"frames": ["▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍", "▎"],
|
512 |
+
},
|
513 |
+
"balloon": {"interval": 140, "frames": [" ", ".", "o", "O", "@", "*", " "]},
|
514 |
+
"balloon2": {"interval": 120, "frames": [".", "o", "O", "°", "O", "o", "."]},
|
515 |
+
"noise": {"interval": 100, "frames": ["▓", "▒", "░"]},
|
516 |
+
"bounce": {"interval": 120, "frames": ["⠁", "⠂", "⠄", "⠂"]},
|
517 |
+
"boxBounce": {"interval": 120, "frames": ["▖", "▘", "▝", "▗"]},
|
518 |
+
"boxBounce2": {"interval": 100, "frames": ["▌", "▀", "▐", "▄"]},
|
519 |
+
"triangle": {"interval": 50, "frames": ["◢", "◣", "◤", "◥"]},
|
520 |
+
"arc": {"interval": 100, "frames": ["◜", "◠", "◝", "◞", "◡", "◟"]},
|
521 |
+
"circle": {"interval": 120, "frames": ["◡", "⊙", "◠"]},
|
522 |
+
"squareCorners": {"interval": 180, "frames": ["◰", "◳", "◲", "◱"]},
|
523 |
+
"circleQuarters": {"interval": 120, "frames": ["◴", "◷", "◶", "◵"]},
|
524 |
+
"circleHalves": {"interval": 50, "frames": ["◐", "◓", "◑", "◒"]},
|
525 |
+
"squish": {"interval": 100, "frames": ["╫", "╪"]},
|
526 |
+
"toggle": {"interval": 250, "frames": ["⊶", "⊷"]},
|
527 |
+
"toggle2": {"interval": 80, "frames": ["▫", "▪"]},
|
528 |
+
"toggle3": {"interval": 120, "frames": ["□", "■"]},
|
529 |
+
"toggle4": {"interval": 100, "frames": ["■", "□", "▪", "▫"]},
|
530 |
+
"toggle5": {"interval": 100, "frames": ["▮", "▯"]},
|
531 |
+
"toggle6": {"interval": 300, "frames": ["ဝ", "၀"]},
|
532 |
+
"toggle7": {"interval": 80, "frames": ["⦾", "⦿"]},
|
533 |
+
"toggle8": {"interval": 100, "frames": ["◍", "◌"]},
|
534 |
+
"toggle9": {"interval": 100, "frames": ["◉", "◎"]},
|
535 |
+
"toggle10": {"interval": 100, "frames": ["㊂", "㊀", "㊁"]},
|
536 |
+
"toggle11": {"interval": 50, "frames": ["⧇", "⧆"]},
|
537 |
+
"toggle12": {"interval": 120, "frames": ["☗", "☖"]},
|
538 |
+
"toggle13": {"interval": 80, "frames": ["=", "*", "-"]},
|
539 |
+
"arrow": {"interval": 100, "frames": ["←", "↖", "↑", "↗", "→", "↘", "↓", "↙"]},
|
540 |
+
"arrow2": {
|
541 |
+
"interval": 80,
|
542 |
+
"frames": ["⬆️ ", "↗️ ", "➡️ ", "↘️ ", "⬇️ ", "↙️ ", "⬅️ ", "↖️ "],
|
543 |
+
},
|
544 |
+
"arrow3": {
|
545 |
+
"interval": 120,
|
546 |
+
"frames": ["▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"],
|
547 |
+
},
|
548 |
+
"bouncingBar": {
|
549 |
+
"interval": 80,
|
550 |
+
"frames": [
|
551 |
+
"[ ]",
|
552 |
+
"[= ]",
|
553 |
+
"[== ]",
|
554 |
+
"[=== ]",
|
555 |
+
"[ ===]",
|
556 |
+
"[ ==]",
|
557 |
+
"[ =]",
|
558 |
+
"[ ]",
|
559 |
+
"[ =]",
|
560 |
+
"[ ==]",
|
561 |
+
"[ ===]",
|
562 |
+
"[====]",
|
563 |
+
"[=== ]",
|
564 |
+
"[== ]",
|
565 |
+
"[= ]",
|
566 |
+
],
|
567 |
+
},
|
568 |
+
"bouncingBall": {
|
569 |
+
"interval": 80,
|
570 |
+
"frames": [
|
571 |
+
"( ● )",
|
572 |
+
"( ● )",
|
573 |
+
"( ● )",
|
574 |
+
"( ● )",
|
575 |
+
"( ●)",
|
576 |
+
"( ● )",
|
577 |
+
"( ● )",
|
578 |
+
"( ● )",
|
579 |
+
"( ● )",
|
580 |
+
"(● )",
|
581 |
+
],
|
582 |
+
},
|
583 |
+
"smiley": {"interval": 200, "frames": ["😄 ", "😝 "]},
|
584 |
+
"monkey": {"interval": 300, "frames": ["🙈 ", "🙈 ", "🙉 ", "🙊 "]},
|
585 |
+
"hearts": {"interval": 100, "frames": ["💛 ", "💙 ", "💜 ", "💚 ", "❤️ "]},
|
586 |
+
"clock": {
|
587 |
+
"interval": 100,
|
588 |
+
"frames": [
|
589 |
+
"🕛 ",
|
590 |
+
"🕐 ",
|
591 |
+
"🕑 ",
|
592 |
+
"🕒 ",
|
593 |
+
"🕓 ",
|
594 |
+
"🕔 ",
|
595 |
+
"🕕 ",
|
596 |
+
"🕖 ",
|
597 |
+
"🕗 ",
|
598 |
+
"🕘 ",
|
599 |
+
"🕙 ",
|
600 |
+
"🕚 ",
|
601 |
+
],
|
602 |
+
},
|
603 |
+
"earth": {"interval": 180, "frames": ["🌍 ", "🌎 ", "🌏 "]},
|
604 |
+
"material": {
|
605 |
+
"interval": 17,
|
606 |
+
"frames": [
|
607 |
+
"█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
608 |
+
"██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
609 |
+
"███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
610 |
+
"████▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
611 |
+
"██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
612 |
+
"██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
613 |
+
"███████▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
614 |
+
"████████▁▁▁▁▁▁▁▁▁▁▁▁",
|
615 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
616 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
617 |
+
"██████████▁▁▁▁▁▁▁▁▁▁",
|
618 |
+
"███████████▁▁▁▁▁▁▁▁▁",
|
619 |
+
"█████████████▁▁▁▁▁▁▁",
|
620 |
+
"██████████████▁▁▁▁▁▁",
|
621 |
+
"██████████████▁▁▁▁▁▁",
|
622 |
+
"▁██████████████▁▁▁▁▁",
|
623 |
+
"▁██████████████▁▁▁▁▁",
|
624 |
+
"▁██████████████▁▁▁▁▁",
|
625 |
+
"▁▁██████████████▁▁▁▁",
|
626 |
+
"▁▁▁██████████████▁▁▁",
|
627 |
+
"▁▁▁▁█████████████▁▁▁",
|
628 |
+
"▁▁▁▁██████████████▁▁",
|
629 |
+
"▁▁▁▁██████████████▁▁",
|
630 |
+
"▁▁▁▁▁██████████████▁",
|
631 |
+
"▁▁▁▁▁██████████████▁",
|
632 |
+
"▁▁▁▁▁██████████████▁",
|
633 |
+
"▁▁▁▁▁▁██████████████",
|
634 |
+
"▁▁▁▁▁▁██████████████",
|
635 |
+
"▁▁▁▁▁▁▁█████████████",
|
636 |
+
"▁▁▁▁▁▁▁█████████████",
|
637 |
+
"▁▁▁▁▁▁▁▁████████████",
|
638 |
+
"▁▁▁▁▁▁▁▁████████████",
|
639 |
+
"▁▁▁▁▁▁▁▁▁███████████",
|
640 |
+
"▁▁▁▁▁▁▁▁▁███████████",
|
641 |
+
"▁▁▁▁▁▁▁▁▁▁██████████",
|
642 |
+
"▁▁▁▁▁▁▁▁▁▁██████████",
|
643 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁████████",
|
644 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
|
645 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁██████",
|
646 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
|
647 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
|
648 |
+
"█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
649 |
+
"██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
650 |
+
"██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
651 |
+
"███▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
652 |
+
"████▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
653 |
+
"█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
654 |
+
"█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
655 |
+
"██████▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
656 |
+
"████████▁▁▁▁▁▁▁▁▁▁▁▁",
|
657 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
658 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
659 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
660 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
661 |
+
"███████████▁▁▁▁▁▁▁▁▁",
|
662 |
+
"████████████▁▁▁▁▁▁▁▁",
|
663 |
+
"████████████▁▁▁▁▁▁▁▁",
|
664 |
+
"██████████████▁▁▁▁▁▁",
|
665 |
+
"██████████████▁▁▁▁▁▁",
|
666 |
+
"▁██████████████▁▁▁▁▁",
|
667 |
+
"▁██████████████▁▁▁▁▁",
|
668 |
+
"▁▁▁█████████████▁▁▁▁",
|
669 |
+
"▁▁▁▁▁████████████▁▁▁",
|
670 |
+
"▁▁▁▁▁████████████▁▁▁",
|
671 |
+
"▁▁▁▁▁▁███████████▁▁▁",
|
672 |
+
"▁▁▁▁▁▁▁▁█████████▁▁▁",
|
673 |
+
"▁▁▁▁▁▁▁▁█████████▁▁▁",
|
674 |
+
"▁▁▁▁▁▁▁▁▁█████████▁▁",
|
675 |
+
"▁▁▁▁▁▁▁▁▁█████████▁▁",
|
676 |
+
"▁▁▁▁▁▁▁▁▁▁█████████▁",
|
677 |
+
"▁▁▁▁▁▁▁▁▁▁▁████████▁",
|
678 |
+
"▁▁▁▁▁▁▁▁▁▁▁████████▁",
|
679 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁███████▁",
|
680 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁███████▁",
|
681 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
|
682 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
|
683 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
|
684 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
685 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
686 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
687 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
688 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
689 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
690 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
691 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
692 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
693 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
694 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
695 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
696 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
697 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
698 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
699 |
+
],
|
700 |
+
},
|
701 |
+
"moon": {
|
702 |
+
"interval": 80,
|
703 |
+
"frames": ["🌑 ", "🌒 ", "🌓 ", "🌔 ", "🌕 ", "🌖 ", "🌗 ", "🌘 "],
|
704 |
+
},
|
705 |
+
"runner": {"interval": 140, "frames": ["🚶 ", "🏃 "]},
|
706 |
+
"pong": {
|
707 |
+
"interval": 80,
|
708 |
+
"frames": [
|
709 |
+
"▐⠂ ▌",
|
710 |
+
"▐⠈ ▌",
|
711 |
+
"▐ ⠂ ▌",
|
712 |
+
"▐ ⠠ ▌",
|
713 |
+
"▐ ⡀ ▌",
|
714 |
+
"▐ ⠠ ▌",
|
715 |
+
"▐ ⠂ ▌",
|
716 |
+
"▐ ⠈ ▌",
|
717 |
+
"▐ ⠂ ▌",
|
718 |
+
"▐ ⠠ ▌",
|
719 |
+
"▐ ⡀ ▌",
|
720 |
+
"▐ ⠠ ▌",
|
721 |
+
"▐ ⠂ ▌",
|
722 |
+
"▐ ⠈ ▌",
|
723 |
+
"▐ ⠂▌",
|
724 |
+
"▐ ⠠▌",
|
725 |
+
"▐ ⡀▌",
|
726 |
+
"▐ ⠠ ▌",
|
727 |
+
"▐ ⠂ ▌",
|
728 |
+
"▐ ⠈ ▌",
|
729 |
+
"▐ ⠂ ▌",
|
730 |
+
"▐ ⠠ ▌",
|
731 |
+
"▐ ⡀ ▌",
|
732 |
+
"▐ ⠠ ▌",
|
733 |
+
"▐ ⠂ ▌",
|
734 |
+
"▐ ⠈ ▌",
|
735 |
+
"▐ ⠂ ▌",
|
736 |
+
"▐ ⠠ ▌",
|
737 |
+
"▐ ⡀ ▌",
|
738 |
+
"▐⠠ ▌",
|
739 |
+
],
|
740 |
+
},
|
741 |
+
"shark": {
|
742 |
+
"interval": 120,
|
743 |
+
"frames": [
|
744 |
+
"▐|\\____________▌",
|
745 |
+
"▐_|\\___________▌",
|
746 |
+
"▐__|\\__________▌",
|
747 |
+
"▐___|\\_________▌",
|
748 |
+
"▐____|\\________▌",
|
749 |
+
"▐_____|\\_______▌",
|
750 |
+
"▐______|\\______▌",
|
751 |
+
"▐_______|\\_____▌",
|
752 |
+
"▐________|\\____▌",
|
753 |
+
"▐_________|\\___▌",
|
754 |
+
"▐__________|\\__▌",
|
755 |
+
"▐___________|\\_▌",
|
756 |
+
"▐____________|\\▌",
|
757 |
+
"▐____________/|▌",
|
758 |
+
"▐___________/|_▌",
|
759 |
+
"▐__________/|__▌",
|
760 |
+
"▐_________/|___▌",
|
761 |
+
"▐________/|____▌",
|
762 |
+
"▐_______/|_____▌",
|
763 |
+
"▐______/|______▌",
|
764 |
+
"▐_____/|_______▌",
|
765 |
+
"▐____/|________▌",
|
766 |
+
"▐___/|_________▌",
|
767 |
+
"▐__/|__________▌",
|
768 |
+
"▐_/|___________▌",
|
769 |
+
"▐/|____________▌",
|
770 |
+
],
|
771 |
+
},
|
772 |
+
"dqpb": {"interval": 100, "frames": ["d", "q", "p", "b"]},
|
773 |
+
"weather": {
|
774 |
+
"interval": 100,
|
775 |
+
"frames": [
|
776 |
+
"☀️ ",
|
777 |
+
"☀️ ",
|
778 |
+
"☀️ ",
|
779 |
+
"🌤 ",
|
780 |
+
"⛅️ ",
|
781 |
+
"🌥 ",
|
782 |
+
"☁️ ",
|
783 |
+
"🌧 ",
|
784 |
+
"🌨 ",
|
785 |
+
"🌧 ",
|
786 |
+
"🌨 ",
|
787 |
+
"🌧 ",
|
788 |
+
"🌨 ",
|
789 |
+
"⛈ ",
|
790 |
+
"🌨 ",
|
791 |
+
"🌧 ",
|
792 |
+
"🌨 ",
|
793 |
+
"☁️ ",
|
794 |
+
"🌥 ",
|
795 |
+
"⛅️ ",
|
796 |
+
"🌤 ",
|
797 |
+
"☀️ ",
|
798 |
+
"☀️ ",
|
799 |
+
],
|
800 |
+
},
|
801 |
+
"christmas": {"interval": 400, "frames": ["🌲", "🎄"]},
|
802 |
+
"grenade": {
|
803 |
+
"interval": 80,
|
804 |
+
"frames": [
|
805 |
+
"، ",
|
806 |
+
"′ ",
|
807 |
+
" ´ ",
|
808 |
+
" ‾ ",
|
809 |
+
" ⸌",
|
810 |
+
" ⸊",
|
811 |
+
" |",
|
812 |
+
" ⁎",
|
813 |
+
" ⁕",
|
814 |
+
" ෴ ",
|
815 |
+
" ⁓",
|
816 |
+
" ",
|
817 |
+
" ",
|
818 |
+
" ",
|
819 |
+
],
|
820 |
+
},
|
821 |
+
"point": {"interval": 125, "frames": ["∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"]},
|
822 |
+
"layer": {"interval": 150, "frames": ["-", "=", "≡"]},
|
823 |
+
"betaWave": {
|
824 |
+
"interval": 80,
|
825 |
+
"frames": [
|
826 |
+
"ρββββββ",
|
827 |
+
"βρβββββ",
|
828 |
+
"ββρββββ",
|
829 |
+
"βββρβββ",
|
830 |
+
"ββββρββ",
|
831 |
+
"βββββρβ",
|
832 |
+
"ββββββρ",
|
833 |
+
],
|
834 |
+
},
|
835 |
+
"aesthetic": {
|
836 |
+
"interval": 80,
|
837 |
+
"frames": [
|
838 |
+
"▰▱▱▱▱▱▱",
|
839 |
+
"▰▰▱▱▱▱▱",
|
840 |
+
"▰▰▰▱▱▱▱",
|
841 |
+
"▰▰▰▰▱▱▱",
|
842 |
+
"▰▰▰▰▰▱▱",
|
843 |
+
"▰▰▰▰▰▰▱",
|
844 |
+
"▰▰▰▰▰▰▰",
|
845 |
+
"▰▱▱▱▱▱▱",
|
846 |
+
],
|
847 |
+
},
|
848 |
+
}
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_windows.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
from dataclasses import dataclass
|
3 |
+
|
4 |
+
|
5 |
+
@dataclass
|
6 |
+
class WindowsConsoleFeatures:
|
7 |
+
"""Windows features available."""
|
8 |
+
|
9 |
+
vt: bool = False
|
10 |
+
"""The console supports VT codes."""
|
11 |
+
truecolor: bool = False
|
12 |
+
"""The console supports truecolor."""
|
13 |
+
|
14 |
+
|
15 |
+
try:
|
16 |
+
import ctypes
|
17 |
+
from ctypes import LibraryLoader, wintypes
|
18 |
+
|
19 |
+
if sys.platform == "win32":
|
20 |
+
windll = LibraryLoader(ctypes.WinDLL)
|
21 |
+
else:
|
22 |
+
windll = None
|
23 |
+
raise ImportError("Not windows")
|
24 |
+
except (AttributeError, ImportError, ValueError):
|
25 |
+
|
26 |
+
# Fallback if we can't load the Windows DLL
|
27 |
+
def get_windows_console_features() -> WindowsConsoleFeatures:
|
28 |
+
features = WindowsConsoleFeatures()
|
29 |
+
return features
|
30 |
+
|
31 |
+
else:
|
32 |
+
|
33 |
+
STDOUT = -11
|
34 |
+
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
|
35 |
+
_GetConsoleMode = windll.kernel32.GetConsoleMode
|
36 |
+
_GetConsoleMode.argtypes = [wintypes.HANDLE, wintypes.LPDWORD]
|
37 |
+
_GetConsoleMode.restype = wintypes.BOOL
|
38 |
+
|
39 |
+
_GetStdHandle = windll.kernel32.GetStdHandle
|
40 |
+
_GetStdHandle.argtypes = [
|
41 |
+
wintypes.DWORD,
|
42 |
+
]
|
43 |
+
_GetStdHandle.restype = wintypes.HANDLE
|
44 |
+
|
45 |
+
def get_windows_console_features() -> WindowsConsoleFeatures:
|
46 |
+
"""Get windows console features.
|
47 |
+
|
48 |
+
Returns:
|
49 |
+
WindowsConsoleFeatures: An instance of WindowsConsoleFeatures.
|
50 |
+
"""
|
51 |
+
handle = _GetStdHandle(STDOUT)
|
52 |
+
console_mode = wintypes.DWORD()
|
53 |
+
result = _GetConsoleMode(handle, console_mode)
|
54 |
+
vt = bool(result and console_mode.value & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
55 |
+
truecolor = False
|
56 |
+
if vt:
|
57 |
+
win_version = sys.getwindowsversion()
|
58 |
+
truecolor = win_version.major > 10 or (
|
59 |
+
win_version.major == 10 and win_version.build >= 15063
|
60 |
+
)
|
61 |
+
features = WindowsConsoleFeatures(vt=vt, truecolor=truecolor)
|
62 |
+
return features
|
63 |
+
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
import platform
|
67 |
+
|
68 |
+
features = get_windows_console_features()
|
69 |
+
from pip._vendor.rich import print
|
70 |
+
|
71 |
+
print(f'platform="{platform.system()}"')
|
72 |
+
print(repr(features))
|
scripts/myenv/lib/python3.10/site-packages/pip/_vendor/rich/_wrap.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
from typing import Iterable, List, Tuple
|
3 |
+
|
4 |
+
from .cells import cell_len, chop_cells
|
5 |
+
from ._loop import loop_last
|
6 |
+
|
7 |
+
re_word = re.compile(r"\s*\S+\s*")
|
8 |
+
|
9 |
+
|
10 |
+
def words(text: str) -> Iterable[Tuple[int, int, str]]:
|
11 |
+
position = 0
|
12 |
+
word_match = re_word.match(text, position)
|
13 |
+
while word_match is not None:
|
14 |
+
start, end = word_match.span()
|
15 |
+
word = word_match.group(0)
|
16 |
+
yield start, end, word
|
17 |
+
word_match = re_word.match(text, end)
|
18 |
+
|
19 |
+
|
20 |
+
def divide_line(text: str, width: int, fold: bool = True) -> List[int]:
|
21 |
+
divides: List[int] = []
|
22 |
+
append = divides.append
|
23 |
+
line_position = 0
|
24 |
+
_cell_len = cell_len
|
25 |
+
for start, _end, word in words(text):
|
26 |
+
word_length = _cell_len(word.rstrip())
|
27 |
+
if line_position + word_length > width:
|
28 |
+
if word_length > width:
|
29 |
+
if fold:
|
30 |
+
for last, line in loop_last(
|
31 |
+
chop_cells(word, width, position=line_position)
|
32 |
+
):
|
33 |
+
if last:
|
34 |
+
line_position = _cell_len(line)
|
35 |
+
else:
|
36 |
+
start += len(line)
|
37 |
+
append(start)
|
38 |
+
else:
|
39 |
+
if start:
|
40 |
+
append(start)
|
41 |
+
line_position = _cell_len(word)
|
42 |
+
elif line_position and start:
|
43 |
+
append(start)
|
44 |
+
line_position = _cell_len(word)
|
45 |
+
else:
|
46 |
+
line_position += _cell_len(word)
|
47 |
+
return divides
|
48 |
+
|
49 |
+
|
50 |
+
if __name__ == "__main__": # pragma: no cover
|
51 |
+
from .console import Console
|
52 |
+
|
53 |
+
console = Console(width=10)
|
54 |
+
console.print("12345 abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ 12345")
|
55 |
+
print(chop_cells("abcdefghijklmnopqrstuvwxyz", 10, position=2))
|
scripts/myenv/lib/python3.10/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))
|