Skip to content

Commit b6d519f

Browse files
committed
Upgrade pygments to 2.15.1
1 parent 6c33bbf commit b6d519f

37 files changed

+389
-228
lines changed

news/pygments.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade pygments to 2.15.1

src/pip/_vendor/pygments/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@
2121
.. _Pygments master branch:
2222
https://github.com/pygments/pygments/archive/master.zip#egg=Pygments-dev
2323
24-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
24+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
2525
:license: BSD, see LICENSE for details.
2626
"""
2727
from io import StringIO, BytesIO
2828

29-
__version__ = '2.14.0'
29+
__version__ = '2.15.1'
3030
__docformat__ = 'restructuredtext'
3131

3232
__all__ = ['lex', 'format', 'highlight']
3333

3434

3535
def lex(code, lexer):
3636
"""
37-
Lex ``code`` with ``lexer`` and return an iterable of tokens.
37+
Lex `code` with the `lexer` (must be a `Lexer` instance)
38+
and return an iterable of tokens. Currently, this only calls
39+
`lexer.get_tokens()`.
3840
"""
3941
try:
4042
return lexer.get_tokens(code)
@@ -49,11 +51,12 @@ def lex(code, lexer):
4951

5052
def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin
5153
"""
52-
Format a tokenlist ``tokens`` with the formatter ``formatter``.
54+
Format ``tokens`` (an iterable of tokens) with the formatter ``formatter``
55+
(a `Formatter` instance).
5356
54-
If ``outfile`` is given and a valid file object (an object
55-
with a ``write`` method), the result will be written to it, otherwise
56-
it is returned as a string.
57+
If ``outfile`` is given and a valid file object (an object with a
58+
``write`` method), the result will be written to it, otherwise it
59+
is returned as a string.
5760
"""
5861
try:
5962
if not outfile:
@@ -73,10 +76,7 @@ def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builti
7376

7477
def highlight(code, lexer, formatter, outfile=None):
7578
"""
76-
Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``.
77-
78-
If ``outfile`` is given and a valid file object (an object
79-
with a ``write`` method), the result will be written to it, otherwise
80-
it is returned as a string.
79+
This is the most high-level highlighting function. It combines `lex` and
80+
`format` in one function.
8181
"""
8282
return format(lex(code, lexer), formatter, outfile)

src/pip/_vendor/pygments/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Main entry point for ``python -m pygments``.
66
7-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
7+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
88
:license: BSD, see LICENSE for details.
99
"""
1010

src/pip/_vendor/pygments/cmdline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Command line interface.
66
7-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
7+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
88
:license: BSD, see LICENSE for details.
99
"""
1010

@@ -185,7 +185,7 @@ def main_inner(parser, argns):
185185
return 0
186186

187187
if argns.V:
188-
print('Pygments version %s, (c) 2006-2022 by Georg Brandl, Matthäus '
188+
print('Pygments version %s, (c) 2006-2023 by Georg Brandl, Matthäus '
189189
'Chajdas and contributors.' % __version__)
190190
return 0
191191

src/pip/_vendor/pygments/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Format colored console output.
66
7-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
7+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
88
:license: BSD, see LICENSE for details.
99
"""
1010

src/pip/_vendor/pygments/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Module that implements the default filter.
66
7-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
7+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
88
:license: BSD, see LICENSE for details.
99
"""
1010

src/pip/_vendor/pygments/filters/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Module containing filter lookup functions and default
66
filters.
77
8-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
99
:license: BSD, see LICENSE for details.
1010
"""
1111

