Skip to content

Commit eb90699

Browse files
authored
Merge pull request #11502 from pradyunsg/vendoring-updates
2 parents 8375281 + 4ab07c7 commit eb90699

23 files changed

+343
-214
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.13.0

news/typing_extensions.vendor.rst

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

news/urllib3.vendor.rst

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

src/pip/_vendor/pygments/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"""
2727
from io import StringIO, BytesIO
2828

29-
__version__ = '2.12.0'
29+
__version__ = '2.13.0'
3030
__docformat__ = 'restructuredtext'
3131

3232
__all__ = ['lex', 'format', 'highlight']
@@ -38,10 +38,10 @@ def lex(code, lexer):
3838
"""
3939
try:
4040
return lexer.get_tokens(code)
41-
except TypeError as err:
42-
if (isinstance(err.args[0], str) and
43-
('unbound method get_tokens' in err.args[0] or
44-
'missing 1 required positional argument' in err.args[0])):
41+
except TypeError:
42+
# Heuristic to catch a common mistake.
43+
from pip._vendor.pygments.lexer import RegexLexer
44+
if isinstance(lexer, type) and issubclass(lexer, RegexLexer):
4545
raise TypeError('lex() argument must be a lexer instance, '
4646
'not a class')
4747
raise
@@ -62,10 +62,10 @@ def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builti
6262
return realoutfile.getvalue()
6363
else:
6464
formatter.format(tokens, outfile)
65-
except TypeError as err:
66-
if (isinstance(err.args[0], str) and
67-
('unbound method format' in err.args[0] or
68-
'missing 1 required positional argument' in err.args[0])):
65+
except TypeError:
66+
# Heuristic to catch a common mistake.
67+
from pip._vendor.pygments.formatter import Formatter
68+
if isinstance(formatter, type) and issubclass(formatter, Formatter):
6969
raise TypeError('format() argument must be a formatter instance, '
7070
'not a class')
7171
raise
@@ -80,4 +80,3 @@ def highlight(code, lexer, formatter, outfile=None):
8080
it is returned as a string.
8181
"""
8282
return format(lex(code, lexer), formatter, outfile)
83-

src/pip/_vendor/pygments/cmdline.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pip._vendor.pygments.formatters import get_all_formatters, get_formatter_by_name, \
2626
load_formatter_from_file, get_formatter_for_filename, find_formatter_class
2727
from pip._vendor.pygments.formatters.terminal import TerminalFormatter
28-
from pip._vendor.pygments.formatters.terminal256 import Terminal256Formatter
28+
from pip._vendor.pygments.formatters.terminal256 import Terminal256Formatter, TerminalTrueColorFormatter
2929
from pip._vendor.pygments.filters import get_all_filters, find_filter_class
3030
from pip._vendor.pygments.styles import get_all_styles, get_style_by_name
3131

@@ -445,7 +445,9 @@ def is_only_option(opt):
445445
return 1
446446
else:
447447
if not fmter:
448-
if '256' in os.environ.get('TERM', ''):
448+
if os.environ.get('COLORTERM','') in ('truecolor', '24bit'):
449+
fmter = TerminalTrueColorFormatter(**parsed_opts)
450+
elif '256' in os.environ.get('TERM', ''):
449451
fmter = Terminal256Formatter(**parsed_opts)
450452
else:
451453
fmter = TerminalFormatter(**parsed_opts)
@@ -636,6 +638,9 @@ def main(args=sys.argv):
636638

637639
try:
638640
return main_inner(parser, argns)
641+
except BrokenPipeError:
642+
# someone closed our stdout, e.g. by quitting a pager.
643+
return 0
639644
except Exception:
640645
if argns.v:
641646
print(file=sys.stderr)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,16 @@ class CodeTagFilter(Filter):
6969
7070
`codetags` : list of strings
7171
A list of strings that are flagged as code tags. The default is to
72-
highlight ``XXX``, ``TODO``, ``BUG`` and ``NOTE``.
72+
highlight ``XXX``, ``TODO``, ``FIXME``, ``BUG`` and ``NOTE``.
73+
74+
.. versionchanged:: 2.13
75+
Now recognizes ``FIXME`` by default.
7376
"""
7477

