Skip to content

Commit fabd7bb

Browse files
authored
bpo-41521: Replace whitelist/blacklist with allowlist/denylist (GH-21822)
Automerge-Triggered-By: @tiran
1 parent 1d541c2 commit fabd7bb

File tree

12 files changed

+36
-36
lines changed

12 files changed

+36
-36
lines changed

Doc/library/http.cookiejar.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,16 @@ receiving cookies. There are also some strictness switches that allow you to
462462
tighten up the rather loose Netscape protocol rules a little bit (at the cost of
463463
blocking some benign cookies).
464464

465-
A domain blacklist and whitelist is provided (both off by default). Only domains
466-
not in the blacklist and present in the whitelist (if the whitelist is active)
465+
A domain denylist and allowlist is provided (both off by default). Only domains
466+
not in the denylist and present in the allowlist (if the allowlist is active)
467467
participate in cookie setting and returning. Use the *blocked_domains*
468468
constructor argument, and :meth:`blocked_domains` and
469469
:meth:`set_blocked_domains` methods (and the corresponding argument and methods
470-
for *allowed_domains*). If you set a whitelist, you can turn it off again by
470+
for *allowed_domains*). If you set an allowlist, you can turn it off again by
471471
setting it to :const:`None`.
472472

473473
Domains in block or allow lists that do not start with a dot must equal the
474-
cookie domain to be matched. For example, ``"example.com"`` matches a blacklist
474+
cookie domain to be matched. For example, ``"example.com"`` matches a denylist
475475
entry of ``"example.com"``, but ``"www.example.com"`` does not. Domains that do
476476
start with a dot are matched by more specific domains too. For example, both
477477
``"www.example.com"`` and ``"www.coyote.example.com"`` match ``".example.com"``
@@ -494,7 +494,7 @@ and ``".168.1.2"``, 192.168.1.2 is blocked, but 193.168.1.2 is not.
494494

495495
.. method:: DefaultCookiePolicy.is_blocked(domain)
496496

497-
Return whether *domain* is on the blacklist for setting or receiving cookies.
497+
Return whether *domain* is on the denylist for setting or receiving cookies.
498498

499499

500500
.. method:: DefaultCookiePolicy.allowed_domains()
@@ -509,7 +509,7 @@ and ``".168.1.2"``, 192.168.1.2 is blocked, but 193.168.1.2 is not.
509509

510510
.. method:: DefaultCookiePolicy.is_not_allowed(domain)
511511

512-
Return whether *domain* is not on the whitelist for setting or receiving
512+
Return whether *domain* is not on the allowlist for setting or receiving
513513
cookies.
514514

515515
:class:`DefaultCookiePolicy` instances have the following attributes, which are

Doc/library/urllib.parse.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ or on combining URL components into a URL string.
153153

154154
.. versionchanged:: 3.3
155155
The fragment is now parsed for all URL schemes (unless *allow_fragment* is
156-
false), in accordance with :rfc:`3986`. Previously, a whitelist of
156+
false), in accordance with :rfc:`3986`. Previously, an allowlist of
157157
schemes that support fragments existed.
158158

159159
.. versionchanged:: 3.6

Lib/codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
class CodecInfo(tuple):
8484
"""Codec details when looking up the codec registry"""
8585

86-
# Private API to allow Python 3.4 to blacklist the known non-Unicode
86+
# Private API to allow Python 3.4 to denylist the known non-Unicode
8787
# codecs in the standard library. A more general mechanism to
8888
# reliably distinguish test encodings from other codecs will hopefully
8989
# be defined for Python 3.5

Lib/ipaddress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ def _parse_octet(cls, octet_str):
12141214
"""
12151215
if not octet_str:
12161216
raise ValueError("Empty octet not permitted")
1217-
# Whitelist the characters, since int() allows a lot of bizarre stuff.
1217+
# Reject non-ASCII digits.
12181218
if not (octet_str.isascii() and octet_str.isdigit()):
12191219
msg = "Only decimal digits permitted in %r"
12201220
raise ValueError(msg % octet_str)
@@ -1719,7 +1719,7 @@ def _parse_hextet(cls, hextet_str):
17191719
[0..FFFF].
17201720
17211721
"""
1722-
# Whitelist the characters, since int() allows a lot of bizarre stuff.
1722+
# Reject non-ASCII digits.
17231723
if not cls._HEX_DIGITS.issuperset(hextet_str):
17241724
raise ValueError("Only hex digits permitted in %r" % hextet_str)
17251725
# We do the length check second, since the invalid character error

Lib/test/test___all__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def walk_modules(self, basedir, modpath):
6969
yield path, modpath + fn[:-3]
7070