src/pip/_vendor/pygments/formatter.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Base formatter class.
66
7-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
7+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
88
:license: BSD, see LICENSE for details.
99
"""
1010

@@ -26,7 +26,21 @@ class Formatter:
2626
"""
2727
Converts a token stream to text.
2828
29-
Options accepted:
29+
Formatters should have attributes to help selecting them. These
30+
are similar to the corresponding :class:`~pygments.lexer.Lexer`
31+
attributes.
32+
33+
.. autoattribute:: name
34+
:no-value:
35+
36+
.. autoattribute:: aliases
37+
:no-value:
38+
39+
.. autoattribute:: filenames
40+
:no-value:
41+
42+
You can pass options as keyword arguments to the constructor.
43+
All formatters accept these basic options:
3044
3145
``style``
3246
The style to use, can be a string or a Style subclass
@@ -47,22 +61,31 @@ class Formatter:
4761
support (default: None).
4862
``outencoding``
4963
Overrides ``encoding`` if given.
64+
5065
"""
5166

52-
#: Name of the formatter
67+
#: Full name for the formatter, in human-readable form.
5368
name = None
5469

55-
#: Shortcuts for the formatter
70+
#: A list of short, unique identifiers that can be used to lookup
71+
#: the formatter from a list, e.g. using :func:`.get_formatter_by_name()`.
5672
aliases = []
5773

58-
#: fn match rules
74+
#: A list of fnmatch patterns that match filenames for which this
75+
#: formatter can produce output. The patterns in this list should be unique
76+
#: among all formatters.
5977
filenames = []
6078

6179
#: If True, this formatter outputs Unicode strings when no encoding
6280
#: option is given.
6381
unicodeoutput = True
6482

6583
def __init__(self, **options):
84+
"""
85+
As with lexers, this constructor takes arbitrary optional arguments,
86+
and if you override it, you should first process your own options, then
87+
call the base class implementation.
88+
"""
6689
self.style = _lookup_style(options.get('style', 'default'))
6790
self.full = get_bool_opt(options, 'full', False)
6891
self.title = options.get('title', '')
@@ -75,18 +98,25 @@ def __init__(self, **options):
7598

7699
def get_style_defs(self, arg=''):
77100
"""
78-
Return the style definitions for the current style as a string.
101+
This method must return statements or declarations suitable to define
102+
the current style for subsequent highlighted text (e.g. CSS classes
103+
in the `HTMLFormatter`).
79104
80-
``arg`` is an additional argument whose meaning depends on the
81-
formatter used. Note that ``arg`` can also be a list or tuple
82-
for some formatters like the html formatter.
105+
The optional argument `arg` can be used to modify the generation and
106+
is formatter dependent (it is standardized because it can be given on
107+
the command line).
108+
109+
This method is called by the ``-S`` :doc:`command-line option <cmdline>`,
110+
the `arg` is then given by the ``-a`` option.
83111
"""
84112
return ''
85113

86114
def format(self, tokensource, outfile):
87115
"""
88-
Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
89-
tuples and write it into ``outfile``.
116+
This method must format the tokens from the `tokensource` iterable and
117+
write the formatted version to the file object `outfile`.
118+
119+
Formatter options can control how exactly the tokens are converted.
90120
"""
91121
if self.encoding:
92122
# wrap the outfile in a StreamWriter

src/pip/_vendor/pygments/formatters/__init__.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
55
Pygments formatters.
66
7-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
7+
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
88
:license: BSD, see LICENSE for details.
99
"""
1010

11+
import re
1112
import sys
1213
import types
13-
from fnmatch import fnmatch
14+
import fnmatch
1415
from os.path import basename
1516

1617
from pip._vendor.pygments.formatters._mapping import FORMATTERS
@@ -21,6 +22,16 @@
2122
'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS)
2223

2324
_formatter_cache = {} # classes by name
25+
_pattern_cache = {}
26+
27+
28+
def _fn_matches(fn, glob):
29+
"""Return whether the supplied file name fn matches pattern filename."""
30+
if glob not in _pattern_cache:
31+
pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
32+
return pattern.match(fn)
33+
return _pattern_cache[glob].match(fn)
34+
2435

2536
def _load_formatters(module_name):
2637
"""Load a formatter (and all others in the module too)."""
@@ -57,29 +68,31 @@ def find_formatter_class(alias):
5768

5869