7578
def __init__(self, **options):
7679
Filter.__init__(self, **options)
7780
tags = get_list_opt(options, 'codetags',
78-
['XXX', 'TODO', 'BUG', 'NOTE'])
81+
['XXX', 'TODO', 'FIXME', 'BUG', 'NOTE'])
7982
self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([
8083
re.escape(tag) for tag in tags if tag
8184
]))

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212
import sys
1313
import types
14-
import fnmatch
14+
from fnmatch import fnmatch
1515
from os.path import basename
1616

1717
from pip._vendor.pygments.formatters._mapping import FORMATTERS
@@ -22,16 +22,6 @@
2222
'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS)
2323

2424
_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-
3525

3626
def _load_formatters(module_name):
3727
"""Load a formatter (and all others in the module too)."""
@@ -122,13 +112,13 @@ def get_formatter_for_filename(fn, **options):
122112
fn = basename(fn)
123113
for modname, name, _, filenames, _ in FORMATTERS.values():
124114
for filename in filenames:
125-
if _fn_matches(fn, filename):
115+
if fnmatch(fn, filename):
126116
if name not in _formatter_cache:
127117
_load_formatters(modname)
128118
return _formatter_cache[name](**options)
129119
for cls in find_plugin_formatters():
130120
for filename in cls.filenames:
131-
if _fn_matches(fn, filename):
121+
if fnmatch(fn, filename):
132122
return cls(**options)
133123
raise ClassNotFound("no formatter found for file name %r" % fn)
134124

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
"""
2-
pygments.formatters._mapping
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4-
5-
Formatter mapping definitions. This file is generated by itself. Every time
6-
you change something on a builtin formatter definition, run this script from
7-
the formatters folder to update it.
8-
9-
Do not alter the FORMATTERS dictionary by hand.
10-
11-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
12-
:license: BSD, see LICENSE for details.
13-
"""
1+
# Automatically generated by scripts/gen_mapfiles.py.
2+
# DO NOT EDIT BY HAND; run `make mapfiles` instead.
143

154
FORMATTERS = {
165
'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.'),
@@ -30,55 +19,5 @@
3019
'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
3120
'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'),
3221
'TerminalTrueColorFormatter': ('pygments.formatters.terminal256', 'TerminalTrueColor', ('terminal16m', 'console16m', '16m'), (), 'Format tokens with ANSI color sequences, for output in a true-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
33-
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
22+
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.'),
3423
}
35-
36-
if __name__ == '__main__': # pragma: no cover
37-
import sys
38-
import os
39-
40-
# lookup formatters
41-
found_formatters = []
42-
imports = []
43-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
44-
from pip._vendor.pygments.util import docstring_headline
45-
46-
for root, dirs, files in os.walk('.'):
47-
for filename in files:
48-
if filename.endswith('.py') and not filename.startswith('_'):
49-
module_name = 'pygments.formatters%s.%s' % (
50-
root[1:].replace('/', '.'), filename[:-3])
51-
print(module_name)
52-
module = __import__(module_name, None, None, [''])
53-
for formatter_name in module.__all__:
54-
formatter = getattr(module, formatter_name)
55-
found_formatters.append(
56-
'%r: %r' % (formatter_name,
57-
(module_name,
58-
formatter.name,
59-
tuple(formatter.aliases),
60-
tuple(formatter.filenames),
61-
docstring_headline(formatter))))
62-
# sort them to make the diff minimal
63-
found_formatters.sort()
64-
65-
# extract useful sourcecode from this file
66-
with open(__file__) as fp:
67-
content = fp.read()
68-
# replace crnl to nl for Windows.
69-
#
70-
# Note that, originally, contributors should keep nl of master
71-
# repository, for example by using some kind of automatic
72-
# management EOL, like `EolExtension
73-
# <https://www.mercurial-scm.org/wiki/EolExtension>`.
74-
content = content.replace("\r\n", "\n")
75-
header = content[:content.find('FORMATTERS = {')]
76-
footer = content[content.find("if __name__ == '__main__':"):]
77-
78-
# write new file
79-
with open(__file__, 'w') as fp:
80-
fp.write(header)
81-
fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
82-
fp.write(footer)
83-
84-
print ('=== %d formatters processed.' % len(found_formatters))

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,17 @@ def get_char_size(self):
206206
"""
207207
Get the character size.
208208
"""
209-
return self.fonts['NORMAL'].getsize('M')
209+
return self.get_text_size('M')
210210

