]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #7367: Fix pkgutil.walk_paths to skip directories whose
authorNed Deily <nad@acm.org>
Thu, 6 Oct 2011 21:17:47 +0000 (14:17 -0700)
committerNed Deily <nad@acm.org>
Thu, 6 Oct 2011 21:17:47 +0000 (14:17 -0700)
contents cannot be read.

Lib/pkgutil.py

index 322bbdf5cb6df459c78c6c8564a09cd41d162694..ce072ec9ef75dcc1eede38e8dc870ae4aac417fe 100644 (file)
@@ -194,8 +194,11 @@ class ImpImporter:
 
         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 @@ class ImpImporter:
 
             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