5970
def get_formatter_by_name(_alias, **options):
60-
"""Lookup and instantiate a formatter by alias.
71+
"""
72+
Return an instance of a :class:`.Formatter` subclass that has `alias` in its
73+
aliases list. The formatter is given the `options` at its instantiation.
6174
62-
Raises ClassNotFound if not found.
75+
Will raise :exc:`pygments.util.ClassNotFound` if no formatter with that
76+
alias is found.
6377
"""
6478
cls = find_formatter_class(_alias)
6579
if cls is None:
6680
raise ClassNotFound("no formatter found for name %r" % _alias)
6781
return cls(**options)
6882

6983

70-
def load_formatter_from_file(filename, formattername="CustomFormatter",
71-
**options):
72-
"""Load a formatter from a file.
73-
74-
This method expects a file located relative to the current working
75-
directory, which contains a class named CustomFormatter. By default,
76-
it expects the Formatter to be named CustomFormatter; you can specify
77-
your own class name as the second argument to this function.
84+
def load_formatter_from_file(filename, formattername="CustomFormatter", **options):
85+
"""
86+
Return a `Formatter` subclass instance loaded from the provided file, relative
87+
to the current directory.
7888
79-
Users should be very careful with the input, because this method
80-
is equivalent to running eval on the input file.
89+
The file is expected to contain a Formatter class named ``formattername``
90+
(by default, CustomFormatter). Users should be very careful with the input, because
91+
this method is equivalent to running ``eval()`` on the input file. The formatter is
92+
given the `options` at its instantiation.
8193
82-
Raises ClassNotFound if there are any problems importing the Formatter.
94+
:exc:`pygments.util.ClassNotFound` is raised if there are any errors loading
95+
the formatter.
8396
8497
.. versionadded:: 2.2
8598
"""
@@ -104,20 +117,23 @@ def load_formatter_from_file(filename, formattername="CustomFormatter",
104117

105118

106119
def get_formatter_for_filename(fn, **options):
107-
"""Lookup and instantiate a formatter by filename pattern.
120+
"""
121+
Return a :class:`.Formatter` subclass instance that has a filename pattern
122+
matching `fn`. The formatter is given the `options` at its instantiation.
108123
109-
Raises ClassNotFound if not found.
124+
Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename
125+
is found.
110126
"""
111127
fn = basename(fn)
112128
for modname, name, _, filenames, _ in FORMATTERS.values():
113129
for filename in filenames:
114-
if fnmatch(fn, filename):
130+
if _fn_matches(fn, filename):
115131
if name not in _formatter_cache:
116132
_load_formatters(modname)
117133
return _formatter_cache[name](**options)
118134
for cls in find_plugin_formatters():
119135
for filename in cls.filenames:
120-
if fnmatch(fn, filename):
136+
if _fn_matches(fn, filename):
121137
return cls(**options)
122138
raise ClassNotFound("no formatter found for file name %r" % fn)
123139

src/pip/_vendor/pygments/formatters/_mapping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Automatically generated by scripts/gen_mapfiles.py.
2-
# DO NOT EDIT BY HAND; run `make mapfiles` instead.
2+
# DO NOT EDIT BY HAND; run `tox -e mapfiles` instead.
33

44
FORMATTERS = {
55
'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'),
66
'BmpImageFormatter': ('pygments.formatters.img', 'img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
77
'GifImageFormatter': ('pygments.formatters.img', 'img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
88
'GroffFormatter': ('pygments.formatters.groff', 'groff', ('groff', 'troff', 'roff'), (), 'Format tokens with groff escapes to change their color and font style.'),
9-
'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` option."),
9+
'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags. By default, the content is enclosed in a ``<pre>`` tag, itself wrapped in a ``<div>`` tag (but see the `nowrap` option). The ``<div>``'s CSS class can be set by the `cssclass` option."),
1010
'IRCFormatter': ('pygments.formatters.irc', 'IRC', ('irc', 'IRC'), (), 'Format tokens with IRC color sequences'),
1111
'ImageFormatter': ('pygments.formatters.img', 'img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
1212
'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),

0 commit comments

Comments
 (0)