211211
def get_text_size(self, text):
212212
"""
213-
Get the text size(width, height).
213+
Get the text size (width, height).
214214
"""
215-
return self.fonts['NORMAL'].getsize(text)
215+
font = self.fonts['NORMAL']
216+
if hasattr(font, 'getbbox'): # Pillow >= 9.2.0
217+
return font.getbbox(text)[2:4]
218+
else:
219+
return font.getsize(text)
216220

217221
def get_font(self, bold, oblique):
218222
"""
@@ -520,7 +524,7 @@ def _create_drawables(self, tokensource):
520524
text_fg = self._get_text_color(style),
521525
text_bg = self._get_text_bg_color(style),
522526
)
523-
temp_width, temp_hight = self.fonts.get_text_size(temp)
527+
temp_width, _ = self.fonts.get_text_size(temp)
524528
linelength += temp_width
525529
maxlinelength = max(maxlinelength, linelength)
526530
charno += len(temp)

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212
import sys
1313
import types
14-
import fnmatch
14+
from fnmatch import fnmatch
1515
from os.path import basename
1616

1717
from pip._vendor.pygments.lexers._mapping import LEXERS
@@ -28,16 +28,6 @@
2828
'guess_lexer', 'load_lexer_from_file'] + list(LEXERS) + list(COMPAT)
2929

3030
_lexer_cache = {}
31-
_pattern_cache = {}
32-
33-
34-
def _fn_matches(fn, glob):
35-
"""Return whether the supplied file name fn matches pattern filename."""
36-
if glob not in _pattern_cache:
37-
pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
38-
return pattern.match(fn)
39-
return _pattern_cache[glob].match(fn)
40-
4131

4232
def _load_lexers(module_name):
4333
"""Load a lexer (and all others in the module too)."""
@@ -169,13 +159,13 @@ def find_lexer_class_for_filename(_fn, code=None):
169159
fn = basename(_fn)
170160
for modname, name, _, filenames, _ in LEXERS.values():
171161
for filename in filenames:
172-
if _fn_matches(fn, filename):
162+
if fnmatch(fn, filename):
173163
if name not in _lexer_cache:
174164
_load_lexers(modname)
175165
matches.append((_lexer_cache[name], filename))
176166
for cls in find_plugin_lexers():
177167
for filename in cls.filenames:
178-
if _fn_matches(fn, filename):
168+
if fnmatch(fn, filename):
179169
matches.append((cls, filename))
180170

181171
if isinstance(code, bytes):
@@ -262,11 +252,11 @@ def guess_lexer_for_filename(_fn, _text, **options):
262252
matching_lexers = set()
263253
for lexer in _iter_lexerclasses():
264254
for filename in lexer.filenames:
265-
if _fn_matches(fn, filename):
255+
if fnmatch(fn, filename):
266256
matching_lexers.add(lexer)
267257
primary[lexer] = True
268258
for filename in lexer.alias_filenames:
269-
if _fn_matches(fn, filename):
259+
if fnmatch(fn, filename):
270260
matching_lexers.add(lexer)
271261
primary[lexer] = False
272262
if not matching_lexers:

0 commit comments

Comments
 (0)