Skip to content

Commit a61f5da

Browse files
[2.7] bpo-31920: Fixed handling directories as arguments in the pygettext script. (GH-6259) (GH-6436)
Based on patch by Oleg Krasnikov. (cherry picked from commit c93938b)
1 parent 77f0a41 commit a61f5da

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ Jerzy Kozera
767767
Maksim Kozyarchuk
768768
Stefan Krah
769769
Bob Kras
770+
Oleg Krasnikov
770771
Sebastian Kreft
771772
Holger Krekel
772773
Michael Kremer
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed handling directories as arguments in the ``pygettext`` script. Based
2+
on patch by Oleg Krasnikov.

Tools/i18n/pygettext.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,6 @@ def containsAny(str, set):
261261
return 1 in [c in str for c in set]
262262

263263

264-
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

0 commit comments

Comments
 (0)