Skip to content

Commit 34d5102

Browse files
authored
block top-level module namespaces not covered by stdlib-list (#2942)
* failing test for #2940 * block top-level module namespaces not covered by stdlib-list fixes #2940, initial work failed to take this into consideration. * additional test cases for #2942
1 parent 2f6c867 commit 34d5102

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

tests/unit/forklift/test_legacy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,11 @@ def test_fails_with_invalid_names(self, pyramid_config, db_request, name):
882882
"main", "future", "al", "uU", "test",
883883
"encodings.utf_8_sig",
884884
"distutils.command.build_clib",
885+
"xmlrpc", "xmlrpc.server",
886+
"xml.etree", "xml.etree.ElementTree",
887+
"xml.parsers", "xml.parsers.expat",
888+
"xml.parsers.expat.errors",
889+
"encodings.idna", "encodings",
885890
"CGIHTTPServer", "cgihttpserver"])
886891
def test_fails_with_stdlib_names(self, pyramid_config, db_request, name):
887892
pyramid_config.testing_securitypolicy(userid=1)

warehouse/forklift/legacy.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,19 @@
5252

5353
PATH_HASHER = "blake2_256"
5454

55+
56+
def namespace_stdlib_list(module_list):
57+
for module_name in module_list:
58+
parts = module_name.split('.')
59+
for i, part in enumerate(parts):
60+
yield '.'.join(parts[:i + 1])
61+
62+
5563
STDLIB_PROHIBITTED = {
5664
packaging.utils.canonicalize_name(s.rstrip('-_.').lstrip('-_.'))
57-
for s in chain.from_iterable(stdlib_list.stdlib_list(version)
58-
for version in stdlib_list.short_versions)
65+
for s in chain.from_iterable(
66+
namespace_stdlib_list(stdlib_list.stdlib_list(version))
67+
for version in stdlib_list.short_versions)
5968
}
6069

6170
# Wheel platform checking

0 commit comments

Comments
 (0)