]> granicus.if.org Git - python/commitdiff
Issue #7367: Fix pkgutil.walk_paths to skip directories whose
authorNed Deily <nad@acm.org>
Thu, 6 Oct 2011 21:19:08 +0000 (14:19 -0700)
committerNed Deily <nad@acm.org>
Thu, 6 Oct 2011 21:19:08 +0000 (14:19 -0700)
contents cannot be read.

Lib/pkgutil.py

index 2d885683e022643e719091b72d0b1852079526f6..51da0b1bb52641d818852f4e3d6c45c822ed08b5 100644 (file)
@@ -191,8 +191,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:
@@ -205,7 +208,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