update
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
.. _Pygments master branch:
|
||||
https://github.com/pygments/pygments/archive/master.zip#egg=Pygments-dev
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from io import StringIO, BytesIO
|
||||
|
||||
__version__ = '2.15.1'
|
||||
__version__ = '2.18.0'
|
||||
__docformat__ = 'restructuredtext'
|
||||
|
||||
__all__ = ['lex', 'format', 'highlight']
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Main entry point for ``python -m pygments``.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
|
||||
Command line interface.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -68,19 +68,19 @@ def _print_help(what, name):
|
||||
try:
|
||||
if what == 'lexer':
|
||||
cls = get_lexer_by_name(name)
|
||||
print("Help on the %s lexer:" % cls.name)
|
||||
print(f"Help on the {cls.name} lexer:")
|
||||
print(dedent(cls.__doc__))
|
||||
elif what == 'formatter':
|
||||
cls = find_formatter_class(name)
|
||||
print("Help on the %s formatter:" % cls.name)
|
||||
print(f"Help on the {cls.name} formatter:")
|
||||
print(dedent(cls.__doc__))
|
||||
elif what == 'filter':
|
||||
cls = find_filter_class(name)
|
||||
print("Help on the %s filter:" % name)
|
||||
print(f"Help on the {name} filter:")
|
||||
print(dedent(cls.__doc__))
|
||||
return 0
|
||||
except (AttributeError, ValueError):
|
||||
print("%s not found!" % what, file=sys.stderr)
|
||||
print(f"{what} not found!", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ def _print_list(what):
|
||||
info.append(tup)
|
||||
info.sort()
|
||||
for i in info:
|
||||
print(('* %s\n %s %s') % i)
|
||||
print(('* {}\n {} {}').format(*i))
|
||||
|
||||
elif what == 'formatter':
|
||||
print()
|
||||
@@ -112,7 +112,7 @@ def _print_list(what):
|
||||
info.append(tup)
|
||||
info.sort()
|
||||
for i in info:
|
||||
print(('* %s\n %s %s') % i)
|
||||
print(('* {}\n {} {}').format(*i))
|
||||
|
||||
elif what == 'filter':
|
||||
print()
|
||||
@@ -122,7 +122,7 @@ def _print_list(what):
|
||||
for name in get_all_filters():
|
||||
cls = find_filter_class(name)
|
||||
print("* " + name + ':')
|
||||
print(" %s" % docstring_headline(cls))
|
||||
print(f" {docstring_headline(cls)}")
|
||||
|
||||
elif what == 'style':
|
||||
print()
|
||||
@@ -132,7 +132,7 @@ def _print_list(what):
|
||||
for name in get_all_styles():
|
||||
cls = get_style_by_name(name)
|
||||
print("* " + name + ':')
|
||||
print(" %s" % docstring_headline(cls))
|
||||
print(f" {docstring_headline(cls)}")
|
||||
|
||||
|
||||
def _print_list_as_json(requested_items):
|
||||
@@ -185,8 +185,8 @@ def main_inner(parser, argns):
|
||||
return 0
|
||||
|
||||
if argns.V:
|
||||
print('Pygments version %s, (c) 2006-2023 by Georg Brandl, Matthäus '
|
||||
'Chajdas and contributors.' % __version__)
|
||||
print(f'Pygments version {__version__}, (c) 2006-2024 by Georg Brandl, Matthäus '
|
||||
'Chajdas and contributors.')
|
||||
return 0
|
||||
|
||||
def is_only_option(opt):
|
||||
@@ -469,11 +469,11 @@ def main_inner(parser, argns):
|
||||
outfile = UnclosingTextIOWrapper(outfile, encoding=fmter.encoding)
|
||||
fmter.encoding = None
|
||||
try:
|
||||
import pip._vendor.colorama.initialise as colorama_initialise
|
||||
import colorama.initialise
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
outfile = colorama_initialise.wrap_stream(
|
||||
outfile = colorama.initialise.wrap_stream(
|
||||
outfile, convert=None, strip=None, autoreset=False, wrap=True)
|
||||
|
||||
# When using the LaTeX formatter and the option `escapeinside` is
|
||||
@@ -659,7 +659,7 @@ def main(args=sys.argv):
|
||||
msg = info[-1].strip()
|
||||
if len(info) >= 3:
|
||||
# extract relevant file and position info
|
||||
msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
|
||||
msg += '\n (f{})'.format(info[-2].split('\n')[0].strip()[1:])
|
||||
print(file=sys.stderr)
|
||||
print('*** Error while highlighting:', file=sys.stderr)
|
||||
print(msg, file=sys.stderr)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Format colored console output.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -27,12 +27,12 @@ light_colors = ["brightblack", "brightred", "brightgreen", "brightyellow", "brig
|
||||
"brightmagenta", "brightcyan", "white"]
|
||||
|
||||
x = 30
|
||||
for d, l in zip(dark_colors, light_colors):
|
||||
codes[d] = esc + "%im" % x
|
||||
codes[l] = esc + "%im" % (60 + x)
|
||||
for dark, light in zip(dark_colors, light_colors):
|
||||
codes[dark] = esc + "%im" % x
|
||||
codes[light] = esc + "%im" % (60 + x)
|
||||
x += 1
|
||||
|
||||
del d, l, x
|
||||
del dark, light, x
|
||||
|
||||
codes["white"] = codes["bold"]
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Module that implements the default filter.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -62,8 +62,7 @@ class FunctionFilter(Filter):
|
||||
|
||||
def __init__(self, **options):
|
||||
if not hasattr(self, 'function'):
|
||||
raise TypeError('%r used without bound function' %
|
||||
self.__class__.__name__)
|
||||
raise TypeError(f'{self.__class__.__name__!r} used without bound function')
|
||||
Filter.__init__(self, **options)
|
||||
|
||||
def filter(self, lexer, stream):
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Module containing filter lookup functions and default
|
||||
filters.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -39,7 +39,7 @@ def get_filter_by_name(filtername, **options):
|
||||
if cls:
|
||||
return cls(**options)
|
||||
else:
|
||||
raise ClassNotFound('filter %r not found' % filtername)
|
||||
raise ClassNotFound(f'filter {filtername!r} not found')
|
||||
|
||||
|
||||
def get_all_filters():
|
||||
@@ -79,9 +79,9 @@ class CodeTagFilter(Filter):
|
||||
Filter.__init__(self, **options)
|
||||
tags = get_list_opt(options, 'codetags',
|
||||
['XXX', 'TODO', 'FIXME', 'BUG', 'NOTE'])
|
||||
self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([
|
||||
self.tag_re = re.compile(r'\b({})\b'.format('|'.join([
|
||||
re.escape(tag) for tag in tags if tag
|
||||
]))
|
||||
])))
|
||||
|
||||
def filter(self, lexer, stream):
|
||||
regex = self.tag_re
|
||||
|
||||
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
|
||||
Base formatter class.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -122,3 +122,8 @@ class Formatter:
|
||||
# wrap the outfile in a StreamWriter
|
||||
outfile = codecs.lookup(self.encoding)[3](outfile)
|
||||
return self.format_unencoded(tokensource, outfile)
|
||||
|
||||
# Allow writing Formatter[str] or Formatter[bytes]. That's equivalent to
|
||||
# Formatter. This helps when using third-party type stubs from typeshed.
|
||||
def __class_getitem__(cls, name):
|
||||
return cls
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Pygments formatters.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -77,7 +77,7 @@ def get_formatter_by_name(_alias, **options):
|
||||
"""
|
||||
cls = find_formatter_class(_alias)
|
||||
if cls is None:
|
||||
raise ClassNotFound("no formatter found for name %r" % _alias)
|
||||
raise ClassNotFound(f"no formatter found for name {_alias!r}")
|
||||
return cls(**options)
|
||||
|
||||
|
||||
@@ -103,17 +103,16 @@ def load_formatter_from_file(filename, formattername="CustomFormatter", **option
|
||||
exec(f.read(), custom_namespace)
|
||||
# Retrieve the class `formattername` from that namespace
|
||||
if formattername not in custom_namespace:
|
||||
raise ClassNotFound('no valid %s class found in %s' %
|
||||
(formattername, filename))
|
||||
raise ClassNotFound(f'no valid {formattername} class found in {filename}')
|
||||
formatter_class = custom_namespace[formattername]
|
||||
# And finally instantiate it with the options
|
||||
return formatter_class(**options)
|
||||
except OSError as err:
|
||||
raise ClassNotFound('cannot read %s: %s' % (filename, err))
|
||||
raise ClassNotFound(f'cannot read {filename}: {err}')
|
||||
except ClassNotFound:
|
||||
raise
|
||||
except Exception as err:
|
||||
raise ClassNotFound('error when loading custom formatter: %s' % err)
|
||||
raise ClassNotFound(f'error when loading custom formatter: {err}')
|
||||
|
||||
|
||||
def get_formatter_for_filename(fn, **options):
|
||||
@@ -131,11 +130,11 @@ def get_formatter_for_filename(fn, **options):
|
||||
if name not in _formatter_cache:
|
||||
_load_formatters(modname)
|
||||
return _formatter_cache[name](**options)
|
||||
for cls in find_plugin_formatters():
|
||||
for _name, cls in find_plugin_formatters():
|
||||
for filename in cls.filenames:
|
||||
if _fn_matches(fn, filename):
|
||||
return cls(**options)
|
||||
raise ClassNotFound("no formatter found for file name %r" % fn)
|
||||
raise ClassNotFound(f"no formatter found for file name {fn!r}")
|
||||
|
||||
|
||||
class _automodule(types.ModuleType):
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
|
||||
BBcode formatter.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -60,7 +60,7 @@ class BBCodeFormatter(Formatter):
|
||||
for ttype, ndef in self.style:
|
||||
start = end = ''
|
||||
if ndef['color']:
|
||||
start += '[color=#%s]' % ndef['color']
|
||||
start += '[color=#{}]'.format(ndef['color'])
|
||||
end = '[/color]' + end
|
||||
if ndef['bold']:
|
||||
start += '[b]'
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Formatter for groff output.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -63,7 +63,7 @@ class GroffFormatter(Formatter):
|
||||
for ttype, ndef in self.style:
|
||||
start = end = ''
|
||||
if ndef['color']:
|
||||
start += '\\m[%s]' % ndef['color']
|
||||
start += '\\m[{}]'.format(ndef['color'])
|
||||
end = '\\m[]' + end
|
||||
if ndef['bold']:
|
||||
start += bold
|
||||
@@ -72,7 +72,7 @@ class GroffFormatter(Formatter):
|
||||
start += italic
|
||||
end = regular + end
|
||||
if ndef['bgcolor']:
|
||||
start += '\\M[%s]' % ndef['bgcolor']
|
||||
start += '\\M[{}]'.format(ndef['bgcolor'])
|
||||
end = '\\M[]' + end
|
||||
|
||||
self.styles[ttype] = start, end
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Formatter for HTML output.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -62,7 +62,7 @@ def _get_ttype_class(ttype):
|
||||
CSSFILE_TEMPLATE = '''\
|
||||
/*
|
||||
generated by Pygments <https://pygments.org/>
|
||||
Copyright 2006-2023 by the Pygments team.
|
||||
Copyright 2006-2024 by the Pygments team.
|
||||
Licensed under the BSD license, see LICENSE for details.
|
||||
*/
|
||||
%(styledefs)s
|
||||
@@ -73,7 +73,7 @@ DOC_HEADER = '''\
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<!--
|
||||
generated by Pygments <https://pygments.org/>
|
||||
Copyright 2006-2023 by the Pygments team.
|
||||
Copyright 2006-2024 by the Pygments team.
|
||||
Licensed under the BSD license, see LICENSE for details.
|
||||
-->
|
||||
<html>
|
||||
@@ -323,6 +323,7 @@ class HtmlFormatter(Formatter):
|
||||
If set to the path of a ctags file, wrap names in anchor tags that
|
||||
link to their definitions. `lineanchors` should be used, and the
|
||||
tags file should specify line numbers (see the `-n` option to ctags).
|
||||
The tags file is assumed to be encoded in UTF-8.
|
||||
|
||||
.. versionadded:: 1.6
|
||||
|
||||
@@ -487,7 +488,7 @@ class HtmlFormatter(Formatter):
|
||||
name = self._get_css_class(ttype)
|
||||
style = ''
|
||||
if ndef['color']:
|
||||
style += 'color: %s; ' % webify(ndef['color'])
|
||||
style += 'color: {}; '.format(webify(ndef['color']))
|
||||
if ndef['bold']:
|
||||
style += 'font-weight: bold; '
|
||||
if ndef['italic']:
|
||||
@@ -495,9 +496,9 @@ class HtmlFormatter(Formatter):
|
||||
if ndef['underline']:
|
||||
style += 'text-decoration: underline; '
|
||||
if ndef['bgcolor']:
|
||||
style += 'background-color: %s; ' % webify(ndef['bgcolor'])
|
||||
style += 'background-color: {}; '.format(webify(ndef['bgcolor']))
|
||||
if ndef['border']:
|
||||
style += 'border: 1px solid %s; ' % webify(ndef['border'])
|
||||
style += 'border: 1px solid {}; '.format(webify(ndef['border']))
|
||||
if style:
|
||||
t2c[ttype] = name
|
||||
# save len(ttype) to enable ordering the styles by
|
||||
@@ -529,7 +530,7 @@ class HtmlFormatter(Formatter):
|
||||
styles.sort()
|
||||
|
||||
lines = [
|
||||
'%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
|
||||
f'{prefix(cls)} {{ {style} }} /* {repr(ttype)[6:]} */'
|
||||
for (level, ttype, cls, style) in styles
|
||||
]
|
||||
|
||||
@@ -547,24 +548,24 @@ class HtmlFormatter(Formatter):
|
||||
if Text in self.ttype2class:
|
||||
text_style = ' ' + self.class2style[self.ttype2class[Text]][0]
|
||||
lines.insert(
|
||||
0, '%s{ background: %s;%s }' % (
|
||||
0, '{}{{ background: {};{} }}'.format(
|
||||
prefix(''), bg_color, text_style
|
||||
)
|
||||
)
|
||||
if hl_color is not None:
|
||||
lines.insert(
|
||||
0, '%s { background-color: %s }' % (prefix('hll'), hl_color)
|
||||
0, '{} {{ background-color: {} }}'.format(prefix('hll'), hl_color)
|
||||
)
|
||||
|
||||
return lines
|
||||
|
||||
def get_linenos_style_defs(self):
|
||||
lines = [
|
||||
'pre { %s }' % self._pre_style,
|
||||
'td.linenos .normal { %s }' % self._linenos_style,
|
||||
'span.linenos { %s }' % self._linenos_style,
|
||||
'td.linenos .special { %s }' % self._linenos_special_style,
|
||||
'span.linenos.special { %s }' % self._linenos_special_style,
|
||||
f'pre {{ {self._pre_style} }}',
|
||||
f'td.linenos .normal {{ {self._linenos_style} }}',
|
||||
f'span.linenos {{ {self._linenos_style} }}',
|
||||
f'td.linenos .special {{ {self._linenos_special_style} }}',
|
||||
f'span.linenos.special {{ {self._linenos_special_style} }}',
|
||||
]
|
||||
|
||||
return lines
|
||||
@@ -593,17 +594,15 @@ class HtmlFormatter(Formatter):
|
||||
|
||||
@property
|
||||
def _linenos_style(self):
|
||||
return 'color: %s; background-color: %s; padding-left: 5px; padding-right: 5px;' % (
|
||||
self.style.line_number_color,
|
||||
self.style.line_number_background_color
|
||||
)
|
||||
color = self.style.line_number_color
|
||||
background_color = self.style.line_number_background_color
|
||||
return f'color: {color}; background-color: {background_color}; padding-left: 5px; padding-right: 5px;'
|
||||
|
||||
@property
|
||||
def _linenos_special_style(self):
|
||||
return 'color: %s; background-color: %s; padding-left: 5px; padding-right: 5px;' % (
|
||||
self.style.line_number_special_color,
|
||||
self.style.line_number_special_background_color
|
||||
)
|
||||
color = self.style.line_number_special_color
|
||||
background_color = self.style.line_number_special_background_color
|
||||
return f'color: {color}; background-color: {background_color}; padding-left: 5px; padding-right: 5px;'
|
||||
|
||||
def _decodeifneeded(self, value):
|
||||
if isinstance(value, bytes):
|
||||
@@ -684,9 +683,9 @@ class HtmlFormatter(Formatter):
|
||||
|
||||
if nocls:
|
||||
if special_line:
|
||||
style = ' style="%s"' % self._linenos_special_style
|
||||
style = f' style="{self._linenos_special_style}"'
|
||||
else:
|
||||
style = ' style="%s"' % self._linenos_style
|
||||
style = f' style="{self._linenos_style}"'
|
||||
else:
|
||||
if special_line:
|
||||
style = ' class="special"'
|
||||
@@ -694,7 +693,7 @@ class HtmlFormatter(Formatter):
|
||||
style = ' class="normal"'
|
||||
|
||||
if style:
|
||||
line = '<span%s>%s</span>' % (style, line)
|
||||
line = f'<span{style}>{line}</span>'
|
||||
|
||||
lines.append(line)
|
||||
|
||||
@@ -743,9 +742,9 @@ class HtmlFormatter(Formatter):
|
||||
|
||||
if nocls:
|
||||
if special_line:
|
||||
style = ' style="%s"' % self._linenos_special_style
|
||||
style = f' style="{self._linenos_special_style}"'
|
||||
else:
|
||||
style = ' style="%s"' % self._linenos_style
|
||||
style = f' style="{self._linenos_style}"'
|
||||
else:
|
||||
if special_line:
|
||||
style = ' class="linenos special"'
|
||||
@@ -753,7 +752,7 @@ class HtmlFormatter(Formatter):
|
||||
style = ' class="linenos"'
|
||||
|
||||
if style:
|
||||
linenos = '<span%s>%s</span>' % (style, line)
|
||||
linenos = f'<span{style}>{line}</span>'
|
||||
else:
|
||||
linenos = line
|
||||
|
||||
@@ -790,13 +789,13 @@ class HtmlFormatter(Formatter):
|
||||
style = []
|
||||
if (self.noclasses and not self.nobackground and
|
||||
self.style.background_color is not None):
|
||||
style.append('background: %s' % (self.style.background_color,))
|
||||
style.append(f'background: {self.style.background_color}')
|
||||
if self.cssstyles:
|
||||
style.append(self.cssstyles)
|
||||
style = '; '.join(style)
|
||||
|
||||
yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) +
|
||||
(style and (' style="%s"' % style)) + '>')
|
||||
yield 0, ('<div' + (self.cssclass and f' class="{self.cssclass}"') +
|
||||
(style and (f' style="{style}"')) + '>')
|
||||
yield from inner
|
||||
yield 0, '</div>\n'
|
||||
|
||||
@@ -813,7 +812,7 @@ class HtmlFormatter(Formatter):
|
||||
|
||||
# the empty span here is to keep leading empty lines from being
|
||||
# ignored by HTML parsers
|
||||
yield 0, ('<pre' + (style and ' style="%s"' % style) + '><span></span>')
|
||||
yield 0, ('<pre' + (style and f' style="{style}"') + '><span></span>')
|
||||
yield from inner
|
||||
yield 0, '</pre>'
|
||||
|
||||
@@ -842,18 +841,18 @@ class HtmlFormatter(Formatter):
|
||||
try:
|
||||
cspan = self.span_element_openers[ttype]
|
||||
except KeyError:
|
||||
title = ' title="%s"' % '.'.join(ttype) if self.debug_token_types else ''
|
||||
title = ' title="{}"'.format('.'.join(ttype)) if self.debug_token_types else ''
|
||||
if nocls:
|
||||
css_style = self._get_css_inline_styles(ttype)
|
||||
if css_style:
|
||||
css_style = self.class2style[css_style][0]
|
||||
cspan = '<span style="%s"%s>' % (css_style, title)
|
||||
cspan = f'<span style="{css_style}"{title}>'
|
||||
else:
|
||||
cspan = ''
|
||||
else:
|
||||
css_class = self._get_css_classes(ttype)
|
||||
if css_class:
|
||||
cspan = '<span class="%s"%s>' % (css_class, title)
|
||||
cspan = f'<span class="{css_class}"{title}>'
|
||||
else:
|
||||
cspan = ''
|
||||
self.span_element_openers[ttype] = cspan
|
||||
@@ -908,7 +907,7 @@ class HtmlFormatter(Formatter):
|
||||
def _lookup_ctag(self, token):
|
||||
entry = ctags.TagEntry()
|
||||
if self._ctags.find(entry, token.encode(), 0):
|
||||
return entry['file'], entry['lineNumber']
|
||||
return entry['file'].decode(), entry['lineNumber']
|
||||
else:
|
||||
return None, None
|
||||
|
||||
@@ -926,11 +925,10 @@ class HtmlFormatter(Formatter):
|
||||
if self.noclasses:
|
||||
style = ''
|
||||
if self.style.highlight_color is not None:
|
||||
style = (' style="background-color: %s"' %
|
||||
(self.style.highlight_color,))
|
||||
yield 1, '<span%s>%s</span>' % (style, value)
|
||||
style = (f' style="background-color: {self.style.highlight_color}"')
|
||||
yield 1, f'<span{style}>{value}</span>'
|
||||
else:
|
||||
yield 1, '<span class="hll">%s</span>' % value
|
||||
yield 1, f'<span class="hll">{value}</span>'
|
||||
else:
|
||||
yield 1, value
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
Formatter for Pixmap output.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -68,6 +67,15 @@ class FontManager:
|
||||
self.font_size = font_size
|
||||
self.fonts = {}
|
||||
self.encoding = None
|
||||
self.variable = False
|
||||
if hasattr(font_name, 'read') or os.path.isfile(font_name):
|
||||
font = ImageFont.truetype(font_name, self.font_size)
|
||||
self.variable = True
|
||||
for style in STYLES:
|
||||
self.fonts[style] = font
|
||||
|
||||
return
|
||||
|
||||
if sys.platform.startswith('win'):
|
||||
if not font_name:
|
||||
self.font_name = DEFAULT_FONT_NAME_WIN
|
||||
@@ -82,7 +90,7 @@ class FontManager:
|
||||
self._create_nix()
|
||||
|
||||
def _get_nix_font_path(self, name, style):
|
||||
proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'],
|
||||
proc = subprocess.Popen(['fc-list', f"{name}:style={style}", 'file'],
|
||||
stdout=subprocess.PIPE, stderr=None)
|
||||
stdout, _ = proc.communicate()
|
||||
if proc.returncode == 0:
|
||||
@@ -102,8 +110,7 @@ class FontManager:
|
||||
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
||||
break
|
||||
else:
|
||||
raise FontNotFound('No usable fonts named: "%s"' %
|
||||
self.font_name)
|
||||
raise FontNotFound(f'No usable fonts named: "{self.font_name}"')
|
||||
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
||||
for stylename in STYLES[style]:
|
||||
path = self._get_nix_font_path(self.font_name, stylename)
|
||||
@@ -134,8 +141,7 @@ class FontManager:
|
||||
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
|
||||
break
|
||||
else:
|
||||
raise FontNotFound('No usable fonts named: "%s"' %
|
||||
self.font_name)
|
||||
raise FontNotFound(f'No usable fonts named: "{self.font_name}"')
|
||||
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
|
||||
for stylename in STYLES[style]:
|
||||
path = self._get_mac_font_path(font_map, self.font_name, stylename)
|
||||
@@ -152,15 +158,14 @@ class FontManager:
|
||||
for suffix in ('', ' (TrueType)'):
|
||||
for style in styles:
|
||||
try:
|
||||
valname = '%s%s%s' % (basename, style and ' '+style, suffix)
|
||||
valname = '{}{}{}'.format(basename, style and ' '+style, suffix)
|
||||
val, _ = _winreg.QueryValueEx(key, valname)
|
||||
return val
|
||||
except OSError:
|
||||
continue
|
||||
else:
|
||||
if fail:
|
||||
raise FontNotFound('Font %s (%s) not found in registry' %
|
||||
(basename, styles[0]))
|
||||
raise FontNotFound(f'Font {basename} ({styles[0]}) not found in registry')
|
||||
return None
|
||||
|
||||
def _create_win(self):
|
||||
@@ -223,14 +228,43 @@ class FontManager:
|
||||
Get the font based on bold and italic flags.
|
||||
"""
|
||||
if bold and oblique:
|
||||
if self.variable:
|
||||
return self.get_style('BOLDITALIC')
|
||||
|
||||
return self.fonts['BOLDITALIC']
|
||||
elif bold:
|
||||
if self.variable:
|
||||
return self.get_style('BOLD')
|
||||
|
||||
return self.fonts['BOLD']
|
||||
elif oblique:
|
||||
if self.variable:
|
||||
return self.get_style('ITALIC')
|
||||
|
||||
return self.fonts['ITALIC']
|
||||
else:
|
||||
if self.variable:
|
||||
return self.get_style('NORMAL')
|
||||
|
||||
return self.fonts['NORMAL']
|
||||
|
||||
def get_style(self, style):
|
||||
"""
|
||||
Get the specified style of the font if it is a variable font.
|
||||
If not found, return the normal font.
|
||||
"""
|
||||
font = self.fonts[style]
|
||||
for style_name in STYLES[style]:
|
||||
try:
|
||||
font.set_variation_by_name(style_name)
|
||||
return font
|
||||
except ValueError:
|
||||
pass
|
||||
except OSError:
|
||||
return font
|
||||
|
||||
return font
|
||||
|
||||
|
||||
class ImageFormatter(Formatter):
|
||||
"""
|
||||
@@ -258,6 +292,8 @@ class ImageFormatter(Formatter):
|
||||
The font name to be used as the base font from which others, such as
|
||||
bold and italic fonts will be generated. This really should be a
|
||||
monospace font to look sane.
|
||||
If a filename or a file-like object is specified, the user must
|
||||
provide different styles of the font.
|
||||
|
||||
Default: "Courier New" on Windows, "Menlo" on Mac OS, and
|
||||
"DejaVu Sans Mono" on \\*nix
|
||||
@@ -594,7 +630,11 @@ class ImageFormatter(Formatter):
|
||||
fill=self.hl_color)
|
||||
for pos, value, font, text_fg, text_bg in self.drawables:
|
||||
if text_bg:
|
||||
text_size = draw.textsize(text=value, font=font)
|
||||
# see deprecations https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
|
||||
if hasattr(draw, 'textsize'):
|
||||
text_size = draw.textsize(text=value, font=font)
|
||||
else:
|
||||
text_size = font.getbbox(value)[2:]
|
||||
draw.rectangle([pos[0], pos[1], pos[0] + text_size[0], pos[1] + text_size[1]], fill=text_bg)
|
||||
draw.text(pos, value, font=font, fill=text_fg)
|
||||
im.save(outfile, self.image_format.upper())
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Formatter for IRC output
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Formatter for LaTeX fancyvrb output.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -23,21 +23,21 @@ def escape_tex(text, commandprefix):
|
||||
return text.replace('\\', '\x00'). \
|
||||
replace('{', '\x01'). \
|
||||
replace('}', '\x02'). \
|
||||
replace('\x00', r'\%sZbs{}' % commandprefix). \
|
||||
replace('\x01', r'\%sZob{}' % commandprefix). \
|
||||
replace('\x02', r'\%sZcb{}' % commandprefix). \
|
||||
replace('^', r'\%sZca{}' % commandprefix). \
|
||||
replace('_', r'\%sZus{}' % commandprefix). \
|
||||
replace('&', r'\%sZam{}' % commandprefix). \
|
||||
replace('<', r'\%sZlt{}' % commandprefix). \
|
||||
replace('>', r'\%sZgt{}' % commandprefix). \
|
||||
replace('#', r'\%sZsh{}' % commandprefix). \
|
||||
replace('%', r'\%sZpc{}' % commandprefix). \
|
||||
replace('$', r'\%sZdl{}' % commandprefix). \
|
||||
replace('-', r'\%sZhy{}' % commandprefix). \
|
||||
replace("'", r'\%sZsq{}' % commandprefix). \
|
||||
replace('"', r'\%sZdq{}' % commandprefix). \
|
||||
replace('~', r'\%sZti{}' % commandprefix)
|
||||
replace('\x00', rf'\{commandprefix}Zbs{{}}'). \
|
||||
replace('\x01', rf'\{commandprefix}Zob{{}}'). \
|
||||
replace('\x02', rf'\{commandprefix}Zcb{{}}'). \
|
||||
replace('^', rf'\{commandprefix}Zca{{}}'). \
|
||||
replace('_', rf'\{commandprefix}Zus{{}}'). \
|
||||
replace('&', rf'\{commandprefix}Zam{{}}'). \
|
||||
replace('<', rf'\{commandprefix}Zlt{{}}'). \
|
||||
replace('>', rf'\{commandprefix}Zgt{{}}'). \
|
||||
replace('#', rf'\{commandprefix}Zsh{{}}'). \
|
||||
replace('%', rf'\{commandprefix}Zpc{{}}'). \
|
||||
replace('$', rf'\{commandprefix}Zdl{{}}'). \
|
||||
replace('-', rf'\{commandprefix}Zhy{{}}'). \
|
||||
replace("'", rf'\{commandprefix}Zsq{{}}'). \
|
||||
replace('"', rf'\{commandprefix}Zdq{{}}'). \
|
||||
replace('~', rf'\{commandprefix}Zti{{}}')
|
||||
|
||||
|
||||
DOC_TEMPLATE = r'''
|
||||
@@ -304,17 +304,14 @@ class LatexFormatter(Formatter):
|
||||
if ndef['mono']:
|
||||
cmndef += r'\let\$$@ff=\textsf'
|
||||
if ndef['color']:
|
||||
cmndef += (r'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}' %
|
||||
rgbcolor(ndef['color']))
|
||||
cmndef += (r'\def\$$@tc##1{{\textcolor[rgb]{{{}}}{{##1}}}}'.format(rgbcolor(ndef['color'])))
|
||||
if ndef['border']:
|
||||
cmndef += (r'\def\$$@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}'
|
||||
r'\fcolorbox[rgb]{%s}{%s}{\strut ##1}}}' %
|
||||
(rgbcolor(ndef['border']),
|
||||
cmndef += (r'\def\$$@bc##1{{{{\setlength{{\fboxsep}}{{\string -\fboxrule}}'
|
||||
r'\fcolorbox[rgb]{{{}}}{{{}}}{{\strut ##1}}}}}}'.format(rgbcolor(ndef['border']),
|
||||
rgbcolor(ndef['bgcolor'])))
|
||||
elif ndef['bgcolor']:
|
||||
cmndef += (r'\def\$$@bc##1{{\setlength{\fboxsep}{0pt}'
|
||||
r'\colorbox[rgb]{%s}{\strut ##1}}}' %
|
||||
rgbcolor(ndef['bgcolor']))
|
||||
cmndef += (r'\def\$$@bc##1{{{{\setlength{{\fboxsep}}{{0pt}}'
|
||||
r'\colorbox[rgb]{{{}}}{{\strut ##1}}}}}}'.format(rgbcolor(ndef['bgcolor'])))
|
||||
if cmndef == '':
|
||||
continue
|
||||
cmndef = cmndef.replace('$$', cp)
|
||||
@@ -329,7 +326,7 @@ class LatexFormatter(Formatter):
|
||||
cp = self.commandprefix
|
||||
styles = []
|
||||
for name, definition in self.cmd2def.items():
|
||||
styles.append(r'\@namedef{%s@tok@%s}{%s}' % (cp, name, definition))
|
||||
styles.append(rf'\@namedef{{{cp}@tok@{name}}}{{{definition}}}')
|
||||
return STYLE_TEMPLATE % {'cp': self.commandprefix,
|
||||
'styles': '\n'.join(styles)}
|
||||
|
||||
@@ -410,10 +407,10 @@ class LatexFormatter(Formatter):
|
||||
spl = value.split('\n')
|
||||
for line in spl[:-1]:
|
||||
if line:
|
||||
outfile.write("\\%s{%s}{%s}" % (cp, styleval, line))
|
||||
outfile.write(f"\\{cp}{{{styleval}}}{{{line}}}")
|
||||
outfile.write('\n')
|
||||
if spl[-1]:
|
||||
outfile.write("\\%s{%s}{%s}" % (cp, styleval, spl[-1]))
|
||||
outfile.write(f"\\{cp}{{{styleval}}}{{{spl[-1]}}}")
|
||||
else:
|
||||
outfile.write(value)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Other formatters: NullFormatter, RawTokenFormatter.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -74,8 +74,7 @@ class RawTokenFormatter(Formatter):
|
||||
try:
|
||||
colorize(self.error_color, '')
|
||||
except KeyError:
|
||||
raise ValueError("Invalid color %r specified" %
|
||||
self.error_color)
|
||||
raise ValueError(f"Invalid color {self.error_color!r} specified")
|
||||
|
||||
def format(self, tokensource, outfile):
|
||||
try:
|
||||
@@ -147,7 +146,7 @@ class TestcaseFormatter(Formatter):
|
||||
outbuf = []
|
||||
for ttype, value in tokensource:
|
||||
rawbuf.append(value)
|
||||
outbuf.append('%s(%s, %r),\n' % (indentation, ttype, value))
|
||||
outbuf.append(f'{indentation}({ttype}, {value!r}),\n')
|
||||
|
||||
before = TESTCASE_BEFORE % (''.join(rawbuf),)
|
||||
during = ''.join(outbuf)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Formatter for Pango markup output.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -45,7 +45,7 @@ class PangoMarkupFormatter(Formatter):
|
||||
start = ''
|
||||
end = ''
|
||||
if style['color']:
|
||||
start += '<span fgcolor="#%s">' % style['color']
|
||||
start += '<span fgcolor="#{}">'.format(style['color'])
|
||||
end = '</span>' + end
|
||||
if style['bold']:
|
||||
start += '<b>'
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
|
||||
A formatter that generates RTF files.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
from collections import OrderedDict
|
||||
from pip._vendor.pygments.formatter import Formatter
|
||||
from pip._vendor.pygments.util import get_int_opt, surrogatepair
|
||||
from pip._vendor.pygments.style import _ansimap
|
||||
from pip._vendor.pygments.util import get_bool_opt, get_int_opt, get_list_opt, surrogatepair
|
||||
|
||||
|
||||
__all__ = ['RtfFormatter']
|
||||
@@ -42,6 +44,59 @@ class RtfFormatter(Formatter):
|
||||
default is 24 half-points, giving a size 12 font.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
`linenos`
|
||||
Turn on line numbering (default: ``False``).
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`lineno_fontsize`
|
||||
Font size for line numbers. Size is specified in half points
|
||||
(default: `fontsize`).
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`lineno_padding`
|
||||
Number of spaces between the (inline) line numbers and the
|
||||
source code (default: ``2``).
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`linenostart`
|
||||
The line number for the first line (default: ``1``).
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`linenostep`
|
||||
If set to a number n > 1, only every nth line number is printed.
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`lineno_color`
|
||||
Color for line numbers specified as a hex triplet, e.g. ``'5e5e5e'``.
|
||||
Defaults to the style's line number color if it is a hex triplet,
|
||||
otherwise ansi bright black.
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`hl_lines`
|
||||
Specify a list of lines to be highlighted, as line numbers separated by
|
||||
spaces, e.g. ``'3 7 8'``. The line numbers are relative to the input
|
||||
(i.e. the first line is line 1) unless `hl_linenostart` is set.
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`hl_color`
|
||||
Color for highlighting the lines specified in `hl_lines`, specified as
|
||||
a hex triplet (default: style's `highlight_color`).
|
||||
|
||||
.. versionadded:: 2.18
|
||||
|
||||
`hl_linenostart`
|
||||
If set to ``True`` line numbers in `hl_lines` are specified
|
||||
relative to `linenostart` (default ``False``).
|
||||
|
||||
.. versionadded:: 2.18
|
||||
"""
|
||||
name = 'RTF'
|
||||
aliases = ['rtf']
|
||||
@@ -62,6 +117,40 @@ class RtfFormatter(Formatter):
|
||||
Formatter.__init__(self, **options)
|
||||
self.fontface = options.get('fontface') or ''
|
||||
self.fontsize = get_int_opt(options, 'fontsize', 0)
|
||||
self.linenos = get_bool_opt(options, 'linenos', False)
|
||||
self.lineno_fontsize = get_int_opt(options, 'lineno_fontsize',
|
||||
self.fontsize)
|
||||
self.lineno_padding = get_int_opt(options, 'lineno_padding', 2)
|
||||
self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
|
||||
self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
|
||||
self.hl_linenostart = get_bool_opt(options, 'hl_linenostart', False)
|
||||
|
||||
self.hl_color = options.get('hl_color', '')
|
||||
if not self.hl_color:
|
||||
self.hl_color = self.style.highlight_color
|
||||
|
||||
self.hl_lines = []
|
||||
for lineno in get_list_opt(options, 'hl_lines', []):
|
||||
try:
|
||||
lineno = int(lineno)
|
||||
if self.hl_linenostart:
|
||||
lineno = lineno - self.linenostart + 1
|
||||
self.hl_lines.append(lineno)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
self.lineno_color = options.get('lineno_color', '')
|
||||
if not self.lineno_color:
|
||||
if self.style.line_number_color == 'inherit':
|
||||
# style color is the css value 'inherit'
|
||||
# default to ansi bright-black
|
||||
self.lineno_color = _ansimap['ansibrightblack']
|
||||
else:
|
||||
# style color is assumed to be a hex triplet as other
|
||||
# colors in pygments/style.py
|
||||
self.lineno_color = self.style.line_number_color
|
||||
|
||||
self.color_mapping = self._create_color_mapping()
|
||||
|
||||
def _escape(self, text):
|
||||
return text.replace('\\', '\\\\') \
|
||||
@@ -90,43 +179,145 @@ class RtfFormatter(Formatter):
|
||||
# Force surrogate pairs
|
||||
buf.append('{\\u%d}{\\u%d}' % surrogatepair(cn))
|
||||
|
||||
return ''.join(buf).replace('\n', '\\par\n')
|
||||
return ''.join(buf).replace('\n', '\\par')
|
||||
|
||||
def format_unencoded(self, tokensource, outfile):
|
||||
# rtf 1.8 header
|
||||
outfile.write('{\\rtf1\\ansi\\uc0\\deff0'
|
||||
'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
|
||||
'{\\colortbl;' % (self.fontface and
|
||||
' ' + self._escape(self.fontface) or
|
||||
''))
|
||||
@staticmethod
|
||||
def hex_to_rtf_color(hex_color):
|
||||
if hex_color[0] == "#":
|
||||
hex_color = hex_color[1:]
|
||||
|
||||
# convert colors and save them in a mapping to access them later.
|
||||
color_mapping = {}
|
||||
return '\\red%d\\green%d\\blue%d;' % (
|
||||
int(hex_color[0:2], 16),
|
||||
int(hex_color[2:4], 16),
|
||||
int(hex_color[4:6], 16)
|
||||
)
|
||||
|
||||
def _split_tokens_on_newlines(self, tokensource):
|
||||
"""
|
||||
Split tokens containing newline characters into multiple token
|
||||
each representing a line of the input file. Needed for numbering
|
||||
lines of e.g. multiline comments.
|
||||
"""
|
||||
for ttype, value in tokensource:
|
||||
if value == '\n':
|
||||
yield (ttype, value)
|
||||
elif "\n" in value:
|
||||
lines = value.split("\n")
|
||||
for line in lines[:-1]:
|
||||
yield (ttype, line+"\n")
|
||||
if lines[-1]:
|
||||
yield (ttype, lines[-1])
|
||||
else:
|
||||
yield (ttype, value)
|
||||
|
||||
def _create_color_mapping(self):
|
||||
"""
|
||||
Create a mapping of style hex colors to index/offset in
|
||||
the RTF color table.
|
||||
"""
|
||||
color_mapping = OrderedDict()
|
||||
offset = 1
|
||||
|
||||
if self.linenos:
|
||||
color_mapping[self.lineno_color] = offset
|
||||
offset += 1
|
||||
|
||||
if self.hl_lines:
|
||||
color_mapping[self.hl_color] = offset
|
||||
offset += 1
|
||||
|
||||
for _, style in self.style:
|
||||
for color in style['color'], style['bgcolor'], style['border']:
|
||||
if color and color not in color_mapping:
|
||||
color_mapping[color] = offset
|
||||
outfile.write('\\red%d\\green%d\\blue%d;' % (
|
||||
int(color[0:2], 16),
|
||||
int(color[2:4], 16),
|
||||
int(color[4:6], 16)
|
||||
))
|
||||
offset += 1
|
||||
outfile.write('}\\f0 ')
|
||||
|
||||
return color_mapping
|
||||
|
||||
@property
|
||||
def _lineno_template(self):
|
||||
if self.lineno_fontsize != self.fontsize:
|
||||
return '{{\\fs{} \\cf{} %s{}}}'.format(self.lineno_fontsize,
|
||||
self.color_mapping[self.lineno_color],
|
||||
" " * self.lineno_padding)
|
||||
|
||||
return '{{\\cf{} %s{}}}'.format(self.color_mapping[self.lineno_color],
|
||||
" " * self.lineno_padding)
|
||||
|
||||
@property
|
||||
def _hl_open_str(self):
|
||||
return rf'{{\highlight{self.color_mapping[self.hl_color]} '
|
||||
|
||||
@property
|
||||
def _rtf_header(self):
|
||||
lines = []
|
||||
# rtf 1.8 header
|
||||
lines.append('{\\rtf1\\ansi\\uc0\\deff0'
|
||||
'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
|
||||
% (self.fontface and ' '
|
||||
+ self._escape(self.fontface) or ''))
|
||||
|
||||
# color table
|
||||
lines.append('{\\colortbl;')
|
||||
for color, _ in self.color_mapping.items():
|
||||
lines.append(self.hex_to_rtf_color(color))
|
||||
lines.append('}')
|
||||
|
||||
# font and fontsize
|
||||
lines.append('\\f0\\sa0')
|
||||
if self.fontsize:
|
||||
outfile.write('\\fs%d' % self.fontsize)
|
||||
lines.append('\\fs%d' % self.fontsize)
|
||||
|
||||
# ensure Libre Office Writer imports and renders consecutive
|
||||
# space characters the same width, needed for line numbering.
|
||||
# https://bugs.documentfoundation.org/show_bug.cgi?id=144050
|
||||
lines.append('\\dntblnsbdb')
|
||||
|
||||
return lines
|
||||
|
||||
def format_unencoded(self, tokensource, outfile):
|
||||
for line in self._rtf_header:
|
||||
outfile.write(line + "\n")
|
||||
|
||||
tokensource = self._split_tokens_on_newlines(tokensource)
|
||||
|
||||
# first pass of tokens to count lines, needed for line numbering
|
||||
if self.linenos:
|
||||
line_count = 0
|
||||
tokens = [] # for copying the token source generator
|
||||
for ttype, value in tokensource:
|
||||
tokens.append((ttype, value))
|
||||
if value.endswith("\n"):
|
||||
line_count += 1
|
||||
|
||||
# width of line number strings (for padding with spaces)
|
||||
linenos_width = len(str(line_count+self.linenostart-1))
|
||||
|
||||
tokensource = tokens
|
||||
|
||||
# highlight stream
|
||||
lineno = 1
|
||||
start_new_line = True
|
||||
for ttype, value in tokensource:
|
||||
if start_new_line and lineno in self.hl_lines:
|
||||
outfile.write(self._hl_open_str)
|
||||
|
||||
if start_new_line and self.linenos:
|
||||
if (lineno-self.linenostart+1)%self.linenostep == 0:
|
||||
current_lineno = lineno + self.linenostart - 1
|
||||
lineno_str = str(current_lineno).rjust(linenos_width)
|
||||
else:
|
||||
lineno_str = "".rjust(linenos_width)
|
||||
outfile.write(self._lineno_template % lineno_str)
|
||||
|
||||
while not self.style.styles_token(ttype) and ttype.parent:
|
||||
ttype = ttype.parent
|
||||
style = self.style.style_for_token(ttype)
|
||||
buf = []
|
||||
if style['bgcolor']:
|
||||
buf.append('\\cb%d' % color_mapping[style['bgcolor']])
|
||||
buf.append('\\cb%d' % self.color_mapping[style['bgcolor']])
|
||||
if style['color']:
|
||||
buf.append('\\cf%d' % color_mapping[style['color']])
|
||||
buf.append('\\cf%d' % self.color_mapping[style['color']])
|
||||
if style['bold']:
|
||||
buf.append('\\b')
|
||||
if style['italic']:
|
||||
@@ -135,12 +326,24 @@ class RtfFormatter(Formatter):
|
||||
buf.append('\\ul')
|
||||
if style['border']:
|
||||
buf.append('\\chbrdr\\chcfpat%d' %
|
||||
color_mapping[style['border']])
|
||||
self.color_mapping[style['border']])
|
||||
start = ''.join(buf)
|
||||
if start:
|
||||
outfile.write('{%s ' % start)
|
||||
outfile.write(f'{{{start} ')
|
||||
outfile.write(self._escape_text(value))
|
||||
if start:
|
||||
outfile.write('}')
|
||||
start_new_line = False
|
||||
|
||||
outfile.write('}')
|
||||
# complete line of input
|
||||
if value.endswith("\n"):
|
||||
# close line highlighting
|
||||
if lineno in self.hl_lines:
|
||||
outfile.write('}')
|
||||
# newline in RTF file after closing }
|
||||
outfile.write("\n")
|
||||
|
||||
start_new_line = True
|
||||
lineno += 1
|
||||
|
||||
outfile.write('}\n')
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Formatter for SVG output.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -60,11 +60,11 @@ class SvgFormatter(Formatter):
|
||||
|
||||
`linenostep`
|
||||
If set to a number n > 1, only every nth line number is printed.
|
||||
|
||||
|
||||
`linenowidth`
|
||||
Maximum width devoted to line numbers (default: ``3*ystep``, sufficient
|
||||
for up to 4-digit line numbers. Increase width for longer code blocks).
|
||||
|
||||
for up to 4-digit line numbers. Increase width for longer code blocks).
|
||||
|
||||
`xoffset`
|
||||
Starting offset in X direction, defaults to ``0``.
|
||||
|
||||
@@ -97,10 +97,11 @@ class SvgFormatter(Formatter):
|
||||
self.fontsize = options.get('fontsize', '14px')
|
||||
self.xoffset = get_int_opt(options, 'xoffset', 0)
|
||||
fs = self.fontsize.strip()
|
||||
if fs.endswith('px'): fs = fs[:-2].strip()
|
||||
if fs.endswith('px'):
|
||||
fs = fs[:-2].strip()
|
||||
try:
|
||||
int_fs = int(fs)
|
||||
except:
|
||||
except ValueError:
|
||||
int_fs = 20
|
||||
self.yoffset = get_int_opt(options, 'yoffset', int_fs)
|
||||
self.ystep = get_int_opt(options, 'ystep', int_fs + 5)
|
||||
@@ -122,30 +123,27 @@ class SvgFormatter(Formatter):
|
||||
y = self.yoffset
|
||||
if not self.nowrap:
|
||||
if self.encoding:
|
||||
outfile.write('<?xml version="1.0" encoding="%s"?>\n' %
|
||||
self.encoding)
|
||||
outfile.write(f'<?xml version="1.0" encoding="{self.encoding}"?>\n')
|
||||
else:
|
||||
outfile.write('<?xml version="1.0"?>\n')
|
||||
outfile.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" '
|
||||
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/'
|
||||
'svg10.dtd">\n')
|
||||
outfile.write('<svg xmlns="http://www.w3.org/2000/svg">\n')
|
||||
outfile.write('<g font-family="%s" font-size="%s">\n' %
|
||||
(self.fontfamily, self.fontsize))
|
||||
|
||||
counter = self.linenostart
|
||||
outfile.write(f'<g font-family="{self.fontfamily}" font-size="{self.fontsize}">\n')
|
||||
|
||||
counter = self.linenostart
|
||||
counter_step = self.linenostep
|
||||
counter_style = self._get_style(Comment)
|
||||
line_x = x
|
||||
|
||||
|
||||
if self.linenos:
|
||||
if counter % counter_step == 0:
|
||||
outfile.write('<text x="%s" y="%s" %s text-anchor="end">%s</text>' %
|
||||
(x+self.linenowidth,y,counter_style,counter))
|
||||
outfile.write(f'<text x="{x+self.linenowidth}" y="{y}" {counter_style} text-anchor="end">{counter}</text>')
|
||||
line_x += self.linenowidth + self.ystep
|
||||
counter += 1
|
||||
|
||||
outfile.write('<text x="%s" y="%s" xml:space="preserve">' % (line_x, y))
|
||||
outfile.write(f'<text x="{line_x}" y="{y}" xml:space="preserve">')
|
||||
for ttype, value in tokensource:
|
||||
style = self._get_style(ttype)
|
||||
tspan = style and '<tspan' + style + '>' or ''
|
||||
@@ -159,11 +157,10 @@ class SvgFormatter(Formatter):
|
||||
y += self.ystep
|
||||
outfile.write('</text>\n')
|
||||
if self.linenos and counter % counter_step == 0:
|
||||
outfile.write('<text x="%s" y="%s" text-anchor="end" %s>%s</text>' %
|
||||
(x+self.linenowidth,y,counter_style,counter))
|
||||
|
||||
outfile.write(f'<text x="{x+self.linenowidth}" y="{y}" text-anchor="end" {counter_style}>{counter}</text>')
|
||||
|
||||
counter += 1
|
||||
outfile.write('<text x="%s" y="%s" ' 'xml:space="preserve">' % (line_x,y))
|
||||
outfile.write(f'<text x="{line_x}" y="{y}" ' 'xml:space="preserve">')
|
||||
outfile.write(tspan + parts[-1] + tspanend)
|
||||
outfile.write('</text>')
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Formatter for terminal output with ANSI sequences.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
Formatter version 1.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Base lexer classes.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -67,10 +67,17 @@ class Lexer(metaclass=LexerMeta):
|
||||
:no-value:
|
||||
.. autoattribute:: priority
|
||||
|
||||
Lexers included in Pygments should have an additional attribute:
|
||||
Lexers included in Pygments should have two additional attributes:
|
||||
|
||||
.. autoattribute:: url
|
||||
:no-value:
|
||||
.. autoattribute:: version_added
|
||||
:no-value:
|
||||
|
||||
Lexers included in Pygments may have additional attributes:
|
||||
|
||||
.. autoattribute:: _example
|
||||
:no-value:
|
||||
|
||||
You can pass options to the constructor. The basic options recognized
|
||||
by all lexers and processed by the base `Lexer` class are:
|
||||
@@ -125,9 +132,16 @@ class Lexer(metaclass=LexerMeta):
|
||||
priority = 0
|
||||
|
||||
#: URL of the language specification/definition. Used in the Pygments
|
||||
#: documentation.
|
||||
#: documentation. Set to an empty string to disable.
|
||||
url = None
|
||||
|
||||
#: Version of Pygments in which the lexer was added.
|
||||
version_added = None
|
||||
|
||||
#: Example file name. Relative to the ``tests/examplefiles`` directory.
|
||||
#: This is used by the documentation generator to show an example.
|
||||
_example = None
|
||||
|
||||
def __init__(self, **options):
|
||||
"""
|
||||
This constructor takes arbitrary options as keyword arguments.
|
||||
@@ -160,10 +174,9 @@ class Lexer(metaclass=LexerMeta):
|
||||
|
||||
def __repr__(self):
|
||||
if self.options:
|
||||
return '<pygments.lexers.%s with %r>' % (self.__class__.__name__,
|
||||
self.options)
|
||||
return f'<pygments.lexers.{self.__class__.__name__} with {self.options!r}>'
|
||||
else:
|
||||
return '<pygments.lexers.%s>' % self.__class__.__name__
|
||||
return f'<pygments.lexers.{self.__class__.__name__}>'
|
||||
|
||||
def add_filter(self, filter_, **options):
|
||||
"""
|
||||
@@ -190,26 +203,17 @@ class Lexer(metaclass=LexerMeta):
|
||||
it's the same as if the return values was ``0.0``.
|
||||
"""
|
||||
|
||||
def get_tokens(self, text, unfiltered=False):
|
||||
"""
|
||||
This method is the basic interface of a lexer. It is called by
|
||||
the `highlight()` function. It must process the text and return an
|
||||
iterable of ``(tokentype, value)`` pairs from `text`.
|
||||
def _preprocess_lexer_input(self, text):
|
||||
"""Apply preprocessing such as decoding the input, removing BOM and normalizing newlines."""
|
||||
|
||||
Normally, you don't need to override this method. The default
|
||||
implementation processes the options recognized by all lexers
|
||||
(`stripnl`, `stripall` and so on), and then yields all tokens
|
||||
from `get_tokens_unprocessed()`, with the ``index`` dropped.
|
||||
|
||||
If `unfiltered` is set to `True`, the filtering mechanism is
|
||||
bypassed even if filters are defined.
|
||||
"""
|
||||
if not isinstance(text, str):
|
||||
if self.encoding == 'guess':
|
||||
text, _ = guess_decode(text)
|
||||
elif self.encoding == 'chardet':
|
||||
try:
|
||||
from pip._vendor import chardet
|
||||
# pip vendoring note: this code is not reachable by pip,
|
||||
# removed import of chardet to make it clear.
|
||||
raise ImportError('chardet is not vendored by pip')
|
||||
except ImportError as e:
|
||||
raise ImportError('To enable chardet encoding guessing, '
|
||||
'please install the chardet library '
|
||||
@@ -246,6 +250,24 @@ class Lexer(metaclass=LexerMeta):
|
||||
if self.ensurenl and not text.endswith('\n'):
|
||||
text += '\n'
|
||||
|
||||
return text
|
||||
|
||||
def get_tokens(self, text, unfiltered=False):
|
||||
"""
|
||||
This method is the basic interface of a lexer. It is called by
|
||||
the `highlight()` function. It must process the text and return an
|
||||
iterable of ``(tokentype, value)`` pairs from `text`.
|
||||
|
||||
Normally, you don't need to override this method. The default
|
||||
implementation processes the options recognized by all lexers
|
||||
(`stripnl`, `stripall` and so on), and then yields all tokens
|
||||
from `get_tokens_unprocessed()`, with the ``index`` dropped.
|
||||
|
||||
If `unfiltered` is set to `True`, the filtering mechanism is
|
||||
bypassed even if filters are defined.
|
||||
"""
|
||||
text = self._preprocess_lexer_input(text)
|
||||
|
||||
def streamer():
|
||||
for _, t, v in self.get_tokens_unprocessed(text):
|
||||
yield t, v
|
||||
@@ -490,7 +512,7 @@ class RegexLexerMeta(LexerMeta):
|
||||
def _process_token(cls, token):
|
||||
"""Preprocess the token component of a token definition."""
|
||||
assert type(token) is _TokenType or callable(token), \
|
||||
'token type must be simple type or callable, not %r' % (token,)
|
||||
f'token type must be simple type or callable, not {token!r}'
|
||||
return token
|
||||
|
||||
def _process_new_state(cls, new_state, unprocessed, processed):
|
||||
@@ -506,14 +528,14 @@ class RegexLexerMeta(LexerMeta):
|
||||
elif new_state[:5] == '#pop:':
|
||||
return -int(new_state[5:])
|
||||
else:
|
||||
assert False, 'unknown new state %r' % new_state
|
||||
assert False, f'unknown new state {new_state!r}'
|
||||
elif isinstance(new_state, combined):
|
||||
# combine a new state from existing ones
|
||||
tmp_state = '_tmp_%d' % cls._tmpname
|
||||
cls._tmpname += 1
|
||||
itokens = []
|
||||
for istate in new_state:
|
||||
assert istate != new_state, 'circular state ref %r' % istate
|
||||
assert istate != new_state, f'circular state ref {istate!r}'
|
||||
itokens.extend(cls._process_state(unprocessed,
|
||||
processed, istate))
|
||||
processed[tmp_state] = itokens
|
||||
@@ -526,12 +548,12 @@ class RegexLexerMeta(LexerMeta):
|
||||
'unknown new state ' + istate
|
||||
return new_state
|
||||
else:
|
||||
assert False, 'unknown new state def %r' % new_state
|
||||
assert False, f'unknown new state def {new_state!r}'
|
||||
|
||||
def _process_state(cls, unprocessed, processed, state):
|
||||
"""Preprocess a single state definition."""
|
||||
assert type(state) is str, "wrong state name %r" % state
|
||||
assert state[0] != '#', "invalid state name %r" % state
|
||||
assert isinstance(state, str), f"wrong state name {state!r}"
|
||||
assert state[0] != '#', f"invalid state name {state!r}"
|
||||
if state in processed:
|
||||
return processed[state]
|
||||
tokens = processed[state] = []
|
||||
@@ -539,7 +561,7 @@ class RegexLexerMeta(LexerMeta):
|
||||
for tdef in unprocessed[state]:
|
||||
if isinstance(tdef, include):
|
||||
# it's a state reference
|
||||
assert tdef != state, "circular state reference %r" % state
|
||||
assert tdef != state, f"circular state reference {state!r}"
|
||||
tokens.extend(cls._process_state(unprocessed, processed,
|
||||
str(tdef)))
|
||||
continue
|
||||
@@ -553,13 +575,12 @@ class RegexLexerMeta(LexerMeta):
|
||||
tokens.append((re.compile('').match, None, new_state))
|
||||
continue
|
||||
|
||||
assert type(tdef) is tuple, "wrong rule def %r" % tdef
|
||||
assert type(tdef) is tuple, f"wrong rule def {tdef!r}"
|
||||
|
||||
try:
|
||||
rex = cls._process_regex(tdef[0], rflags, state)
|
||||
except Exception as err:
|
||||
raise ValueError("uncompilable regex %r in state %r of %r: %s" %
|
||||
(tdef[0], state, cls, err)) from err
|
||||
raise ValueError(f"uncompilable regex {tdef[0]!r} in state {state!r} of {cls!r}: {err}") from err
|
||||
|
||||
token = cls._process_token(tdef[1])
|
||||
|
||||
@@ -720,7 +741,7 @@ class RegexLexer(Lexer, metaclass=RegexLexerMeta):
|
||||
elif new_state == '#push':
|
||||
statestack.append(statestack[-1])
|
||||
else:
|
||||
assert False, "wrong state def: %r" % new_state
|
||||
assert False, f"wrong state def: {new_state!r}"
|
||||
statetokens = tokendefs[statestack[-1]]
|
||||
break
|
||||
else:
|
||||
@@ -752,8 +773,7 @@ class LexerContext:
|
||||
self.stack = stack or ['root']
|
||||
|
||||
def __repr__(self):
|
||||
return 'LexerContext(%r, %r, %r)' % (
|
||||
self.text, self.pos, self.stack)
|
||||
return f'LexerContext({self.text!r}, {self.pos!r}, {self.stack!r})'
|
||||
|
||||
|
||||
class ExtendedRegexLexer(RegexLexer):
|
||||
@@ -808,7 +828,7 @@ class ExtendedRegexLexer(RegexLexer):
|
||||
elif new_state == '#push':
|
||||
ctx.stack.append(ctx.stack[-1])
|
||||
else:
|
||||
assert False, "wrong state def: %r" % new_state
|
||||
assert False, f"wrong state def: {new_state!r}"
|
||||
statetokens = tokendefs[ctx.stack[-1]]
|
||||
break
|
||||
else:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Pygments lexers.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -22,6 +22,7 @@ from pip._vendor.pygments.util import ClassNotFound, guess_decode
|
||||
COMPAT = {
|
||||
'Python3Lexer': 'PythonLexer',
|
||||
'Python3TracebackLexer': 'PythonTracebackLexer',
|
||||
'LeanLexer': 'Lean3Lexer',
|
||||
}
|
||||
|
||||
__all__ = ['get_lexer_by_name', 'get_lexer_for_filename', 'find_lexer_class',
|
||||
@@ -92,7 +93,7 @@ def find_lexer_class_by_name(_alias):
|
||||
.. versionadded:: 2.2
|
||||
"""
|
||||
if not _alias:
|
||||
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
||||
raise ClassNotFound(f'no lexer for alias {_alias!r} found')
|
||||
# lookup builtin lexers
|
||||
for module_name, name, aliases, _, _ in LEXERS.values():
|
||||
if _alias.lower() in aliases:
|
||||
@@ -103,7 +104,7 @@ def find_lexer_class_by_name(_alias):
|
||||
for cls in find_plugin_lexers():
|
||||
if _alias.lower() in cls.aliases:
|
||||
return cls
|
||||
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
||||
raise ClassNotFound(f'no lexer for alias {_alias!r} found')
|
||||
|
||||
|
||||
def get_lexer_by_name(_alias, **options):
|
||||
@@ -116,7 +117,7 @@ def get_lexer_by_name(_alias, **options):
|
||||
found.
|
||||
"""
|
||||
if not _alias:
|
||||
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
||||
raise ClassNotFound(f'no lexer for alias {_alias!r} found')
|
||||
|
||||
# lookup builtin lexers
|
||||
for module_name, name, aliases, _, _ in LEXERS.values():
|
||||
@@ -128,7 +129,7 @@ def get_lexer_by_name(_alias, **options):
|
||||
for cls in find_plugin_lexers():
|
||||
if _alias.lower() in cls.aliases:
|
||||
return cls(**options)
|
||||
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
||||
raise ClassNotFound(f'no lexer for alias {_alias!r} found')
|
||||
|
||||
|
||||
def load_lexer_from_file(filename, lexername="CustomLexer", **options):
|
||||
@@ -153,17 +154,16 @@ def load_lexer_from_file(filename, lexername="CustomLexer", **options):
|
||||
exec(f.read(), custom_namespace)
|
||||
# Retrieve the class `lexername` from that namespace
|
||||
if lexername not in custom_namespace:
|
||||
raise ClassNotFound('no valid %s class found in %s' %
|
||||
(lexername, filename))
|
||||
raise ClassNotFound(f'no valid {lexername} class found in {filename}')
|
||||
lexer_class = custom_namespace[lexername]
|
||||
# And finally instantiate it with the options
|
||||
return lexer_class(**options)
|
||||
except OSError as err:
|
||||
raise ClassNotFound('cannot read %s: %s' % (filename, err))
|
||||
raise ClassNotFound(f'cannot read {filename}: {err}')
|
||||
except ClassNotFound:
|
||||
raise
|
||||
except Exception as err:
|
||||
raise ClassNotFound('error when loading custom lexer: %s' % err)
|
||||
raise ClassNotFound(f'error when loading custom lexer: {err}')
|
||||
|
||||
|
||||
def find_lexer_class_for_filename(_fn, code=None):
|
||||
@@ -224,7 +224,7 @@ def get_lexer_for_filename(_fn, code=None, **options):
|
||||
"""
|
||||
res = find_lexer_class_for_filename(_fn, code)
|
||||
if not res:
|
||||
raise ClassNotFound('no lexer for filename %r found' % _fn)
|
||||
raise ClassNotFound(f'no lexer for filename {_fn!r} found')
|
||||
return res(**options)
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ def get_lexer_for_mimetype(_mime, **options):
|
||||
for cls in find_plugin_lexers():
|
||||
if _mime in cls.mimetypes:
|
||||
return cls(**options)
|
||||
raise ClassNotFound('no lexer for mimetype %r found' % _mime)
|
||||
raise ClassNotFound(f'no lexer for mimetype {_mime!r} found')
|
||||
|
||||
|
||||
def _iter_lexerclasses(plugins=True):
|
||||
@@ -279,7 +279,7 @@ def guess_lexer_for_filename(_fn, _text, **options):
|
||||
matching_lexers.add(lexer)
|
||||
primary[lexer] = False
|
||||
if not matching_lexers:
|
||||
raise ClassNotFound('no lexer for filename %r found' % fn)
|
||||
raise ClassNotFound(f'no lexer for filename {fn!r} found')
|
||||
if len(matching_lexers) == 1:
|
||||
return matching_lexers.pop()(**options)
|
||||
result = []
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -31,7 +31,8 @@ LEXERS = {
|
||||
'ArduinoLexer': ('pip._vendor.pygments.lexers.c_like', 'Arduino', ('arduino',), ('*.ino',), ('text/x-arduino',)),
|
||||
'ArrowLexer': ('pip._vendor.pygments.lexers.arrow', 'Arrow', ('arrow',), ('*.arw',), ()),
|
||||
'ArturoLexer': ('pip._vendor.pygments.lexers.arturo', 'Arturo', ('arturo', 'art'), ('*.art',), ()),
|
||||
'AscLexer': ('pip._vendor.pygments.lexers.asc', 'ASCII armored', ('asc', 'pem'), ('*.asc', '*.pem', 'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', 'id_rsa'), ('application/pgp-keys', 'application/pgp-encrypted', 'application/pgp-signature')),
|
||||
'AscLexer': ('pip._vendor.pygments.lexers.asc', 'ASCII armored', ('asc', 'pem'), ('*.asc', '*.pem', 'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', 'id_rsa'), ('application/pgp-keys', 'application/pgp-encrypted', 'application/pgp-signature', 'application/pem-certificate-chain')),
|
||||
'Asn1Lexer': ('pip._vendor.pygments.lexers.asn1', 'ASN.1', ('asn1',), ('*.asn1',), ()),
|
||||
'AspectJLexer': ('pip._vendor.pygments.lexers.jvm', 'AspectJ', ('aspectj',), ('*.aj',), ('text/x-aspectj',)),
|
||||
'AsymptoteLexer': ('pip._vendor.pygments.lexers.graphics', 'Asymptote', ('asymptote', 'asy'), ('*.asy',), ('text/x-asymptote',)),
|
||||
'AugeasLexer': ('pip._vendor.pygments.lexers.configs', 'Augeas', ('augeas',), ('*.aug',), ()),
|
||||
@@ -41,10 +42,11 @@ LEXERS = {
|
||||
'BBCBasicLexer': ('pip._vendor.pygments.lexers.basic', 'BBC Basic', ('bbcbasic',), ('*.bbc',), ()),
|
||||
'BBCodeLexer': ('pip._vendor.pygments.lexers.markup', 'BBCode', ('bbcode',), (), ('text/x-bbcode',)),
|
||||
'BCLexer': ('pip._vendor.pygments.lexers.algebra', 'BC', ('bc',), ('*.bc',), ()),
|
||||
'BQNLexer': ('pip._vendor.pygments.lexers.bqn', 'BQN', ('bqn',), ('*.bqn',), ()),
|
||||
'BSTLexer': ('pip._vendor.pygments.lexers.bibtex', 'BST', ('bst', 'bst-pybtex'), ('*.bst',), ()),
|
||||
'BareLexer': ('pip._vendor.pygments.lexers.bare', 'BARE', ('bare',), ('*.bare',), ()),
|
||||
'BaseMakefileLexer': ('pip._vendor.pygments.lexers.make', 'Base Makefile', ('basemake',), (), ()),
|
||||
'BashLexer': ('pip._vendor.pygments.lexers.shell', 'Bash', ('bash', 'sh', 'ksh', 'zsh', 'shell'), ('*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '*.exheres-0', '*.exlib', '*.zsh', '.bashrc', 'bashrc', '.bash_*', 'bash_*', 'zshrc', '.zshrc', '.kshrc', 'kshrc', 'PKGBUILD'), ('application/x-sh', 'application/x-shellscript', 'text/x-shellscript')),
|
||||
'BashLexer': ('pip._vendor.pygments.lexers.shell', 'Bash', ('bash', 'sh', 'ksh', 'zsh', 'shell', 'openrc'), ('*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '*.exheres-0', '*.exlib', '*.zsh', '.bashrc', 'bashrc', '.bash_*', 'bash_*', 'zshrc', '.zshrc', '.kshrc', 'kshrc', 'PKGBUILD'), ('application/x-sh', 'application/x-shellscript', 'text/x-shellscript')),
|
||||
'BashSessionLexer': ('pip._vendor.pygments.lexers.shell', 'Bash Session', ('console', 'shell-session'), ('*.sh-session', '*.shell-session'), ('application/x-shell-session', 'application/x-sh-session')),
|
||||
'BatchLexer': ('pip._vendor.pygments.lexers.shell', 'Batchfile', ('batch', 'bat', 'dosbatch', 'winbatch'), ('*.bat', '*.cmd'), ('application/x-dos-batch',)),
|
||||
'BddLexer': ('pip._vendor.pygments.lexers.bdd', 'Bdd', ('bdd',), ('*.feature',), ('text/x-bdd',)),
|
||||
@@ -53,6 +55,7 @@ LEXERS = {
|
||||
'BibTeXLexer': ('pip._vendor.pygments.lexers.bibtex', 'BibTeX', ('bibtex', 'bib'), ('*.bib',), ('text/x-bibtex',)),
|
||||
'BlitzBasicLexer': ('pip._vendor.pygments.lexers.basic', 'BlitzBasic', ('blitzbasic', 'b3d', 'bplus'), ('*.bb', '*.decls'), ('text/x-bb',)),
|
||||
'BlitzMaxLexer': ('pip._vendor.pygments.lexers.basic', 'BlitzMax', ('blitzmax', 'bmax'), ('*.bmx',), ('text/x-bmx',)),
|
||||
'BlueprintLexer': ('pip._vendor.pygments.lexers.blueprint', 'Blueprint', ('blueprint',), ('*.blp',), ('text/x-blueprint',)),
|
||||
'BnfLexer': ('pip._vendor.pygments.lexers.grammar_notation', 'BNF', ('bnf',), ('*.bnf',), ('text/x-bnf',)),
|
||||
'BoaLexer': ('pip._vendor.pygments.lexers.boa', 'Boa', ('boa',), ('*.boa',), ()),
|
||||
'BooLexer': ('pip._vendor.pygments.lexers.dotnet', 'Boo', ('boo',), ('*.boo',), ('text/x-boo',)),
|
||||
@@ -125,10 +128,12 @@ LEXERS = {
|
||||
'DaxLexer': ('pip._vendor.pygments.lexers.dax', 'Dax', ('dax',), ('*.dax',), ()),
|
||||
'DebianControlLexer': ('pip._vendor.pygments.lexers.installers', 'Debian Control file', ('debcontrol', 'control'), ('control',), ()),
|
||||
'DelphiLexer': ('pip._vendor.pygments.lexers.pascal', 'Delphi', ('delphi', 'pas', 'pascal', 'objectpascal'), ('*.pas', '*.dpr'), ('text/x-pascal',)),
|
||||
'DesktopLexer': ('pip._vendor.pygments.lexers.configs', 'Desktop file', ('desktop',), ('*.desktop',), ('application/x-desktop',)),
|
||||
'DevicetreeLexer': ('pip._vendor.pygments.lexers.devicetree', 'Devicetree', ('devicetree', 'dts'), ('*.dts', '*.dtsi'), ('text/x-c',)),
|
||||
'DgLexer': ('pip._vendor.pygments.lexers.python', 'dg', ('dg',), ('*.dg',), ('text/x-dg',)),
|
||||
'DiffLexer': ('pip._vendor.pygments.lexers.diff', 'Diff', ('diff', 'udiff'), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch')),
|
||||
'DjangoLexer': ('pip._vendor.pygments.lexers.templates', 'Django/Jinja', ('django', 'jinja'), (), ('application/x-django-templating', 'application/x-jinja')),
|
||||
'DnsZoneLexer': ('pip._vendor.pygments.lexers.dns', 'Zone', ('zone',), ('*.zone',), ('text/dns',)),
|
||||
'DockerLexer': ('pip._vendor.pygments.lexers.configs', 'Docker', ('docker', 'dockerfile'), ('Dockerfile', '*.docker'), ('text/x-dockerfile-config',)),
|
||||
'DtdLexer': ('pip._vendor.pygments.lexers.html', 'DTD', ('dtd',), ('*.dtd',), ('application/xml-dtd',)),
|
||||
'DuelLexer': ('pip._vendor.pygments.lexers.webmisc', 'Duel', ('duel', 'jbst', 'jsonml+bst'), ('*.duel', '*.jbst'), ('text/x-duel', 'text/x-jbst')),
|
||||
@@ -190,6 +195,7 @@ LEXERS = {
|
||||
'GoodDataCLLexer': ('pip._vendor.pygments.lexers.business', 'GoodData-CL', ('gooddata-cl',), ('*.gdc',), ('text/x-gooddata-cl',)),
|
||||
'GosuLexer': ('pip._vendor.pygments.lexers.jvm', 'Gosu', ('gosu',), ('*.gs', '*.gsx', '*.gsp', '*.vark'), ('text/x-gosu',)),
|
||||
'GosuTemplateLexer': ('pip._vendor.pygments.lexers.jvm', 'Gosu Template', ('gst',), ('*.gst',), ('text/x-gosu-template',)),
|
||||
'GraphQLLexer': ('pip._vendor.pygments.lexers.graphql', 'GraphQL', ('graphql',), ('*.graphql',), ()),
|
||||
'GraphvizLexer': ('pip._vendor.pygments.lexers.graphviz', 'Graphviz', ('graphviz', 'dot'), ('*.gv', '*.dot'), ('text/x-graphviz', 'text/vnd.graphviz')),
|
||||
'GroffLexer': ('pip._vendor.pygments.lexers.markup', 'Groff', ('groff', 'nroff', 'man'), ('*.[1-9]', '*.man', '*.1p', '*.3pm'), ('application/x-troff', 'text/troff')),
|
||||
'GroovyLexer': ('pip._vendor.pygments.lexers.jvm', 'Groovy', ('groovy',), ('*.groovy', '*.gradle'), ('text/x-groovy',)),
|
||||
@@ -210,8 +216,8 @@ LEXERS = {
|
||||
'HtmlSmartyLexer': ('pip._vendor.pygments.lexers.templates', 'HTML+Smarty', ('html+smarty',), (), ('text/html+smarty',)),
|
||||
'HttpLexer': ('pip._vendor.pygments.lexers.textfmts', 'HTTP', ('http',), (), ()),
|
||||
'HxmlLexer': ('pip._vendor.pygments.lexers.haxe', 'Hxml', ('haxeml', 'hxml'), ('*.hxml',), ()),
|
||||
'HyLexer': ('pip._vendor.pygments.lexers.lisp', 'Hy', ('hylang',), ('*.hy',), ('text/x-hy', 'application/x-hy')),
|
||||
'HybrisLexer': ('pip._vendor.pygments.lexers.scripting', 'Hybris', ('hybris', 'hy'), ('*.hy', '*.hyb'), ('text/x-hybris', 'application/x-hybris')),
|
||||
'HyLexer': ('pip._vendor.pygments.lexers.lisp', 'Hy', ('hylang', 'hy'), ('*.hy',), ('text/x-hy', 'application/x-hy')),
|
||||
'HybrisLexer': ('pip._vendor.pygments.lexers.scripting', 'Hybris', ('hybris',), ('*.hyb',), ('text/x-hybris', 'application/x-hybris')),
|
||||
'IDLLexer': ('pip._vendor.pygments.lexers.idl', 'IDL', ('idl',), ('*.pro',), ('text/idl',)),
|
||||
'IconLexer': ('pip._vendor.pygments.lexers.unicon', 'Icon', ('icon',), ('*.icon', '*.ICON'), ()),
|
||||
'IdrisLexer': ('pip._vendor.pygments.lexers.haskell', 'Idris', ('idris', 'idr'), ('*.idr',), ('text/x-idris',)),
|
||||
@@ -219,7 +225,7 @@ LEXERS = {
|
||||
'Inform6Lexer': ('pip._vendor.pygments.lexers.int_fiction', 'Inform 6', ('inform6', 'i6'), ('*.inf',), ()),
|
||||
'Inform6TemplateLexer': ('pip._vendor.pygments.lexers.int_fiction', 'Inform 6 template', ('i6t',), ('*.i6t',), ()),
|
||||
'Inform7Lexer': ('pip._vendor.pygments.lexers.int_fiction', 'Inform 7', ('inform7', 'i7'), ('*.ni', '*.i7x'), ()),
|
||||
'IniLexer': ('pip._vendor.pygments.lexers.configs', 'INI', ('ini', 'cfg', 'dosini'), ('*.ini', '*.cfg', '*.inf', '.editorconfig', '*.service', '*.socket', '*.device', '*.mount', '*.automount', '*.swap', '*.target', '*.path', '*.timer', '*.slice', '*.scope'), ('text/x-ini', 'text/inf')),
|
||||
'IniLexer': ('pip._vendor.pygments.lexers.configs', 'INI', ('ini', 'cfg', 'dosini'), ('*.ini', '*.cfg', '*.inf', '.editorconfig'), ('text/x-ini', 'text/inf')),
|
||||
'IoLexer': ('pip._vendor.pygments.lexers.iolang', 'Io', ('io',), ('*.io',), ('text/x-iosrc',)),
|
||||
'IokeLexer': ('pip._vendor.pygments.lexers.jvm', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)),
|
||||
'IrcLogsLexer': ('pip._vendor.pygments.lexers.textfmts', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)),
|
||||
@@ -228,6 +234,7 @@ LEXERS = {
|
||||
'JMESPathLexer': ('pip._vendor.pygments.lexers.jmespath', 'JMESPath', ('jmespath', 'jp'), ('*.jp',), ()),
|
||||
'JSLTLexer': ('pip._vendor.pygments.lexers.jslt', 'JSLT', ('jslt',), ('*.jslt',), ('text/x-jslt',)),
|
||||
'JagsLexer': ('pip._vendor.pygments.lexers.modeling', 'JAGS', ('jags',), ('*.jag', '*.bug'), ()),
|
||||
'JanetLexer': ('pip._vendor.pygments.lexers.lisp', 'Janet', ('janet',), ('*.janet', '*.jdn'), ('text/x-janet', 'application/x-janet')),
|
||||
'JasminLexer': ('pip._vendor.pygments.lexers.jvm', 'Jasmin', ('jasmin', 'jasminxt'), ('*.j',), ()),
|
||||
'JavaLexer': ('pip._vendor.pygments.lexers.jvm', 'Java', ('java',), ('*.java',), ('text/x-java',)),
|
||||
'JavascriptDjangoLexer': ('pip._vendor.pygments.lexers.templates', 'JavaScript+Django/Jinja', ('javascript+django', 'js+django', 'javascript+jinja', 'js+jinja'), ('*.js.j2', '*.js.jinja2'), ('application/x-javascript+django', 'application/x-javascript+jinja', 'text/x-javascript+django', 'text/x-javascript+jinja', 'text/javascript+django', 'text/javascript+jinja')),
|
||||
@@ -241,9 +248,10 @@ LEXERS = {
|
||||
'JsgfLexer': ('pip._vendor.pygments.lexers.grammar_notation', 'JSGF', ('jsgf',), ('*.jsgf',), ('application/jsgf', 'application/x-jsgf', 'text/jsgf')),
|
||||
'JsonBareObjectLexer': ('pip._vendor.pygments.lexers.data', 'JSONBareObject', (), (), ()),
|
||||
'JsonLdLexer': ('pip._vendor.pygments.lexers.data', 'JSON-LD', ('jsonld', 'json-ld'), ('*.jsonld',), ('application/ld+json',)),
|
||||
'JsonLexer': ('pip._vendor.pygments.lexers.data', 'JSON', ('json', 'json-object'), ('*.json', 'Pipfile.lock'), ('application/json', 'application/json-object')),
|
||||
'JsonLexer': ('pip._vendor.pygments.lexers.data', 'JSON', ('json', 'json-object'), ('*.json', '*.jsonl', '*.ndjson', 'Pipfile.lock'), ('application/json', 'application/json-object', 'application/x-ndjson', 'application/jsonl', 'application/json-seq')),
|
||||
'JsonnetLexer': ('pip._vendor.pygments.lexers.jsonnet', 'Jsonnet', ('jsonnet',), ('*.jsonnet', '*.libsonnet'), ()),
|
||||
'JspLexer': ('pip._vendor.pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ('application/x-jsp',)),
|
||||
'JsxLexer': ('pip._vendor.pygments.lexers.jsx', 'JSX', ('jsx', 'react'), ('*.jsx', '*.react'), ('text/jsx', 'text/typescript-jsx')),
|
||||
'JuliaConsoleLexer': ('pip._vendor.pygments.lexers.julia', 'Julia console', ('jlcon', 'julia-repl'), (), ()),
|
||||
'JuliaLexer': ('pip._vendor.pygments.lexers.julia', 'Julia', ('julia', 'jl'), ('*.jl',), ('text/x-julia', 'application/x-julia')),
|
||||
'JuttleLexer': ('pip._vendor.pygments.lexers.javascript', 'Juttle', ('juttle',), ('*.juttle',), ('application/juttle', 'application/x-juttle', 'text/x-juttle', 'text/juttle')),
|
||||
@@ -254,13 +262,17 @@ LEXERS = {
|
||||
'KokaLexer': ('pip._vendor.pygments.lexers.haskell', 'Koka', ('koka',), ('*.kk', '*.kki'), ('text/x-koka',)),
|
||||
'KotlinLexer': ('pip._vendor.pygments.lexers.jvm', 'Kotlin', ('kotlin',), ('*.kt', '*.kts'), ('text/x-kotlin',)),
|
||||
'KuinLexer': ('pip._vendor.pygments.lexers.kuin', 'Kuin', ('kuin',), ('*.kn',), ()),
|
||||
'KustoLexer': ('pip._vendor.pygments.lexers.kusto', 'Kusto', ('kql', 'kusto'), ('*.kql', '*.kusto', '.csl'), ()),
|
||||
'LSLLexer': ('pip._vendor.pygments.lexers.scripting', 'LSL', ('lsl',), ('*.lsl',), ('text/x-lsl',)),
|
||||
'LassoCssLexer': ('pip._vendor.pygments.lexers.templates', 'CSS+Lasso', ('css+lasso',), (), ('text/css+lasso',)),
|
||||
'LassoHtmlLexer': ('pip._vendor.pygments.lexers.templates', 'HTML+Lasso', ('html+lasso',), (), ('text/html+lasso', 'application/x-httpd-lasso', 'application/x-httpd-lasso[89]')),
|
||||
'LassoJavascriptLexer': ('pip._vendor.pygments.lexers.templates', 'JavaScript+Lasso', ('javascript+lasso', 'js+lasso'), (), ('application/x-javascript+lasso', 'text/x-javascript+lasso', 'text/javascript+lasso')),
|
||||
'LassoLexer': ('pip._vendor.pygments.lexers.javascript', 'Lasso', ('lasso', 'lassoscript'), ('*.lasso', '*.lasso[89]'), ('text/x-lasso',)),
|
||||
'LassoXmlLexer': ('pip._vendor.pygments.lexers.templates', 'XML+Lasso', ('xml+lasso',), (), ('application/xml+lasso',)),
|
||||
'LeanLexer': ('pip._vendor.pygments.lexers.theorem', 'Lean', ('lean',), ('*.lean',), ('text/x-lean',)),
|
||||
'LdaprcLexer': ('pip._vendor.pygments.lexers.ldap', 'LDAP configuration file', ('ldapconf', 'ldaprc'), ('.ldaprc', 'ldaprc', 'ldap.conf'), ('text/x-ldapconf',)),
|
||||
'LdifLexer': ('pip._vendor.pygments.lexers.ldap', 'LDIF', ('ldif',), ('*.ldif',), ('text/x-ldif',)),
|
||||
'Lean3Lexer': ('pip._vendor.pygments.lexers.lean', 'Lean', ('lean', 'lean3'), ('*.lean',), ('text/x-lean', 'text/x-lean3')),
|
||||
'Lean4Lexer': ('pip._vendor.pygments.lexers.lean', 'Lean4', ('lean4',), ('*.lean',), ('text/x-lean4',)),
|
||||
'LessCssLexer': ('pip._vendor.pygments.lexers.css', 'LessCss', ('less',), ('*.less',), ('text/x-less-css',)),
|
||||
'LighttpdConfLexer': ('pip._vendor.pygments.lexers.configs', 'Lighttpd configuration file', ('lighttpd', 'lighty'), ('lighttpd.conf',), ('text/x-lighttpd-conf',)),
|
||||
'LilyPondLexer': ('pip._vendor.pygments.lexers.lilypond', 'LilyPond', ('lilypond',), ('*.ly',), ()),
|
||||
@@ -277,6 +289,7 @@ LEXERS = {
|
||||
'LogosLexer': ('pip._vendor.pygments.lexers.objective', 'Logos', ('logos',), ('*.x', '*.xi', '*.xm', '*.xmi'), ('text/x-logos',)),
|
||||
'LogtalkLexer': ('pip._vendor.pygments.lexers.prolog', 'Logtalk', ('logtalk',), ('*.lgt', '*.logtalk'), ('text/x-logtalk',)),
|
||||
'LuaLexer': ('pip._vendor.pygments.lexers.scripting', 'Lua', ('lua',), ('*.lua', '*.wlua'), ('text/x-lua', 'application/x-lua')),
|
||||
'LuauLexer': ('pip._vendor.pygments.lexers.scripting', 'Luau', ('luau',), ('*.luau',), ()),
|
||||
'MCFunctionLexer': ('pip._vendor.pygments.lexers.minecraft', 'MCFunction', ('mcfunction', 'mcf'), ('*.mcfunction',), ('text/mcfunction',)),
|
||||
'MCSchemaLexer': ('pip._vendor.pygments.lexers.minecraft', 'MCSchema', ('mcschema',), ('*.mcschema',), ('text/mcschema',)),
|
||||
'MIMELexer': ('pip._vendor.pygments.lexers.mime', 'MIME', ('mime',), (), ('multipart/mixed', 'multipart/related', 'multipart/alternative')),
|
||||
@@ -304,6 +317,7 @@ LEXERS = {
|
||||
'ModelicaLexer': ('pip._vendor.pygments.lexers.modeling', 'Modelica', ('modelica',), ('*.mo',), ('text/x-modelica',)),
|
||||
'Modula2Lexer': ('pip._vendor.pygments.lexers.modula2', 'Modula-2', ('modula2', 'm2'), ('*.def', '*.mod'), ('text/x-modula2',)),
|
||||
'MoinWikiLexer': ('pip._vendor.pygments.lexers.markup', 'MoinMoin/Trac Wiki markup', ('trac-wiki', 'moin'), (), ('text/x-trac-wiki',)),
|
||||
'MojoLexer': ('pip._vendor.pygments.lexers.mojo', 'Mojo', ('mojo', '🔥'), ('*.mojo', '*.🔥'), ('text/x-mojo', 'application/x-mojo')),
|
||||
'MonkeyLexer': ('pip._vendor.pygments.lexers.basic', 'Monkey', ('monkey',), ('*.monkey',), ('text/x-monkey',)),
|
||||
'MonteLexer': ('pip._vendor.pygments.lexers.monte', 'Monte', ('monte',), ('*.mt',), ()),
|
||||
'MoonScriptLexer': ('pip._vendor.pygments.lexers.scripting', 'MoonScript', ('moonscript', 'moon'), ('*.moon',), ('text/x-moonscript', 'application/x-moonscript')),
|
||||
@@ -351,6 +365,8 @@ LEXERS = {
|
||||
'OocLexer': ('pip._vendor.pygments.lexers.ooc', 'Ooc', ('ooc',), ('*.ooc',), ('text/x-ooc',)),
|
||||
'OpaLexer': ('pip._vendor.pygments.lexers.ml', 'Opa', ('opa',), ('*.opa',), ('text/x-opa',)),
|
||||
'OpenEdgeLexer': ('pip._vendor.pygments.lexers.business', 'OpenEdge ABL', ('openedge', 'abl', 'progress'), ('*.p', '*.cls'), ('text/x-openedge', 'application/x-openedge')),
|
||||
'OpenScadLexer': ('pip._vendor.pygments.lexers.openscad', 'OpenSCAD', ('openscad',), ('*.scad',), ('application/x-openscad',)),
|
||||
'OrgLexer': ('pip._vendor.pygments.lexers.markup', 'Org Mode', ('org', 'orgmode', 'org-mode'), ('*.org',), ('text/org',)),
|
||||
'OutputLexer': ('pip._vendor.pygments.lexers.special', 'Text output', ('output',), (), ()),
|
||||
'PacmanConfLexer': ('pip._vendor.pygments.lexers.configs', 'PacmanConf', ('pacmanconf',), ('pacman.conf',), ()),
|
||||
'PanLexer': ('pip._vendor.pygments.lexers.dsls', 'Pan', ('pan',), ('*.pan',), ()),
|
||||
@@ -379,16 +395,19 @@ LEXERS = {
|
||||
'ProcfileLexer': ('pip._vendor.pygments.lexers.procfile', 'Procfile', ('procfile',), ('Procfile',), ()),
|
||||
'PrologLexer': ('pip._vendor.pygments.lexers.prolog', 'Prolog', ('prolog',), ('*.ecl', '*.prolog', '*.pro', '*.pl'), ('text/x-prolog',)),
|
||||
'PromQLLexer': ('pip._vendor.pygments.lexers.promql', 'PromQL', ('promql',), ('*.promql',), ()),
|
||||
'PromelaLexer': ('pip._vendor.pygments.lexers.c_like', 'Promela', ('promela',), ('*.pml', '*.prom', '*.prm', '*.promela', '*.pr', '*.pm'), ('text/x-promela',)),
|
||||
'PropertiesLexer': ('pip._vendor.pygments.lexers.configs', 'Properties', ('properties', 'jproperties'), ('*.properties',), ('text/x-java-properties',)),
|
||||
'ProtoBufLexer': ('pip._vendor.pygments.lexers.dsls', 'Protocol Buffer', ('protobuf', 'proto'), ('*.proto',), ()),
|
||||
'PrqlLexer': ('pip._vendor.pygments.lexers.prql', 'PRQL', ('prql',), ('*.prql',), ('application/prql', 'application/x-prql')),
|
||||
'PsyshConsoleLexer': ('pip._vendor.pygments.lexers.php', 'PsySH console session for PHP', ('psysh',), (), ()),
|
||||
'PtxLexer': ('pip._vendor.pygments.lexers.ptx', 'PTX', ('ptx',), ('*.ptx',), ('text/x-ptx',)),
|
||||
'PugLexer': ('pip._vendor.pygments.lexers.html', 'Pug', ('pug', 'jade'), ('*.pug', '*.jade'), ('text/x-pug', 'text/x-jade')),
|
||||
'PuppetLexer': ('pip._vendor.pygments.lexers.dsls', 'Puppet', ('puppet',), ('*.pp',), ()),
|
||||
'PyPyLogLexer': ('pip._vendor.pygments.lexers.console', 'PyPy Log', ('pypylog', 'pypy'), ('*.pypylog',), ('application/x-pypylog',)),
|
||||
'Python2Lexer': ('pip._vendor.pygments.lexers.python', 'Python 2.x', ('python2', 'py2'), (), ('text/x-python2', 'application/x-python2')),
|
||||
'Python2TracebackLexer': ('pip._vendor.pygments.lexers.python', 'Python 2.x Traceback', ('py2tb',), ('*.py2tb',), ('text/x-python2-traceback',)),
|
||||
'PythonConsoleLexer': ('pip._vendor.pygments.lexers.python', 'Python console session', ('pycon',), (), ('text/x-python-doctest',)),
|
||||
'PythonLexer': ('pip._vendor.pygments.lexers.python', 'Python', ('python', 'py', 'sage', 'python3', 'py3'), ('*.py', '*.pyw', '*.pyi', '*.jy', '*.sage', '*.sc', 'SConstruct', 'SConscript', '*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE', '*.tac'), ('text/x-python', 'application/x-python', 'text/x-python3', 'application/x-python3')),
|
||||
'PythonConsoleLexer': ('pip._vendor.pygments.lexers.python', 'Python console session', ('pycon', 'python-console'), (), ('text/x-python-doctest',)),
|
||||
'PythonLexer': ('pip._vendor.pygments.lexers.python', 'Python', ('python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark'), ('*.py', '*.pyw', '*.pyi', '*.jy', '*.sage', '*.sc', 'SConstruct', 'SConscript', '*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE', '*.tac'), ('text/x-python', 'application/x-python', 'text/x-python3', 'application/x-python3')),
|
||||
'PythonTracebackLexer': ('pip._vendor.pygments.lexers.python', 'Python Traceback', ('pytb', 'py3tb'), ('*.pytb', '*.py3tb'), ('text/x-python-traceback', 'text/x-python3-traceback')),
|
||||
'PythonUL4Lexer': ('pip._vendor.pygments.lexers.ul4', 'Python+UL4', ('py+ul4',), ('*.pyul4',), ()),
|
||||
'QBasicLexer': ('pip._vendor.pygments.lexers.basic', 'QBasic', ('qbasic', 'basic'), ('*.BAS', '*.bas'), ('text/basic',)),
|
||||
@@ -460,6 +479,7 @@ LEXERS = {
|
||||
'SnobolLexer': ('pip._vendor.pygments.lexers.snobol', 'Snobol', ('snobol',), ('*.snobol',), ('text/x-snobol',)),
|
||||
'SnowballLexer': ('pip._vendor.pygments.lexers.dsls', 'Snowball', ('snowball',), ('*.sbl',), ()),
|
||||
'SolidityLexer': ('pip._vendor.pygments.lexers.solidity', 'Solidity', ('solidity',), ('*.sol',), ()),
|
||||
'SoongLexer': ('pip._vendor.pygments.lexers.soong', 'Soong', ('androidbp', 'bp', 'soong'), ('Android.bp',), ()),
|
||||
'SophiaLexer': ('pip._vendor.pygments.lexers.sophia', 'Sophia', ('sophia',), ('*.aes',), ()),
|
||||
'SourcePawnLexer': ('pip._vendor.pygments.lexers.pawn', 'SourcePawn', ('sp',), ('*.sp',), ('text/x-sourcepawn',)),
|
||||
'SourcesListLexer': ('pip._vendor.pygments.lexers.installers', 'Debian Sourcelist', ('debsources', 'sourceslist', 'sources.list'), ('sources.list',), ()),
|
||||
@@ -477,9 +497,11 @@ LEXERS = {
|
||||
'SwiftLexer': ('pip._vendor.pygments.lexers.objective', 'Swift', ('swift',), ('*.swift',), ('text/x-swift',)),
|
||||
'SwigLexer': ('pip._vendor.pygments.lexers.c_like', 'SWIG', ('swig',), ('*.swg', '*.i'), ('text/swig',)),
|
||||
'SystemVerilogLexer': ('pip._vendor.pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)),
|
||||
'SystemdLexer': ('pip._vendor.pygments.lexers.configs', 'Systemd', ('systemd',), ('*.service', '*.socket', '*.device', '*.mount', '*.automount', '*.swap', '*.target', '*.path', '*.timer', '*.slice', '*.scope'), ()),
|
||||
'TAPLexer': ('pip._vendor.pygments.lexers.testing', 'TAP', ('tap',), ('*.tap',), ()),
|
||||
'TNTLexer': ('pip._vendor.pygments.lexers.tnt', 'Typographic Number Theory', ('tnt',), ('*.tnt',), ()),
|
||||
'TOMLLexer': ('pip._vendor.pygments.lexers.configs', 'TOML', ('toml',), ('*.toml', 'Pipfile', 'poetry.lock'), ()),
|
||||
'TOMLLexer': ('pip._vendor.pygments.lexers.configs', 'TOML', ('toml',), ('*.toml', 'Pipfile', 'poetry.lock'), ('application/toml',)),
|
||||
'TactLexer': ('pip._vendor.pygments.lexers.tact', 'Tact', ('tact',), ('*.tact',), ()),
|
||||
'Tads3Lexer': ('pip._vendor.pygments.lexers.int_fiction', 'TADS 3', ('tads3',), ('*.t',), ()),
|
||||
'TalLexer': ('pip._vendor.pygments.lexers.tal', 'Tal', ('tal', 'uxntal'), ('*.tal',), ('text/x-uxntal',)),
|
||||
'TasmLexer': ('pip._vendor.pygments.lexers.asm', 'TASM', ('tasm',), ('*.asm', '*.ASM', '*.tasm'), ('text/x-tasm',)),
|
||||
@@ -498,6 +520,7 @@ LEXERS = {
|
||||
'ThriftLexer': ('pip._vendor.pygments.lexers.dsls', 'Thrift', ('thrift',), ('*.thrift',), ('application/x-thrift',)),
|
||||
'TiddlyWiki5Lexer': ('pip._vendor.pygments.lexers.markup', 'tiddler', ('tid',), ('*.tid',), ('text/vnd.tiddlywiki',)),
|
||||
'TlbLexer': ('pip._vendor.pygments.lexers.tlb', 'Tl-b', ('tlb',), ('*.tlb',), ()),
|
||||
'TlsLexer': ('pip._vendor.pygments.lexers.tls', 'TLS Presentation Language', ('tls',), (), ()),
|
||||
'TodotxtLexer': ('pip._vendor.pygments.lexers.textfmts', 'Todotxt', ('todotxt',), ('todo.txt', '*.todotxt'), ('text/x-todo',)),
|
||||
'TransactSqlLexer': ('pip._vendor.pygments.lexers.sql', 'Transact-SQL', ('tsql', 't-sql'), ('*.sql',), ('text/x-tsql',)),
|
||||
'TreetopLexer': ('pip._vendor.pygments.lexers.parsers', 'Treetop', ('treetop',), ('*.treetop', '*.tt'), ()),
|
||||
@@ -508,11 +531,13 @@ LEXERS = {
|
||||
'TypoScriptCssDataLexer': ('pip._vendor.pygments.lexers.typoscript', 'TypoScriptCssData', ('typoscriptcssdata',), (), ()),
|
||||
'TypoScriptHtmlDataLexer': ('pip._vendor.pygments.lexers.typoscript', 'TypoScriptHtmlData', ('typoscripthtmldata',), (), ()),
|
||||
'TypoScriptLexer': ('pip._vendor.pygments.lexers.typoscript', 'TypoScript', ('typoscript',), ('*.typoscript',), ('text/x-typoscript',)),
|
||||
'TypstLexer': ('pip._vendor.pygments.lexers.typst', 'Typst', ('typst',), ('*.typ',), ('text/x-typst',)),
|
||||
'UL4Lexer': ('pip._vendor.pygments.lexers.ul4', 'UL4', ('ul4',), ('*.ul4',), ()),
|
||||
'UcodeLexer': ('pip._vendor.pygments.lexers.unicon', 'ucode', ('ucode',), ('*.u', '*.u1', '*.u2'), ()),
|
||||
'UniconLexer': ('pip._vendor.pygments.lexers.unicon', 'Unicon', ('unicon',), ('*.icn',), ('text/unicon',)),
|
||||
'UnixConfigLexer': ('pip._vendor.pygments.lexers.configs', 'Unix/Linux config files', ('unixconfig', 'linuxconfig'), (), ()),
|
||||
'UrbiscriptLexer': ('pip._vendor.pygments.lexers.urbi', 'UrbiScript', ('urbiscript',), ('*.u',), ('application/x-urbiscript',)),
|
||||
'UrlEncodedLexer': ('pip._vendor.pygments.lexers.html', 'urlencoded', ('urlencoded',), (), ('application/x-www-form-urlencoded',)),
|
||||
'UsdLexer': ('pip._vendor.pygments.lexers.usd', 'USD', ('usd', 'usda'), ('*.usd', '*.usda'), ()),
|
||||
'VBScriptLexer': ('pip._vendor.pygments.lexers.basic', 'VBScript', ('vbscript',), ('*.vbs', '*.VBS'), ()),
|
||||
'VCLLexer': ('pip._vendor.pygments.lexers.varnish', 'VCL', ('vcl',), ('*.vcl',), ('text/x-vclsrc',)),
|
||||
@@ -521,13 +546,17 @@ LEXERS = {
|
||||
'VGLLexer': ('pip._vendor.pygments.lexers.dsls', 'VGL', ('vgl',), ('*.rpf',), ()),
|
||||
'ValaLexer': ('pip._vendor.pygments.lexers.c_like', 'Vala', ('vala', 'vapi'), ('*.vala', '*.vapi'), ('text/x-vala',)),
|
||||
'VbNetAspxLexer': ('pip._vendor.pygments.lexers.dotnet', 'aspx-vb', ('aspx-vb',), ('*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'), ()),
|
||||
'VbNetLexer': ('pip._vendor.pygments.lexers.dotnet', 'VB.net', ('vb.net', 'vbnet', 'lobas', 'oobas', 'sobas'), ('*.vb', '*.bas'), ('text/x-vbnet', 'text/x-vba')),
|
||||
'VbNetLexer': ('pip._vendor.pygments.lexers.dotnet', 'VB.net', ('vb.net', 'vbnet', 'lobas', 'oobas', 'sobas', 'visual-basic', 'visualbasic'), ('*.vb', '*.bas'), ('text/x-vbnet', 'text/x-vba')),
|
||||
'VelocityHtmlLexer': ('pip._vendor.pygments.lexers.templates', 'HTML+Velocity', ('html+velocity',), (), ('text/html+velocity',)),
|
||||
'VelocityLexer': ('pip._vendor.pygments.lexers.templates', 'Velocity', ('velocity',), ('*.vm', '*.fhtml'), ()),
|
||||
'VelocityXmlLexer': ('pip._vendor.pygments.lexers.templates', 'XML+Velocity', ('xml+velocity',), (), ('application/xml+velocity',)),
|
||||
'VerifpalLexer': ('pip._vendor.pygments.lexers.verifpal', 'Verifpal', ('verifpal',), ('*.vp',), ('text/x-verifpal',)),
|
||||
'VerilogLexer': ('pip._vendor.pygments.lexers.hdl', 'verilog', ('verilog', 'v'), ('*.v',), ('text/x-verilog',)),
|
||||
'VhdlLexer': ('pip._vendor.pygments.lexers.hdl', 'vhdl', ('vhdl',), ('*.vhdl', '*.vhd'), ('text/x-vhdl',)),
|
||||
'VimLexer': ('pip._vendor.pygments.lexers.textedit', 'VimL', ('vim',), ('*.vim', '.vimrc', '.exrc', '.gvimrc', '_vimrc', '_exrc', '_gvimrc', 'vimrc', 'gvimrc'), ('text/x-vim',)),
|
||||
'VisualPrologGrammarLexer': ('pip._vendor.pygments.lexers.vip', 'Visual Prolog Grammar', ('visualprologgrammar',), ('*.vipgrm',), ()),
|
||||
'VisualPrologLexer': ('pip._vendor.pygments.lexers.vip', 'Visual Prolog', ('visualprolog',), ('*.pro', '*.cl', '*.i', '*.pack', '*.ph'), ()),
|
||||
'VyperLexer': ('pip._vendor.pygments.lexers.vyper', 'Vyper', ('vyper',), ('*.vy',), ()),
|
||||
'WDiffLexer': ('pip._vendor.pygments.lexers.diff', 'WDiff', ('wdiff',), ('*.wdiff',), ()),
|
||||
'WatLexer': ('pip._vendor.pygments.lexers.webassembly', 'WebAssembly', ('wast', 'wat'), ('*.wat', '*.wast'), ()),
|
||||
'WebIDLLexer': ('pip._vendor.pygments.lexers.webidl', 'Web IDL', ('webidl',), ('*.webidl',), ()),
|
||||
@@ -552,6 +581,7 @@ LEXERS = {
|
||||
'YamlJinjaLexer': ('pip._vendor.pygments.lexers.templates', 'YAML+Jinja', ('yaml+jinja', 'salt', 'sls'), ('*.sls', '*.yaml.j2', '*.yml.j2', '*.yaml.jinja2', '*.yml.jinja2'), ('text/x-yaml+jinja', 'text/x-sls')),
|
||||
'YamlLexer': ('pip._vendor.pygments.lexers.data', 'YAML', ('yaml',), ('*.yaml', '*.yml'), ('text/x-yaml',)),
|
||||
'YangLexer': ('pip._vendor.pygments.lexers.yang', 'YANG', ('yang',), ('*.yang',), ('application/yang',)),
|
||||
'YaraLexer': ('pip._vendor.pygments.lexers.yara', 'YARA', ('yara', 'yar'), ('*.yar',), ('text/x-yara',)),
|
||||
'ZeekLexer': ('pip._vendor.pygments.lexers.dsls', 'Zeek', ('zeek', 'bro'), ('*.zeek', '*.bro'), ()),
|
||||
'ZephirLexer': ('pip._vendor.pygments.lexers.php', 'Zephir', ('zephir',), ('*.zep',), ()),
|
||||
'ZigLexer': ('pip._vendor.pygments.lexers.zig', 'Zig', ('zig',), ('*.zig',), ('text/zig',)),
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
|
||||
Lexers for Python and related languages.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
import keyword
|
||||
|
||||
from pip._vendor.pygments.lexer import DelegatingLexer, Lexer, RegexLexer, include, \
|
||||
bygroups, using, default, words, combined, do_insertions, this, line_re
|
||||
from pip._vendor.pygments.lexer import DelegatingLexer, RegexLexer, include, \
|
||||
bygroups, using, default, words, combined, this
|
||||
from pip._vendor.pygments.util import get_bool_opt, shebang_matches
|
||||
from pip._vendor.pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
||||
Number, Punctuation, Generic, Other, Error, Whitespace
|
||||
@@ -27,16 +26,14 @@ class PythonLexer(RegexLexer):
|
||||
"""
|
||||
For Python source code (version 3.x).
|
||||
|
||||
.. versionadded:: 0.10
|
||||
|
||||
.. versionchanged:: 2.5
|
||||
This is now the default ``PythonLexer``. It is still available as the
|
||||
alias ``Python3Lexer``.
|
||||
"""
|
||||
|
||||
name = 'Python'
|
||||
url = 'http://www.python.org'
|
||||
aliases = ['python', 'py', 'sage', 'python3', 'py3']
|
||||
url = 'https://www.python.org'
|
||||
aliases = ['python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark']
|
||||
filenames = [
|
||||
'*.py',
|
||||
'*.pyw',
|
||||
@@ -61,8 +58,9 @@ class PythonLexer(RegexLexer):
|
||||
]
|
||||
mimetypes = ['text/x-python', 'application/x-python',
|
||||
'text/x-python3', 'application/x-python3']
|
||||
version_added = '0.10'
|
||||
|
||||
uni_name = "[%s][%s]*" % (uni.xid_start, uni.xid_continue)
|
||||
uni_name = f"[{uni.xid_start}][{uni.xid_continue}]*"
|
||||
|
||||
def innerstring_rules(ttype):
|
||||
return [
|
||||
@@ -224,7 +222,8 @@ class PythonLexer(RegexLexer):
|
||||
r'(match|case)\b' # a possible keyword
|
||||
r'(?![ \t]*(?:' # not followed by...
|
||||
r'[:,;=^&|@~)\]}]|(?:' + # characters and keywords that mean this isn't
|
||||
r'|'.join(keyword.kwlist) + r')\b))', # pattern matching
|
||||
# pattern matching (but None/True/False is ok)
|
||||
r'|'.join(k for k in keyword.kwlist if k[0].islower()) + r')\b))',
|
||||
bygroups(Text, Keyword), 'soft-keywords-inner'),
|
||||
],
|
||||
'soft-keywords-inner': [
|
||||
@@ -425,10 +424,11 @@ class Python2Lexer(RegexLexer):
|
||||
"""
|
||||
|
||||
name = 'Python 2.x'
|
||||
url = 'http://www.python.org'
|
||||
url = 'https://www.python.org'
|
||||
aliases = ['python2', 'py2']
|
||||
filenames = [] # now taken over by PythonLexer (3.x)
|
||||
mimetypes = ['text/x-python2', 'application/x-python2']
|
||||
version_added = ''
|
||||
|
||||
def innerstring_rules(ttype):
|
||||
return [
|
||||
@@ -637,7 +637,7 @@ class Python2Lexer(RegexLexer):
|
||||
|
||||
class _PythonConsoleLexerBase(RegexLexer):
|
||||
name = 'Python console session'
|
||||
aliases = ['pycon']
|
||||
aliases = ['pycon', 'python-console']
|
||||
mimetypes = ['text/x-python-doctest']
|
||||
|
||||
"""Auxiliary lexer for `PythonConsoleLexer`.
|
||||
@@ -696,8 +696,10 @@ class PythonConsoleLexer(DelegatingLexer):
|
||||
"""
|
||||
|
||||
name = 'Python console session'
|
||||
aliases = ['pycon']
|
||||
aliases = ['pycon', 'python-console']
|
||||
mimetypes = ['text/x-python-doctest']
|
||||
url = 'https://python.org'
|
||||
version_added = ''
|
||||
|
||||
def __init__(self, **options):
|
||||
python3 = get_bool_opt(options, 'python3', True)
|
||||
@@ -721,8 +723,6 @@ class PythonTracebackLexer(RegexLexer):
|
||||
"""
|
||||
For Python 3.x tracebacks, with support for chained exceptions.
|
||||
|
||||
.. versionadded:: 1.0
|
||||
|
||||
.. versionchanged:: 2.5
|
||||
This is now the default ``PythonTracebackLexer``. It is still available
|
||||
as the alias ``Python3TracebackLexer``.
|
||||
@@ -732,6 +732,8 @@ class PythonTracebackLexer(RegexLexer):
|
||||
aliases = ['pytb', 'py3tb']
|
||||
filenames = ['*.pytb', '*.py3tb']
|
||||
mimetypes = ['text/x-python-traceback', 'text/x-python3-traceback']
|
||||
url = 'https://python.org'
|
||||
version_added = '1.0'
|
||||
|
||||
tokens = {
|
||||
'root': [
|
||||
@@ -778,8 +780,6 @@ class Python2TracebackLexer(RegexLexer):
|
||||
"""
|
||||
For Python tracebacks.
|
||||
|
||||
.. versionadded:: 0.7
|
||||
|
||||
.. versionchanged:: 2.5
|
||||
This class has been renamed from ``PythonTracebackLexer``.
|
||||
``PythonTracebackLexer`` now refers to the Python 3 variant.
|
||||
@@ -789,6 +789,8 @@ class Python2TracebackLexer(RegexLexer):
|
||||
aliases = ['py2tb']
|
||||
filenames = ['*.py2tb']
|
||||
mimetypes = ['text/x-python2-traceback']
|
||||
url = 'https://python.org'
|
||||
version_added = '0.7'
|
||||
|
||||
tokens = {
|
||||
'root': [
|
||||
@@ -825,15 +827,14 @@ class Python2TracebackLexer(RegexLexer):
|
||||
class CythonLexer(RegexLexer):
|
||||
"""
|
||||
For Pyrex and Cython source code.
|
||||
|
||||
.. versionadded:: 1.1
|
||||
"""
|
||||
|
||||
name = 'Cython'
|
||||
url = 'http://cython.org'
|
||||
url = 'https://cython.org'
|
||||
aliases = ['cython', 'pyx', 'pyrex']
|
||||
filenames = ['*.pyx', '*.pxd', '*.pxi']
|
||||
mimetypes = ['text/x-cython', 'application/x-cython']
|
||||
version_added = '1.1'
|
||||
|
||||
tokens = {
|
||||
'root': [
|
||||
@@ -1007,13 +1008,13 @@ class DgLexer(RegexLexer):
|
||||
Lexer for dg,
|
||||
a functional and object-oriented programming language
|
||||
running on the CPython 3 VM.
|
||||
|
||||
.. versionadded:: 1.6
|
||||
"""
|
||||
name = 'dg'
|
||||
aliases = ['dg']
|
||||
filenames = ['*.dg']
|
||||
mimetypes = ['text/x-dg']
|
||||
url = 'http://pyos.github.io/dg'
|
||||
version_added = '1.6'
|
||||
|
||||
tokens = {
|
||||
'root': [
|
||||
@@ -1104,13 +1105,12 @@ class DgLexer(RegexLexer):
|
||||
class NumPyLexer(PythonLexer):
|
||||
"""
|
||||
A Python lexer recognizing Numerical Python builtins.
|
||||
|
||||
.. versionadded:: 0.10
|
||||
"""
|
||||
|
||||
name = 'NumPy'
|
||||
url = 'https://numpy.org/'
|
||||
aliases = ['numpy']
|
||||
version_added = '0.10'
|
||||
|
||||
# override the mimetypes to not inherit them from python
|
||||
mimetypes = []
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
A simple modeline parser (based on pymodeline).
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -19,7 +19,7 @@ modeline_re = re.compile(r'''
|
||||
''', re.VERBOSE)
|
||||
|
||||
|
||||
def get_filetype_from_line(l):
|
||||
def get_filetype_from_line(l): # noqa: E741
|
||||
m = modeline_re.search(l)
|
||||
if m:
|
||||
return m.group(1)
|
||||
@@ -30,8 +30,8 @@ def get_filetype_from_buffer(buf, max_lines=5):
|
||||
Scan the buffer for modelines and return filetype if one is found.
|
||||
"""
|
||||
lines = buf.splitlines()
|
||||
for l in lines[-1:-max_lines-1:-1]:
|
||||
ret = get_filetype_from_line(l)
|
||||
for line in lines[-1:-max_lines-1:-1]:
|
||||
ret = get_filetype_from_line(line)
|
||||
if ret:
|
||||
return ret
|
||||
for i in range(max_lines, -1, -1):
|
||||
|
||||
@@ -2,12 +2,7 @@
|
||||
pygments.plugin
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Pygments plugin interface. By default, this tries to use
|
||||
``importlib.metadata``, which is in the Python standard
|
||||
library since Python 3.8, or its ``importlib_metadata``
|
||||
backport for earlier versions of Python. It falls back on
|
||||
``pkg_resources`` if not found. Finally, if ``pkg_resources``
|
||||
is not found either, no plugins are loaded at all.
|
||||
Pygments plugin interface.
|
||||
|
||||
lexer plugins::
|
||||
|
||||
@@ -34,9 +29,10 @@
|
||||
yourfilter = yourfilter:YourFilter
|
||||
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from importlib.metadata import entry_points
|
||||
|
||||
LEXER_ENTRY_POINT = 'pygments.lexers'
|
||||
FORMATTER_ENTRY_POINT = 'pygments.formatters'
|
||||
@@ -45,18 +41,6 @@ FILTER_ENTRY_POINT = 'pygments.filters'
|
||||
|
||||
|
||||
def iter_entry_points(group_name):
|
||||
try:
|
||||
from importlib.metadata import entry_points
|
||||
except ImportError:
|
||||
try:
|
||||
from importlib_metadata import entry_points
|
||||
except ImportError:
|
||||
try:
|
||||
from pip._vendor.pkg_resources import iter_entry_points
|
||||
except (ImportError, OSError):
|
||||
return []
|
||||
else:
|
||||
return iter_entry_points(group_name)
|
||||
groups = entry_points()
|
||||
if hasattr(groups, 'select'):
|
||||
# New interface in Python 3.10 and newer versions of the
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
An algorithm that generates optimized regexes for matching long lists of
|
||||
literal strings.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
Have a look at the `DelphiLexer` to get an idea of how to use
|
||||
this scanner.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
import re
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Sphinx extension to generate automatic documentation of lexers,
|
||||
formatters and filters.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -33,6 +33,8 @@ LEXERDOC = '''
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
|
||||
'''
|
||||
|
||||
FMTERDOC = '''
|
||||
@@ -119,11 +121,11 @@ class PygmentsDoc(Directive):
|
||||
def write_row(*columns):
|
||||
"""Format a table row"""
|
||||
out = []
|
||||
for l, c in zip(column_lengths, columns):
|
||||
if c:
|
||||
out.append(c.ljust(l))
|
||||
for length, col in zip(column_lengths, columns):
|
||||
if col:
|
||||
out.append(col.ljust(length))
|
||||
else:
|
||||
out.append(' '*l)
|
||||
out.append(' '*length)
|
||||
|
||||
return ' '.join(out)
|
||||
|
||||
@@ -147,6 +149,10 @@ class PygmentsDoc(Directive):
|
||||
|
||||
def document_lexers(self):
|
||||
from pip._vendor.pygments.lexers._mapping import LEXERS
|
||||
from pip._vendor import pygments
|
||||
import inspect
|
||||
import pathlib
|
||||
|
||||
out = []
|
||||
modules = {}
|
||||
moduledocstrings = {}
|
||||
@@ -156,16 +162,40 @@ class PygmentsDoc(Directive):
|
||||
self.filenames.add(mod.__file__)
|
||||
cls = getattr(mod, classname)
|
||||
if not cls.__doc__:
|
||||
print("Warning: %s does not have a docstring." % classname)
|
||||
print(f"Warning: {classname} does not have a docstring.")
|
||||
docstring = cls.__doc__
|
||||
if isinstance(docstring, bytes):
|
||||
docstring = docstring.decode('utf8')
|
||||
|
||||
example_file = getattr(cls, '_example', None)
|
||||
if example_file:
|
||||
p = pathlib.Path(inspect.getabsfile(pygments)).parent.parent /\
|
||||
'tests' / 'examplefiles' / example_file
|
||||
content = p.read_text(encoding='utf-8')
|
||||
if not content:
|
||||
raise Exception(
|
||||
f"Empty example file '{example_file}' for lexer "
|
||||
f"{classname}")
|
||||
|
||||
if data[2]:
|
||||
lexer_name = data[2][0]
|
||||
docstring += '\n\n .. admonition:: Example\n'
|
||||
docstring += f'\n .. code-block:: {lexer_name}\n\n'
|
||||
for line in content.splitlines():
|
||||
docstring += f' {line}\n'
|
||||
|
||||
if cls.version_added:
|
||||
version_line = f'.. versionadded:: {cls.version_added}'
|
||||
else:
|
||||
version_line = ''
|
||||
|
||||
modules.setdefault(module, []).append((
|
||||
classname,
|
||||
', '.join(data[2]) or 'None',
|
||||
', '.join(data[3]).replace('*', '\\*').replace('_', '\\') or 'None',
|
||||
', '.join(data[4]) or 'None',
|
||||
docstring))
|
||||
docstring,
|
||||
version_line))
|
||||
if module not in moduledocstrings:
|
||||
moddoc = mod.__doc__
|
||||
if isinstance(moddoc, bytes):
|
||||
@@ -174,7 +204,7 @@ class PygmentsDoc(Directive):
|
||||
|
||||
for module, lexers in sorted(modules.items(), key=lambda x: x[0]):
|
||||
if moduledocstrings[module] is None:
|
||||
raise Exception("Missing docstring for %s" % (module,))
|
||||
raise Exception(f"Missing docstring for {module}")
|
||||
heading = moduledocstrings[module].splitlines()[4].strip().rstrip('.')
|
||||
out.append(MODULEDOC % (module, heading, '-'*len(heading)))
|
||||
for data in lexers:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Basic style object.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -76,7 +76,7 @@ class StyleMeta(type):
|
||||
return ''
|
||||
elif text.startswith('var') or text.startswith('calc'):
|
||||
return text
|
||||
assert False, "wrong color format %r" % text
|
||||
assert False, f"wrong color format {text!r}"
|
||||
|
||||
_styles = obj._styles = {}
|
||||
|
||||
@@ -190,6 +190,12 @@ class Style(metaclass=StyleMeta):
|
||||
#: Style definitions for individual token types.
|
||||
styles = {}
|
||||
|
||||
#: user-friendly style name (used when selecting the style, so this
|
||||
# should be all-lowercase, no spaces, hyphens)
|
||||
name = 'unnamed'
|
||||
|
||||
aliases = []
|
||||
|
||||
# Attribute for lexers defined within Pygments. If set
|
||||
# to True, the style is not shown in the style gallery
|
||||
# on the website. This is intended for language-specific
|
||||
|
||||
@@ -4,65 +4,21 @@
|
||||
|
||||
Contains built-in styles.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
from pip._vendor.pygments.plugin import find_plugin_styles
|
||||
from pip._vendor.pygments.util import ClassNotFound
|
||||
from pip._vendor.pygments.styles._mapping import STYLES
|
||||
|
||||
#: A dictionary of built-in styles, mapping style names to
|
||||
#: ``'submodule::classname'`` strings.
|
||||
STYLE_MAP = {
|
||||
'default': 'default::DefaultStyle',
|
||||
'emacs': 'emacs::EmacsStyle',
|
||||
'friendly': 'friendly::FriendlyStyle',
|
||||
'friendly_grayscale': 'friendly_grayscale::FriendlyGrayscaleStyle',
|
||||
'colorful': 'colorful::ColorfulStyle',
|
||||
'autumn': 'autumn::AutumnStyle',
|
||||
'murphy': 'murphy::MurphyStyle',
|
||||
'manni': 'manni::ManniStyle',
|
||||
'material': 'material::MaterialStyle',
|
||||
'monokai': 'monokai::MonokaiStyle',
|
||||
'perldoc': 'perldoc::PerldocStyle',
|
||||
'pastie': 'pastie::PastieStyle',
|
||||
'borland': 'borland::BorlandStyle',
|
||||
'trac': 'trac::TracStyle',
|
||||
'native': 'native::NativeStyle',
|
||||
'fruity': 'fruity::FruityStyle',
|
||||
'bw': 'bw::BlackWhiteStyle',
|
||||
'vim': 'vim::VimStyle',
|
||||
'vs': 'vs::VisualStudioStyle',
|
||||
'tango': 'tango::TangoStyle',
|
||||
'rrt': 'rrt::RrtStyle',
|
||||
'xcode': 'xcode::XcodeStyle',
|
||||
'igor': 'igor::IgorStyle',
|
||||
'paraiso-light': 'paraiso_light::ParaisoLightStyle',
|
||||
'paraiso-dark': 'paraiso_dark::ParaisoDarkStyle',
|
||||
'lovelace': 'lovelace::LovelaceStyle',
|
||||
'algol': 'algol::AlgolStyle',
|
||||
'algol_nu': 'algol_nu::Algol_NuStyle',
|
||||
'arduino': 'arduino::ArduinoStyle',
|
||||
'rainbow_dash': 'rainbow_dash::RainbowDashStyle',
|
||||
'abap': 'abap::AbapStyle',
|
||||
'solarized-dark': 'solarized::SolarizedDarkStyle',
|
||||
'solarized-light': 'solarized::SolarizedLightStyle',
|
||||
'sas': 'sas::SasStyle',
|
||||
'staroffice' : 'staroffice::StarofficeStyle',
|
||||
'stata': 'stata_light::StataLightStyle',
|
||||
'stata-light': 'stata_light::StataLightStyle',
|
||||
'stata-dark': 'stata_dark::StataDarkStyle',
|
||||
'inkpot': 'inkpot::InkPotStyle',
|
||||
'zenburn': 'zenburn::ZenburnStyle',
|
||||
'gruvbox-dark': 'gruvbox::GruvboxDarkStyle',
|
||||
'gruvbox-light': 'gruvbox::GruvboxLightStyle',
|
||||
'dracula': 'dracula::DraculaStyle',
|
||||
'one-dark': 'onedark::OneDarkStyle',
|
||||
'lilypond' : 'lilypond::LilyPondStyle',
|
||||
'nord': 'nord::NordStyle',
|
||||
'nord-darker': 'nord::NordDarkerStyle',
|
||||
'github-dark': 'gh_dark::GhDarkStyle'
|
||||
}
|
||||
#: This list is deprecated. Use `pygments.styles.STYLES` instead
|
||||
STYLE_MAP = {v[1]: v[0].split('.')[-1] + '::' + k for k, v in STYLES.items()}
|
||||
|
||||
#: Internal reverse mapping to make `get_style_by_name` more efficient
|
||||
_STYLE_NAME_TO_MODULE_MAP = {v[1]: (v[0], k) for k, v in STYLES.items()}
|
||||
|
||||
|
||||
def get_style_by_name(name):
|
||||
@@ -73,8 +29,8 @@ def get_style_by_name(name):
|
||||
Will raise :exc:`pygments.util.ClassNotFound` if no style of that name is
|
||||
found.
|
||||
"""
|
||||
if name in STYLE_MAP:
|
||||
mod, cls = STYLE_MAP[name].split('::')
|
||||
if name in _STYLE_NAME_TO_MODULE_MAP:
|
||||
mod, cls = _STYLE_NAME_TO_MODULE_MAP[name]
|
||||
builtin = "yes"
|
||||
else:
|
||||
for found_name, style in find_plugin_styles():
|
||||
@@ -82,22 +38,24 @@ def get_style_by_name(name):
|
||||
return style
|
||||
# perhaps it got dropped into our styles package
|
||||
builtin = ""
|
||||
mod = name
|
||||
mod = 'pygments.styles.' + name
|
||||
cls = name.title() + "Style"
|
||||
|
||||
try:
|
||||
mod = __import__('pygments.styles.' + mod, None, None, [cls])
|
||||
mod = __import__(mod, None, None, [cls])
|
||||
except ImportError:
|
||||
raise ClassNotFound("Could not find style module %r" % mod +
|
||||
(builtin and ", though it should be builtin") + ".")
|
||||
raise ClassNotFound(f"Could not find style module {mod!r}" +
|
||||
(builtin and ", though it should be builtin")
|
||||
+ ".")
|
||||
try:
|
||||
return getattr(mod, cls)
|
||||
except AttributeError:
|
||||
raise ClassNotFound("Could not find style class %r in style module." % cls)
|
||||
raise ClassNotFound(f"Could not find style class {cls!r} in style module.")
|
||||
|
||||
|
||||
def get_all_styles():
|
||||
"""Return a generator for all styles by name, both builtin and plugin."""
|
||||
yield from STYLE_MAP
|
||||
for v in STYLES.values():
|
||||
yield v[1]
|
||||
for name, _ in find_plugin_styles():
|
||||
yield name
|
||||
|
||||
Binary file not shown.
BIN
.CondaPkg/env/Lib/site-packages/pip/_vendor/pygments/styles/__pycache__/_mapping.cpython-312.pyc
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/pip/_vendor/pygments/styles/__pycache__/_mapping.cpython-312.pyc
vendored
Normal file
Binary file not shown.
54
.CondaPkg/env/Lib/site-packages/pip/_vendor/pygments/styles/_mapping.py
vendored
Normal file
54
.CondaPkg/env/Lib/site-packages/pip/_vendor/pygments/styles/_mapping.py
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
# Automatically generated by scripts/gen_mapfiles.py.
|
||||
# DO NOT EDIT BY HAND; run `tox -e mapfiles` instead.
|
||||
|
||||
STYLES = {
|
||||
'AbapStyle': ('pygments.styles.abap', 'abap', ()),
|
||||
'AlgolStyle': ('pygments.styles.algol', 'algol', ()),
|
||||
'Algol_NuStyle': ('pygments.styles.algol_nu', 'algol_nu', ()),
|
||||
'ArduinoStyle': ('pygments.styles.arduino', 'arduino', ()),
|
||||
'AutumnStyle': ('pygments.styles.autumn', 'autumn', ()),
|
||||
'BlackWhiteStyle': ('pygments.styles.bw', 'bw', ()),
|
||||
'BorlandStyle': ('pygments.styles.borland', 'borland', ()),
|
||||
'CoffeeStyle': ('pygments.styles.coffee', 'coffee', ()),
|
||||
'ColorfulStyle': ('pygments.styles.colorful', 'colorful', ()),
|
||||
'DefaultStyle': ('pygments.styles.default', 'default', ()),
|
||||
'DraculaStyle': ('pygments.styles.dracula', 'dracula', ()),
|
||||
'EmacsStyle': ('pygments.styles.emacs', 'emacs', ()),
|
||||
'FriendlyGrayscaleStyle': ('pygments.styles.friendly_grayscale', 'friendly_grayscale', ()),
|
||||
'FriendlyStyle': ('pygments.styles.friendly', 'friendly', ()),
|
||||
'FruityStyle': ('pygments.styles.fruity', 'fruity', ()),
|
||||
'GhDarkStyle': ('pygments.styles.gh_dark', 'github-dark', ()),
|
||||
'GruvboxDarkStyle': ('pygments.styles.gruvbox', 'gruvbox-dark', ()),
|
||||
'GruvboxLightStyle': ('pygments.styles.gruvbox', 'gruvbox-light', ()),
|
||||
'IgorStyle': ('pygments.styles.igor', 'igor', ()),
|
||||
'InkPotStyle': ('pygments.styles.inkpot', 'inkpot', ()),
|
||||
'LightbulbStyle': ('pygments.styles.lightbulb', 'lightbulb', ()),
|
||||
'LilyPondStyle': ('pygments.styles.lilypond', 'lilypond', ()),
|
||||
'LovelaceStyle': ('pygments.styles.lovelace', 'lovelace', ()),
|
||||
'ManniStyle': ('pygments.styles.manni', 'manni', ()),
|
||||
'MaterialStyle': ('pygments.styles.material', 'material', ()),
|
||||
'MonokaiStyle': ('pygments.styles.monokai', 'monokai', ()),
|
||||
'MurphyStyle': ('pygments.styles.murphy', 'murphy', ()),
|
||||
'NativeStyle': ('pygments.styles.native', 'native', ()),
|
||||
'NordDarkerStyle': ('pygments.styles.nord', 'nord-darker', ()),
|
||||
'NordStyle': ('pygments.styles.nord', 'nord', ()),
|
||||
'OneDarkStyle': ('pygments.styles.onedark', 'one-dark', ()),
|
||||
'ParaisoDarkStyle': ('pygments.styles.paraiso_dark', 'paraiso-dark', ()),
|
||||
'ParaisoLightStyle': ('pygments.styles.paraiso_light', 'paraiso-light', ()),
|
||||
'PastieStyle': ('pygments.styles.pastie', 'pastie', ()),
|
||||
'PerldocStyle': ('pygments.styles.perldoc', 'perldoc', ()),
|
||||
'RainbowDashStyle': ('pygments.styles.rainbow_dash', 'rainbow_dash', ()),
|
||||
'RrtStyle': ('pygments.styles.rrt', 'rrt', ()),
|
||||
'SasStyle': ('pygments.styles.sas', 'sas', ()),
|
||||
'SolarizedDarkStyle': ('pygments.styles.solarized', 'solarized-dark', ()),
|
||||
'SolarizedLightStyle': ('pygments.styles.solarized', 'solarized-light', ()),
|
||||
'StarofficeStyle': ('pygments.styles.staroffice', 'staroffice', ()),
|
||||
'StataDarkStyle': ('pygments.styles.stata_dark', 'stata-dark', ()),
|
||||
'StataLightStyle': ('pygments.styles.stata_light', 'stata-light', ()),
|
||||
'TangoStyle': ('pygments.styles.tango', 'tango', ()),
|
||||
'TracStyle': ('pygments.styles.trac', 'trac', ()),
|
||||
'VimStyle': ('pygments.styles.vim', 'vim', ()),
|
||||
'VisualStudioStyle': ('pygments.styles.vs', 'vs', ()),
|
||||
'XcodeStyle': ('pygments.styles.xcode', 'xcode', ()),
|
||||
'ZenburnStyle': ('pygments.styles.zenburn', 'zenburn', ()),
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Basic token types and the standard tokens.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -209,5 +209,6 @@ STANDARD_TYPES = {
|
||||
Generic.Prompt: 'gp',
|
||||
Generic.Strong: 'gs',
|
||||
Generic.Subheading: 'gu',
|
||||
Generic.EmphStrong: 'ges',
|
||||
Generic.Traceback: 'gt',
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
Inspired by chartypes_create.py from the MoinMoin project.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -104,7 +104,7 @@ def _handle_runs(char_list): # pragma: no cover
|
||||
if a == b:
|
||||
yield a
|
||||
else:
|
||||
yield '%s-%s' % (a, b)
|
||||
yield f'{a}-{b}'
|
||||
|
||||
|
||||
if __name__ == '__main__': # pragma: no cover
|
||||
@@ -141,13 +141,13 @@ if __name__ == '__main__': # pragma: no cover
|
||||
|
||||
for cat in sorted(categories):
|
||||
val = ''.join(_handle_runs(categories[cat]))
|
||||
fp.write('%s = %a\n\n' % (cat, val))
|
||||
fp.write(f'{cat} = {val!a}\n\n')
|
||||
|
||||
cats = sorted(categories)
|
||||
cats.remove('xid_start')
|
||||
cats.remove('xid_continue')
|
||||
fp.write('cats = %r\n\n' % cats)
|
||||
fp.write(f'cats = {cats!r}\n\n')
|
||||
|
||||
fp.write('# Generated from unidata %s\n\n' % (unicodedata.unidata_version,))
|
||||
fp.write(f'# Generated from unidata {unicodedata.unidata_version}\n\n')
|
||||
|
||||
fp.write(footer)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Utility functions.
|
||||
|
||||
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -46,8 +46,7 @@ def get_choice_opt(options, optname, allowed, default=None, normcase=False):
|
||||
if normcase:
|
||||
string = string.lower()
|
||||
if string not in allowed:
|
||||
raise OptionError('Value for option %s must be one of %s' %
|
||||
(optname, ', '.join(map(str, allowed))))
|
||||
raise OptionError('Value for option {} must be one of {}'.format(optname, ', '.join(map(str, allowed))))
|
||||
return string
|
||||
|
||||
|
||||
@@ -69,17 +68,15 @@ def get_bool_opt(options, optname, default=None):
|
||||
elif isinstance(string, int):
|
||||
return bool(string)
|
||||
elif not isinstance(string, str):
|
||||
raise OptionError('Invalid type %r for option %s; use '
|
||||
'1/0, yes/no, true/false, on/off' % (
|
||||
string, optname))
|
||||
raise OptionError(f'Invalid type {string!r} for option {optname}; use '
|
||||
'1/0, yes/no, true/false, on/off')
|
||||
elif string.lower() in ('1', 'yes', 'true', 'on'):
|
||||
return True
|
||||
elif string.lower() in ('0', 'no', 'false', 'off'):
|
||||
return False
|
||||
else:
|
||||
raise OptionError('Invalid value %r for option %s; use '
|
||||
'1/0, yes/no, true/false, on/off' % (
|
||||
string, optname))
|
||||
raise OptionError(f'Invalid value {string!r} for option {optname}; use '
|
||||
'1/0, yes/no, true/false, on/off')
|
||||
|
||||
|
||||
def get_int_opt(options, optname, default=None):
|
||||
@@ -88,13 +85,11 @@ def get_int_opt(options, optname, default=None):
|
||||
try:
|
||||
return int(string)
|
||||
except TypeError:
|
||||
raise OptionError('Invalid type %r for option %s; you '
|
||||
'must give an integer value' % (
|
||||
string, optname))
|
||||
raise OptionError(f'Invalid type {string!r} for option {optname}; you '
|
||||
'must give an integer value')
|
||||
except ValueError:
|
||||
raise OptionError('Invalid value %r for option %s; you '
|
||||
'must give an integer value' % (
|
||||
string, optname))
|
||||
raise OptionError(f'Invalid value {string!r} for option {optname}; you '
|
||||
'must give an integer value')
|
||||
|
||||
def get_list_opt(options, optname, default=None):
|
||||
"""
|
||||
@@ -108,9 +103,8 @@ def get_list_opt(options, optname, default=None):
|
||||
elif isinstance(val, (list, tuple)):
|
||||
return list(val)
|
||||
else:
|
||||
raise OptionError('Invalid type %r for option %s; you '
|
||||
'must give a list value' % (
|
||||
val, optname))
|
||||
raise OptionError(f'Invalid type {val!r} for option {optname}; you '
|
||||
'must give a list value')
|
||||
|
||||
|
||||
def docstring_headline(obj):
|
||||
@@ -181,7 +175,7 @@ def shebang_matches(text, regex):
|
||||
if x and not x.startswith('-')][-1]
|
||||
except IndexError:
|
||||
return False
|
||||
regex = re.compile(r'^%s(\.(exe|cmd|bat|bin))?$' % regex, re.IGNORECASE)
|
||||
regex = re.compile(rf'^{regex}(\.(exe|cmd|bat|bin))?$', re.IGNORECASE)
|
||||
if regex.search(found) is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user