7171
def test_all(self):
72-
# Blacklisted modules and packages
73-
blacklist = set([
72+
# List of denied modules and packages
73+
denylist = set([
7474
# Will raise a SyntaxError when compiling the exec statement
7575
'__future__',
7676
])
@@ -85,13 +85,13 @@ def test_all(self):
8585
lib_dir = os.path.dirname(os.path.dirname(__file__))
8686
for path, modname in self.walk_modules(lib_dir, ""):
8787
m = modname
88-
blacklisted = False
88+
denylisted = False
8989
while m:
90-
if m in blacklist:
91-
blacklisted = True
90+
if m in denylist:
91+
denylisted = True
9292
break
9393
m = m.rpartition('.')[0]
94-
if blacklisted:
94+
if denylisted:
9595
continue
9696
if support.verbose:
9797
print(modname)

Lib/test/test_httplib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,9 +1434,9 @@ def test_all(self):
14341434
expected = {"responses"} # White-list documented dict() object
14351435
# HTTPMessage, parse_headers(), and the HTTP status code constants are
14361436
# intentionally omitted for simplicity
1437-
blacklist = {"HTTPMessage", "parse_headers"}
1437+
denylist = {"HTTPMessage", "parse_headers"}
14381438
for name in dir(client):
1439-
if name.startswith("_") or name in blacklist:
1439+
if name.startswith("_") or name in denylist:
14401440
continue
14411441
module_object = getattr(client, name)
14421442
if getattr(module_object, "__module__", None) == "http.client":

Lib/test/test_httpservers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,9 +1189,9 @@ def test_windows_colon(self):
11891189
class MiscTestCase(unittest.TestCase):
11901190
def test_all(self):
11911191
expected = []
1192-
blacklist = {'executable', 'nobody_uid', 'test'}
1192+
denylist = {'executable', 'nobody_uid', 'test'}
11931193
for name in dir(server):
1194-
if name.startswith('_') or name in blacklist:
1194+
if name.startswith('_') or name in denylist:
11951195
continue
11961196
module_object = getattr(server, name)
11971197
if getattr(module_object, '__module__', None) == 'http.server':

Lib/test/test_nntplib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ def test_article_head_body(self):
197197
self.assertTrue(resp.startswith("220 "), resp)
198198
self.check_article_resp(resp, article, art_num)
199199
# Tolerate running the tests from behind a NNTP virus checker
200-
blacklist = lambda line: line.startswith(b'X-Antivirus')
200+
denylist = lambda line: line.startswith(b'X-Antivirus')
201201
filtered_head_lines = [line for line in head.lines
202-
if not blacklist(line)]
202+
if not denylist(line)]
203203
filtered_lines = [line for line in article.lines
204-
if not blacklist(line)]
204+
if not denylist(line)]
205205
self.assertEqual(filtered_lines, filtered_head_lines + [b''] + body.lines)
206206

207207
def test_capabilities(self):

Lib/test/test_tools/test_sundry.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
class TestSundryScripts(unittest.TestCase):
1818
# At least make sure the rest don't have syntax errors. When tests are
19-
# added for a script it should be added to the whitelist below.
19+
# added for a script it should be added to the allowlist below.
2020

2121
# scripts that have independent tests.
22-
whitelist = ['reindent', 'pdeps', 'gprof2html', 'md5sum']
22+
allowlist = ['reindent', 'pdeps', 'gprof2html', 'md5sum']
2323
# scripts that can't be imported without running
24-
blacklist = ['make_ctype']
24+
denylist = ['make_ctype']
2525
# scripts that use windows-only modules
2626
windows_only = ['win_add2path']
27-
# blacklisted for other reasons
27+
# denylisted for other reasons
2828
other = ['analyze_dxp', '2to3']
2929

30-
skiplist = blacklist + whitelist + windows_only + other
30+
skiplist = denylist + allowlist + windows_only + other
3131

3232
def test_sundry(self):
3333
old_modules = import_helper.modules_setup()

Lib/test/test_traceback.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,9 @@ class MiscTest(unittest.TestCase):
11911191

11921192
def test_all(self):
11931193
expected = set()
1194-
blacklist = {'print_list'}
1194+
denylist = {'print_list'}
11951195
for name in dir(traceback):
1196-
if name.startswith('_') or name in blacklist:
1196+
if name.startswith('_') or name in denylist:
11971197
continue
11981198
module_object = getattr(traceback, name)
11991199
if getattr(module_object, '__module__', None) == 'traceback':

Objects/typeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,10 +4171,10 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
41714171
In theory the proper fix would be to identify which classes rely on
41724172
this invariant and somehow disallow __class__ assignment only for them,
41734173
perhaps via some mechanism like a new Py_TPFLAGS_IMMUTABLE flag (a
4174-
"blacklisting" approach). But in practice, since this problem wasn't
4174+
"denylisting" approach). But in practice, since this problem wasn't
41754175
noticed late in the 3.5 RC cycle, we're taking the conservative
41764176
approach and reinstating the same HEAPTYPE->HEAPTYPE check that we used
4177-
to have, plus a "whitelist". For now, the whitelist consists only of
4177+
to have, plus an "allowlist". For now, the allowlist consists only of
41784178
ModuleType subtypes, since those are the cases that motivated the patch
41794179
in the first place -- see https://bugs.python.org/issue22986 -- and
41804180
since module objects are mutable we can be sure that they are

Tools/clinic/clinic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4433,7 +4433,7 @@ def state_parameter(self, line):
44334433

44344434
if 'c_default' not in kwargs:
44354435
# we can only represent very simple data values in C.
4436-
# detect whether default is okay, via a blacklist
4436+
# detect whether default is okay, via a denylist
44374437
# of disallowed ast nodes.
44384438
class DetectBadNodes(ast.NodeVisitor):
44394439
bad = False
@@ -4456,9 +4456,9 @@ def bad_node(self, node):
44564456
# "starred": "a = [1, 2, 3]; *a"
44574457
visit_Starred = bad_node
44584458

4459-
blacklist = DetectBadNodes()
4460-
blacklist.visit(module)
4461-
bad = blacklist.bad
4459+
denylist = DetectBadNodes()
4460+
denylist.visit(module)
4461+
bad = denylist.bad
44624462
else:
44634463
# if they specify a c_default, we can be more lenient about the default value.
44644464
# but at least make an attempt at ensuring it's a valid expression.

0 commit comments

Comments
 (0)