[2.7] bpo-31920: Fixed handling directories as arguments in the ``pyg… · python/cpython@a61f5da

@@ -261,25 +261,6 @@ def containsAny(str, set):

261261

return 1 in [c in str for c in set]

262262263263264-

def _visit_pyfiles(list, dirname, names):

265-

"""Helper for getFilesForName()."""

266-

# get extension for python source files

267-

if not globals().has_key('_py_ext'):

268-

global _py_ext

269-

_py_ext = [triple[0] for triple in imp.get_suffixes()

270-

if triple[2] == imp.PY_SOURCE][0]

271-272-

# don't recurse into CVS directories

273-

if 'CVS' in names:

274-

names.remove('CVS')

275-276-

# add all *.py files to list

277-

list.extend(

278-

[os.path.join(dirname, file) for file in names

279-

if os.path.splitext(file)[1] == _py_ext]

280-

)

281-282-283264

def _get_modpkg_path(dotted_name, pathlist=None):

284265

"""Get the filesystem path for a module or a package.

285266

@@ -340,7 +321,20 @@ def getFilesForName(name):

340321

if os.path.isdir(name):

341322

# find all python files in directory

342323

list = []

343-

os.path.walk(name, _visit_pyfiles, list)

324+

# get extension for python source files

325+

if '_py_ext' not in globals():

326+

global _py_ext

327+

_py_ext = [triple[0] for triple in imp.get_suffixes()

328+

if triple[2] == imp.PY_SOURCE][0]

329+

for root, dirs, files in os.walk(name):

330+

# don't recurse into CVS directories

331+

if 'CVS' in dirs:

332+

dirs.remove('CVS')

333+

# add all *.py files to list

334+

list.extend(

335+

[os.path.join(root, file) for file in files

336+

if os.path.splitext(file)[1] == _py_ext]

337+

)

344338

return list

345339

elif os.path.exists(name):

346340

# a single file