[Python-checkins] cpython (2.7): Issue #7367: Fix pkgutil.walk_paths to skip directories whose

ned.deily python-checkins at python.org
Thu Oct 6 23:43:09 CEST 2011


http://hg.python.org/cpython/rev/1449095397ae
changeset:   72771:1449095397ae
branch:      2.7
user:        Ned Deily <nad at acm.org>
date:        Thu Oct 06 14:17:47 2011 -0700
summary:
  Issue #7367: Fix pkgutil.walk_paths to skip directories whose
contents cannot be read.

files:
  Lib/pkgutil.py |  14 +++++++++++---
  1 files changed, 11 insertions(+), 3 deletions(-)


diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -194,8 +194,11 @@
 
         yielded = {}
         import inspect
-
-        filenames = os.listdir(self.path)
+        try:
+            filenames = os.listdir(self.path)
+        except OSError:
+            # ignore unreadable directories like import does
+            filenames = []
         filenames.sort()  # handle packages before same-named modules
 
         for fn in filenames:
@@ -208,7 +211,12 @@
 
             if not modname and os.path.isdir(path) and '.' not in fn:
                 modname = fn
-                for fn in os.listdir(path):
+                try:
+                    dircontents = os.listdir(path)
+                except OSError:
+                    # ignore unreadable directories like import does
+                    dircontents = []
+                for fn in dircontents:
                     subname = inspect.getmodulename(fn)
                     if subname=='__init__':
                         ispkg = True

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list