mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-41043: Escape literal part of the path for glob(). (GH-20994)
This commit is contained in:
parent
a041e116db
commit
9355868458
24 changed files with 37 additions and 31 deletions
|
@ -41,6 +41,8 @@ def walk_tree(root, *,
|
|||
def glob_tree(root, *,
|
||||
suffix=None,
|
||||
_glob=glob.iglob,
|
||||
_escape=glob.escape,
|
||||
_join=os.path.join,
|
||||
):
|
||||
"""Yield each file in the tree under the given directory name.
|
||||
|
||||
|
@ -51,9 +53,9 @@ def glob_tree(root, *,
|
|||
if not isinstance(suffix, str):
|
||||
raise ValueError('suffix must be a string')
|
||||
|
||||
for filename in _glob(f'{root}/*{suffix}'):
|
||||
for filename in _glob(_join(_escape(root), f'*{suffix}')):
|
||||
yield filename
|
||||
for filename in _glob(f'{root}/**/*{suffix}'):
|
||||
for filename in _glob(_join(_escape(root), f'**/*{suffix}')):
|
||||
yield filename
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue